@synertech/ui 0.45.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/skills/use-synertech-ui/SKILL.md +116 -18
- package/README.md +47 -5
- package/dist/components/area-chart/AreaChart.cjs +1 -1
- package/dist/components/area-chart/AreaChart.js +1 -1
- package/dist/components/avatar/Avatar.cjs +1 -1
- package/dist/components/avatar/Avatar.js +1 -1
- package/dist/components/banner/Banner.cjs +1 -1
- package/dist/components/banner/Banner.js +1 -1
- package/dist/components/bar-chart/BarChart.cjs +1 -1
- package/dist/components/bar-chart/BarChart.js +1 -1
- package/dist/components/box-plot/BoxPlot.cjs +1 -1
- package/dist/components/box-plot/BoxPlot.js +1 -1
- package/dist/components/breadcrumb/Breadcrumb.cjs +1 -1
- package/dist/components/breadcrumb/Breadcrumb.js +1 -1
- package/dist/components/bullet-chart/BulletChart.cjs +1 -1
- package/dist/components/bullet-chart/BulletChart.js +1 -1
- package/dist/components/calendar/Calendar.cjs +1 -1
- package/dist/components/calendar/Calendar.js +1 -1
- package/dist/components/candlestick-chart/CandlestickChart.cjs +1 -1
- package/dist/components/candlestick-chart/CandlestickChart.js +1 -1
- package/dist/components/chart/ChartBrush.cjs +1 -1
- package/dist/components/chart/ChartBrush.js +1 -1
- package/dist/components/chart/ChartExportButton.cjs +1 -1
- package/dist/components/chart/ChartExportButton.js +1 -1
- package/dist/components/chart/ChartSync.cjs +1 -1
- package/dist/components/chart/ChartSync.js +1 -1
- package/dist/components/chart/utils/cartesian.cjs +1 -1
- package/dist/components/chart/utils/cartesian.js +1 -1
- package/dist/components/chart/utils/export.cjs +1 -2
- package/dist/components/chart/utils/export.js +1 -2
- package/dist/components/chart/utils/keyboard.cjs +1 -0
- package/dist/components/chart/utils/keyboard.js +1 -0
- package/dist/components/chart/utils/path.cjs +1 -1
- package/dist/components/chart/utils/path.js +1 -1
- package/dist/components/chart/utils/time.cjs +1 -1
- package/dist/components/chart/utils/time.js +1 -1
- package/dist/components/chart/utils/timestamp.cjs +1 -0
- package/dist/components/chart/utils/timestamp.js +1 -0
- package/dist/components/chart/utils/touch.cjs +1 -0
- package/dist/components/chart/utils/touch.js +1 -0
- package/dist/components/chip/Chip.cjs +1 -1
- package/dist/components/chip/Chip.js +1 -1
- package/dist/components/datagrid/DataGrid.cjs +1 -2
- package/dist/components/datagrid/DataGrid.js +1 -2
- package/dist/components/device-mockup/DeviceMockup.cjs +1 -1
- package/dist/components/device-mockup/DeviceMockup.js +1 -1
- package/dist/components/dropdown/Dropdown.cjs +1 -1
- package/dist/components/dropdown/Dropdown.js +1 -1
- package/dist/components/dropdown/DropdownCheckboxItem.cjs +1 -1
- package/dist/components/dropdown/DropdownCheckboxItem.js +1 -1
- package/dist/components/dropdown/DropdownContent.cjs +1 -1
- package/dist/components/dropdown/DropdownContent.js +1 -1
- package/dist/components/dropdown/DropdownItem.cjs +1 -1
- package/dist/components/dropdown/DropdownItem.js +1 -1
- package/dist/components/dropdown/DropdownRadio.cjs +1 -1
- package/dist/components/dropdown/DropdownRadio.js +1 -1
- package/dist/components/dropdown/DropdownSubMenu.cjs +1 -1
- package/dist/components/dropdown/DropdownSubMenu.js +1 -1
- package/dist/components/dropdown/hooks/index.cjs +1 -1
- package/dist/components/dropdown/hooks/index.js +1 -1
- package/dist/components/dropdown/hooks/useClickOutside.cjs +1 -1
- package/dist/components/dropdown/hooks/useClickOutside.js +1 -1
- package/dist/components/dropdown/index.cjs +1 -1
- package/dist/components/dropdown/index.js +1 -1
- package/dist/components/dropdown/menu-navigation.cjs +1 -0
- package/dist/components/dropdown/menu-navigation.js +1 -0
- package/dist/components/dumbbell-chart/DumbbellChart.cjs +1 -1
- package/dist/components/dumbbell-chart/DumbbellChart.js +1 -1
- package/dist/components/file-selector/FileSelector.cjs +1 -1
- package/dist/components/file-selector/FileSelector.js +1 -1
- package/dist/components/form/input/Input.cjs +1 -1
- package/dist/components/form/input/Input.js +1 -1
- package/dist/components/form/mention-input/MentionInput.cjs +1 -1
- package/dist/components/form/mention-input/MentionInput.js +1 -1
- package/dist/components/form/number-input/NumberInput.cjs +1 -1
- package/dist/components/form/number-input/NumberInput.js +1 -1
- package/dist/components/funnel-chart/FunnelChart.cjs +1 -1
- package/dist/components/funnel-chart/FunnelChart.js +1 -1
- package/dist/components/gantt-chart/GanttChart.cjs +1 -1
- package/dist/components/gantt-chart/GanttChart.js +1 -1
- package/dist/components/header/Header.cjs +1 -1
- package/dist/components/header/Header.js +1 -1
- package/dist/components/heat-map/Heatmap.cjs +1 -1
- package/dist/components/heat-map/Heatmap.js +1 -1
- package/dist/components/help-button/HelpButton.cjs +7 -7
- package/dist/components/help-button/HelpButton.js +7 -7
- package/dist/components/help-button/MarkdownEditor.cjs +1 -1
- package/dist/components/help-button/MarkdownEditor.js +1 -1
- package/dist/components/image-uploader/ImageUploader.cjs +1 -1
- package/dist/components/image-uploader/ImageUploader.js +1 -1
- package/dist/components/label/Label.cjs +1 -1
- package/dist/components/label/Label.js +1 -1
- package/dist/components/line-chart/LineChart.cjs +1 -1
- package/dist/components/line-chart/LineChart.js +1 -1
- package/dist/components/modal/Modal.cjs +1 -1
- package/dist/components/modal/Modal.js +1 -1
- package/dist/components/pagination/Pagination.cjs +1 -1
- package/dist/components/pagination/Pagination.js +1 -1
- package/dist/components/pie-chart/PieChart.cjs +1 -1
- package/dist/components/pie-chart/PieChart.js +1 -1
- package/dist/components/radio-button/RadioButton.cjs +1 -1
- package/dist/components/radio-button/RadioButton.js +1 -1
- package/dist/components/scatter-chart/ScatterChart.cjs +1 -1
- package/dist/components/scatter-chart/ScatterChart.js +1 -1
- package/dist/components/schema-editor/SchemaEditor.cjs +1 -1
- package/dist/components/schema-editor/SchemaEditor.js +1 -1
- package/dist/components/schema-editor/legend/SchemaLegend.cjs +1 -1
- package/dist/components/schema-editor/legend/SchemaLegend.js +1 -1
- package/dist/components/schema-editor/tables/SchemaTableRenderer.cjs +1 -1
- package/dist/components/schema-editor/tables/SchemaTableRenderer.js +1 -1
- package/dist/components/schema-editor/toolbar/SchemaToolbar.cjs +1 -1
- package/dist/components/schema-editor/toolbar/SchemaToolbar.js +1 -1
- package/dist/components/select/Select.cjs +1 -1
- package/dist/components/select/Select.js +1 -1
- package/dist/components/tabs/Tabs.cjs +1 -1
- package/dist/components/tabs/Tabs.js +1 -1
- package/dist/components/tabs/TabsContent.cjs +1 -1
- package/dist/components/tabs/TabsContent.js +1 -1
- package/dist/components/tabs/TabsContext.cjs +1 -1
- package/dist/components/tabs/TabsContext.js +1 -1
- package/dist/components/tabs/TabsList.cjs +1 -1
- package/dist/components/tabs/TabsList.js +1 -1
- package/dist/components/tabs/TabsTrigger.cjs +1 -1
- package/dist/components/tabs/TabsTrigger.js +1 -1
- package/dist/components/toast/Toast.cjs +1 -1
- package/dist/components/toast/Toast.js +1 -1
- package/dist/components/waterfall-chart/WaterfallChart.cjs +1 -1
- package/dist/components/waterfall-chart/WaterfallChart.js +1 -1
- package/dist/components/wizard/Wizard.cjs +1 -1
- package/dist/components/wizard/Wizard.js +1 -1
- package/dist/components/workflow-editor/WorkflowEditor.cjs +1 -1
- package/dist/components/workflow-editor/WorkflowEditor.js +1 -1
- package/dist/components/workflow-editor/toolbar/WorkflowToolbar.cjs +1 -1
- package/dist/components/workflow-editor/toolbar/WorkflowToolbar.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +830 -175
- package/dist/index.d.ts +830 -175
- package/dist/index.js +1 -1
- package/dist/lib/aria-hide.cjs +1 -1
- package/dist/lib/aria-hide.js +1 -1
- package/dist/lib/csv.cjs +2 -0
- package/dist/lib/csv.js +2 -0
- package/dist/lib/i18n.cjs +1 -1
- package/dist/lib/i18n.js +1 -1
- package/dist/lib/server-labels.cjs +1 -0
- package/dist/lib/server-labels.js +1 -0
- package/dist/lib/ui-labels.cjs +1 -0
- package/dist/lib/ui-labels.js +1 -0
- package/dist/styles.css +3070 -264
- package/package.json +14 -14
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var ge=Object.defineProperty;var wt=Object.getOwnPropertyDescriptor;var zt=Object.getOwnPropertyNames;var Ft=Object.prototype.hasOwnProperty;var Dt=(R,S)=>{for(var g in S)ge(R,g,{get:S[g],enumerable:!0})},xt=(R,S,g,J)=>{if(S&&typeof S=="object"||typeof S=="function")for(let F of zt(S))!Ft.call(R,F)&&F!==g&&ge(R,F,{get:()=>S[F],enumerable:!(J=wt(S,F))||J.enumerable});return R};var Mt=R=>xt(ge({},"__esModule",{value:!0}),R);var Ht={};Dt(Ht,{SchemaEditor:()=>$e});module.exports=Mt(Ht);var o=require("react"),Ke=require("../../lib/cn.cjs"),Oe=require("./canvas/GridLayer.cjs"),Pe=require("./tables/SchemaTableRenderer.cjs"),Be=require("./relations/SchemaRelationRenderer.cjs"),We=require("./toolbar/SchemaToolbar.cjs"),Ge=require("./legend/SchemaLegend.cjs"),Je=require("./minimap/SchemaMinimap.cjs"),a=require("./utils/geometry.cjs"),_=require("./utils/schema-helpers.cjs"),Ie=require("./utils/sql-export.cjs"),Qe=require("./utils/auto-layout.cjs"),I=require("react/jsx-runtime"),pe={x:0,y:0,zoom:1},ye=.1,Xt=.1,Yt=3,Ct=20,Lt=50;function At({value:R,defaultValue:S,onValueChange:g,fieldTypes:J=_.DEFAULT_FIELD_TYPES,onTableClick:F,onTableDoubleClick:Z,onTableContextMenu:ee,onFieldClick:Nt,onFieldDoubleClick:_t,readOnly:D=!1,disabled:h=!1,draggableTables:Ee=!0,panOnDrag:Re=!0,zoomOnWheel:Te=!0,editable:Y=!0,minZoom:C=Xt,maxZoom:L=Yt,snapToGrid:Se=!1,gridSize:te=Ct,showGrid:qe=!0,toolbar:je=!0,legend:ve=!0,autoFit:we=!1,className:Ze},et){let k=R!==void 0,[tt,ne]=(0,o.useState)(()=>S??{tables:[],relations:[],viewport:{...pe}}),z=k?R:tt,T=z.tables,re=z.relations,s=z.viewport??pe,x=(0,o.useRef)(null),A=(0,o.useRef)(null),[U,O]=(0,o.useState)(null),[P,B]=(0,o.useState)(null),[M,oe]=(0,o.useState)(null),[ze,Fe]=(0,o.useState)(null),[ie,nt]=(0,o.useState)({width:0,height:0}),v=(0,o.useRef)([]),w=(0,o.useRef)(-1),W=(0,o.useRef)(!1),Q=(0,o.useRef)(s);Q.current=s;let De=(0,o.useRef)(T);De.current=T;let xe=(0,o.useRef)(re);xe.current=re;let Me=(0,o.useRef)(Se);Me.current=Se;let se=(0,o.useRef)(te);se.current=te;let Xe=(0,o.useRef)(Y);Xe.current=Y;let le=(0,o.useCallback)(e=>{if(W.current)return;let t=v.current,r=w.current;v.current=t.slice(0,r+1),v.current.push(e),v.current.length>Lt&&v.current.shift(),w.current=v.current.length-1},[]),l=(0,o.useCallback)(e=>{if(k){let t=e(R);le(t),g?.(t)}else ne(t=>{let r=e(t);return le(r),g?.(r),r})},[k,R,g,le]),$=(0,o.useRef)(l);$.current=l;let E=(0,o.useCallback)(e=>{l(t=>({...t,viewport:e}))},[l]),Ye=(0,o.useRef)(E);Ye.current=E,(0,o.useEffect)(()=>{function e(n){let i=A.current;if(!i)return;let u=x.current?.getBoundingClientRect();if(!u)return;let f=Q.current;if(i.type==="pan"){let m=n.clientX-i.startX,c=n.clientY-i.startY;Ye.current({...f,x:i.startVpX+m,y:i.startVpY+c})}if(i.type==="table"){let m=(0,a.screenToCanvas)(n.clientX,n.clientY,f,u),c=m.x-i.offsetX,p=m.y-i.offsetY;Me.current&&(c=(0,a.snapValue)(c,se.current),p=(0,a.snapValue)(p,se.current)),$.current(d=>({...d,tables:d.tables.map(y=>y.id===i.tableId?{...y,x:c,y:p}:y)}))}if(i.type==="relation"){let m=(0,a.screenToCanvas)(n.clientX,n.clientY,f,u);A.current={...i,currentX:m.x,currentY:m.y},oe({fromX:i.fromX,fromY:i.fromY,currentX:m.x,currentY:m.y})}if(i.type==="resize"){let m=(n.clientX-i.startX)/f.zoom,c=(n.clientY-i.startY)/f.zoom,p=180,d=80,y=Math.max(p,i.startWidth+m),b=Math.max(d,i.startHeight+c);$.current(H=>({...H,tables:H.tables.map(X=>X.id===i.tableId?{...X,width:y,height:b}:X)}))}}function t(n,i,u,f){let m=Q.current,c=(0,a.screenToCanvas)(n,i,m,u),p=1/0,d=null,y=null;for(let b of f){if(b.collapsed)continue;let H=b.fields.length;if(H===0)continue;let X=b.width??a.DEFAULT_TABLE_WIDTH,K=a.HEADER_HEIGHT+H*a.FIELD_ROW_HEIGHT+(Xe.current?a.ADD_BUTTON_HEIGHT:0),N=40;if(!(c.x<b.x-N||c.x>b.x+X+N||c.y<b.y-N||c.y>b.y+K+N))for(let j=0;j<b.fields.length;j++){let vt=b.y+(0,a.getFieldConnectionY)(j,!!b.notes),Ve=Math.abs(c.y-vt);Ve<p&&(p=Ve,d=b.id,y=b.fields[j].id)}}return d&&y?{tableId:d,fieldId:y}:null}function r(n){let i=A.current;if(i){if(i.type==="relation"){let u=x.current?.getBoundingClientRect();if(u){let f=xe.current,m=De.current,c=t(n.clientX,n.clientY,u,m);if(c&&c.tableId!==i.fromTableId&&!f.some(d=>d.from.tableId===i.fromTableId&&d.from.fieldId===i.fromFieldId&&d.to.tableId===c.tableId&&d.to.fieldId===c.fieldId)){let d=i.fromTableId,y=i.fromFieldId,b=c.tableId,H=c.fieldId;$.current(X=>({...X,tables:X.tables.map(K=>K.id===b?{...K,fields:K.fields.map(N=>N.id===H?{...N,foreignKey:{tableId:d,fieldId:y}}:N)}:K),relations:[...X.relations,{id:(0,_.generateRelationId)(),from:{tableId:d,fieldId:y},to:{tableId:b,fieldId:H},cardinality:"1:n"}]}))}}oe(null),Fe(null)}A.current=null}}return document.addEventListener("mousemove",e),document.addEventListener("mouseup",r),()=>{document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",r)}},[]);let rt=(0,o.useCallback)(e=>{if(!Te||h)return;e.preventDefault();let t=x.current?.getBoundingClientRect();if(!t)return;let r=e.clientX-t.left,n=e.clientY-t.top,i=e.deltaY<0?1:-1,u=(0,a.clampZoom)(s.zoom+i*ye,C,L),f=u/s.zoom;E({x:r-(r-s.x)*f,y:n-(n-s.y)*f,zoom:u})},[Te,h,s,C,L,E]),ot=(0,o.useCallback)(e=>{if(h)return;let t=e.target,r=t.tagName,n=r==="INPUT"||r==="SELECT"||r==="TEXTAREA"||r==="BUTTON";if(t.closest("[data-resize-handle]"))return;let i=t.closest("[data-connection-side]");if(i&&!n){if(D)return;e.preventDefault();let f=i.getAttribute("data-table-id"),m=i.getAttribute("data-field-id");if(!f||!m)return;let c=T.find(y=>y.id===f);if(!c)return;let p=i.getAttribute("data-connection-side"),d=(0,a.getFieldConnectionPosition)(c,m,p);if(!d)return;A.current={type:"relation",fromTableId:f,fromFieldId:m,fromX:d.x,fromY:d.y,currentX:d.x,currentY:d.y},oe({fromX:d.x,fromY:d.y,currentX:d.x,currentY:d.y}),Fe(f);return}let u=t.closest("[data-table-id]");if(u){if(D)return;let f=u.getAttribute("data-table-id");if(B(null),O(f),n)return;if(Ee){let m=x.current?.getBoundingClientRect();if(!m)return;let c=T.find(d=>d.id===f);if(!c||c.locked)return;let p=(0,a.screenToCanvas)(e.clientX,e.clientY,s,m);A.current={type:"table",tableId:f,offsetX:p.x-c.x,offsetY:p.y-c.y}}return}O(null),B(null),Re&&e.button===0&&(A.current={type:"pan",startX:e.clientX,startY:e.clientY,startVpX:s.x,startVpY:s.y})},[h,D,Ee,Re,s,T]),V=(0,o.useCallback)(e=>{let t=e.target;if(t.closest("[data-connection-side]"))return null;let r=t.closest("[data-table-id]");if(!r)return null;let n=r.getAttribute("data-table-id");return T.find(i=>i.id===n)??null},[T]),it=(0,o.useCallback)(e=>{if(h)return;let t=V(e);t&&F&&F({table:t,nativeEvent:e.nativeEvent})},[F,h,V]),st=(0,o.useCallback)(e=>{if(h)return;let t=V(e);t&&Z&&Z({table:t,nativeEvent:e.nativeEvent})},[Z,h,V]),lt=(0,o.useCallback)(e=>{if(h)return;let t=V(e);t&&ee&&(e.preventDefault(),ee({table:t,nativeEvent:e.nativeEvent}))},[ee,h,V]),at=(0,o.useCallback)((e,t)=>{h||(t.stopPropagation(),O(null),B(e))},[h]),ct=(0,o.useCallback)((e,t)=>{l(r=>({...r,relations:r.relations.map(n=>n.id===e?{...n,cardinality:t}:n)}))},[l]),dt=w.current>0,ut=w.current<v.current.length-1,ae=(0,o.useCallback)(()=>{if(w.current<=0)return;W.current=!0,w.current--;let e=v.current[w.current];k||ne(e),g?.(e),W.current=!1},[k,g]),ce=(0,o.useCallback)(()=>{if(w.current>=v.current.length-1)return;W.current=!0,w.current++;let e=v.current[w.current];k||ne(e),g?.(e),W.current=!1},[k,g]),ft=(0,o.useCallback)(()=>(0,Ie.generateSQL)(z),[z]),mt=(0,o.useCallback)(()=>{l(e=>({...e,tables:(0,Qe.autoLayoutTables)(e.tables,Y)}))},[l,Y]),ht=(0,o.useCallback)((e,t,r)=>{t!==r&&l(n=>({...n,tables:n.tables.map(i=>{if(i.id!==e)return i;let u=[...i.fields],[f]=u.splice(t,1);return u.splice(r,0,f),{...i,fields:u}})}))},[l]);(0,o.useEffect)(()=>{let e=x.current;if(!e)return;let t=new ResizeObserver(r=>{for(let n of r)nt({width:n.contentRect.width,height:n.contentRect.height})});return t.observe(e),()=>t.disconnect()},[]);let Ce=(0,o.useRef)(!1);Ce.current||(Ce.current=!0,v.current=[z],w.current=0);let bt=(0,o.useCallback)(e=>{if(!(D||h)){if((e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey){e.preventDefault(),ae();return}if((e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey)){e.preventDefault(),ce();return}if(e.key==="Delete"||e.key==="Backspace"){let t=e.target;if(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT")return;U&&(l(r=>({...r,tables:r.tables.filter(n=>n.id!==U),relations:r.relations.filter(n=>n.from.tableId!==U&&n.to.tableId!==U)})),O(null)),P&&(l(r=>{let n=r.relations.find(i=>i.id===P);return{...r,tables:n?r.tables.map(i=>i.id===n.to.tableId?{...i,fields:i.fields.map(u=>u.id===n.to.fieldId?{...u,foreignKey:void 0}:u)}:i):r.tables,relations:r.relations.filter(i=>i.id!==P)}}),B(null))}e.key==="Escape"&&(O(null),B(null))}},[D,h,U,P,l,ae,ce]),gt=(0,o.useCallback)((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,name:t}:n)}))},[l]),pt=(0,o.useCallback)((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,notes:t}:n)}))},[l]),yt=(0,o.useCallback)(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e?{...r,collapsed:!r.collapsed}:r)}))},[l]),It=(0,o.useCallback)((e,t,r)=>{l(n=>({...n,tables:n.tables.map(i=>i.id===e?{...i,fields:i.fields.map(u=>u.id===t?{...u,...r}:u)}:i)}))},[l]),Et=(0,o.useCallback)(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e?{...r,fields:[...r.fields,(0,_.createDefaultField)()]}:r)}))},[l]),de=(0,o.useCallback)((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,fields:n.fields.filter(i=>i.id!==t)}:n),relations:r.relations.filter(n=>!(n.from.tableId===e&&n.from.fieldId===t)&&!(n.to.tableId===e&&n.to.fieldId===t))}))},[l]),Rt=(0,o.useCallback)((e,t,r,n,i)=>{A.current={type:"resize",tableId:e,startX:t,startY:r,startWidth:n,startHeight:i}},[]),ue=(0,o.useCallback)(()=>{let e=(0,a.clampZoom)(s.zoom+ye,C,L);E({...s,zoom:e})},[s,C,L,E]),fe=(0,o.useCallback)(()=>{let e=(0,a.clampZoom)(s.zoom-ye,C,L);E({...s,zoom:e})},[s,C,L,E]),me=(0,o.useCallback)(()=>{E({...pe})},[E]),G=(0,o.useCallback)(()=>{let e=x.current?.getBoundingClientRect();if(!e)return;let t=(0,a.fitViewport)(T,e.width,e.height,Y),r=(0,a.clampZoom)(t.zoom,C,L);E({...t,zoom:r})},[T,Y,C,L,E]),q=(0,o.useCallback)(e=>{l(t=>({...t,tables:[...t.tables,e]}))},[l]),Le=(0,o.useCallback)(e=>{l(t=>({...t,tables:t.tables.filter(r=>r.id!==e),relations:t.relations.filter(r=>r.from.tableId!==e&&r.to.tableId!==e)}))},[l]),Ae=(0,o.useCallback)((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,fields:[...n.fields,t]}:n)}))},[l]),He=(0,o.useCallback)((e,t)=>{de(e,t)},[de]),Ne=(0,o.useCallback)(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e.to.tableId?{...r,fields:r.fields.map(n=>n.id===e.to.fieldId?{...n,foreignKey:{tableId:e.from.tableId,fieldId:e.from.fieldId}}:n)}:r),relations:[...t.relations,e]}))},[l]),_e=(0,o.useCallback)(e=>{l(t=>{let r=t.relations.find(n=>n.id===e);return{...t,tables:r?t.tables.map(n=>n.id===r.to.tableId?{...n,fields:n.fields.map(i=>i.id===r.to.fieldId?{...i,foreignKey:void 0}:i)}:n):t.tables,relations:t.relations.filter(n=>n.id!==e)}})},[l]),he=(0,o.useCallback)(()=>JSON.stringify(z,null,2),[z]),be=(0,o.useCallback)(e=>{try{let t=JSON.parse(e);t&&Array.isArray(t.tables)&&Array.isArray(t.relations)&&l(()=>t)}catch{}},[l]),Tt=(0,o.useCallback)(()=>{let e=x.current?.getBoundingClientRect(),t=Q.current,r=100,n=100;e&&(r=(e.width/2-t.x)/t.zoom-a.DEFAULT_TABLE_WIDTH/2,n=(e.height/2-t.y)/t.zoom-60),q((0,_.createDefaultTable)(r,n))},[q]),ke=(0,o.useCallback)(()=>(0,Ie.generateSQL)(z),[z]);(0,o.useImperativeHandle)(et,()=>({zoomIn:ue,zoomOut:fe,resetView:me,fitToContent:G,addTable:q,removeTable:Le,addField:Ae,removeField:He,addRelation:Ne,removeRelation:_e,toJSON:he,loadJSON:be,toSQL:ke}),[ue,fe,me,G,q,Le,Ae,He,Ne,_e,he,be,ke]);let Ue=(0,o.useRef)(!1);(0,o.useEffect)(()=>{we&&!Ue.current&&x.current&&(Ue.current=!0,G())},[we,G]);let St=(0,o.useMemo)(()=>({transform:`translate(${s.x}px, ${s.y}px) scale(${s.zoom})`,transformOrigin:"0 0"}),[s.x,s.y,s.zoom]);return(0,I.jsxs)("div",{ref:x,"data-testid":"schema-editor",className:(0,Ke.cn)("relative w-full overflow-hidden bg-gray-50 dark:bg-gray-900 select-none",h&&"opacity-60 pointer-events-none",Ze),tabIndex:0,onWheel:rt,onMouseDown:ot,onClick:it,onDoubleClick:st,onContextMenu:lt,onKeyDown:bt,children:[qe&&(0,I.jsx)(Oe.GridLayer,{gridSize:te,zoom:s.zoom}),je&&!D&&(0,I.jsx)(We.SchemaToolbar,{zoom:s.zoom,onZoomIn:ue,onZoomOut:fe,onResetView:me,onFitToContent:G,onAddTable:Tt,onExportJSON:he,onImportJSON:be,onExportSQL:ft,onUndo:ae,onRedo:ce,canUndo:dt,canRedo:ut,onAutoLayout:mt,disabled:h}),ve&&(0,I.jsx)(Ge.SchemaLegend,{}),(0,I.jsx)(Be.SchemaRelationRenderer,{relations:re,tables:T,viewport:s,selectedRelationId:P,disabled:h||D,onRelationClick:at,onCardinalityChange:ct}),(0,I.jsx)("div",{style:St,children:T.map(e=>(0,I.jsx)(Pe.SchemaTableRenderer,{table:e,selected:U===e.id,disabled:h||D,readOnly:D,editable:Y,dropTarget:ze!==null&&ze!==e.id&&!e.collapsed,fieldTypes:J,onTableNameChange:gt,onTableNotesChange:pt,onToggleCollapse:yt,onFieldChange:It,onFieldAdd:Et,onFieldRemove:de,onFieldReorder:ht,onResizeStart:Rt},e.id))}),M&&(0,I.jsxs)("svg",{"data-testid":"drag-relation-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:1e3,overflow:"visible"},children:[(0,I.jsx)("path",{d:(0,a.computeBezierPath)(M.fromX*s.zoom+s.x,M.fromY*s.zoom+s.y,M.currentX*s.zoom+s.x,M.currentY*s.zoom+s.y),fill:"none",stroke:"#3b82f6",strokeWidth:2.5,strokeDasharray:"8 4"}),(0,I.jsx)("circle",{cx:M.fromX*s.zoom+s.x,cy:M.fromY*s.zoom+s.y,r:5,fill:"#3b82f6"}),(0,I.jsx)("circle",{cx:M.currentX*s.zoom+s.x,cy:M.currentY*s.zoom+s.y,r:4,fill:"#3b82f6",opacity:.6})]}),ve&&ie.width>0&&(0,I.jsx)(Je.SchemaMinimap,{tables:T,viewport:s,containerWidth:ie.width,containerHeight:ie.height,editable:Y,onViewportChange:E})]})}var $e=(0,o.forwardRef)(At);$e.displayName="SchemaEditor";0&&(module.exports={SchemaEditor});
|
|
1
|
+
"use strict";"use client";var pe=Object.defineProperty;var Dt=Object.getOwnPropertyDescriptor;var xt=Object.getOwnPropertyNames;var Mt=Object.prototype.hasOwnProperty;var Xt=(R,S)=>{for(var g in S)pe(R,g,{get:S[g],enumerable:!0})},Yt=(R,S,g,J)=>{if(S&&typeof S=="object"||typeof S=="function")for(let F of xt(S))!Mt.call(R,F)&&F!==g&&pe(R,F,{get:()=>S[F],enumerable:!(J=Dt(S,F))||J.enumerable});return R};var Lt=R=>Yt(pe({},"__esModule",{value:!0}),R);var kt={};Xt(kt,{SchemaEditor:()=>je});module.exports=Lt(kt);var o=require("react"),Oe=require("../../lib/cn.cjs"),Pe=require("../../lib/i18n.cjs"),Be=require("./canvas/GridLayer.cjs"),We=require("./tables/SchemaTableRenderer.cjs"),Ge=require("./relations/SchemaRelationRenderer.cjs"),Je=require("./toolbar/SchemaToolbar.cjs"),Qe=require("./legend/SchemaLegend.cjs"),$e=require("./minimap/SchemaMinimap.cjs"),a=require("./utils/geometry.cjs"),_=require("./utils/schema-helpers.cjs"),Ee=require("./utils/sql-export.cjs"),qe=require("./utils/auto-layout.cjs"),I=require("react/jsx-runtime"),ye={x:0,y:0,zoom:1},Ie=.1,Ct=.1,At=3,Ht=20,Nt=50;function _t({value:R,defaultValue:S,onValueChange:g,fieldTypes:J=_.DEFAULT_FIELD_TYPES,onTableClick:F,onTableDoubleClick:Z,onTableContextMenu:ee,onFieldClick:Ut,onFieldDoubleClick:Vt,readOnly:D=!1,disabled:b=!1,draggableTables:Re=!0,panOnDrag:Te=!0,zoomOnWheel:Se=!0,editable:Y=!0,minZoom:L=Ct,maxZoom:C=At,snapToGrid:ve=!1,gridSize:te=Ht,showGrid:Ze=!0,toolbar:et=!0,legend:we=!0,autoFit:ze=!1,labels:tt,className:nt},rt){let ne=(0,Pe.useUILabels)(tt),k=R!==void 0,[ot,re]=(0,o.useState)(()=>S??{tables:[],relations:[],viewport:{...ye}}),z=k?R:ot,T=z.tables,oe=z.relations,s=z.viewport??ye,x=(0,o.useRef)(null),A=(0,o.useRef)(null),[U,O]=(0,o.useState)(null),[P,B]=(0,o.useState)(null),[M,ie]=(0,o.useState)(null),[Fe,De]=(0,o.useState)(null),[se,it]=(0,o.useState)({width:0,height:0}),v=(0,o.useRef)([]),w=(0,o.useRef)(-1),W=(0,o.useRef)(!1),Q=(0,o.useRef)(s);Q.current=s;let xe=(0,o.useRef)(T);xe.current=T;let Me=(0,o.useRef)(oe);Me.current=oe;let Xe=(0,o.useRef)(ve);Xe.current=ve;let le=(0,o.useRef)(te);le.current=te;let Ye=(0,o.useRef)(Y);Ye.current=Y;let ae=(0,o.useCallback)(e=>{if(W.current)return;let t=v.current,r=w.current;v.current=t.slice(0,r+1),v.current.push(e),v.current.length>Nt&&v.current.shift(),w.current=v.current.length-1},[]),l=(0,o.useCallback)(e=>{if(k){let t=e(R);ae(t),g?.(t)}else re(t=>{let r=e(t);return ae(r),g?.(r),r})},[k,R,g,ae]),$=(0,o.useRef)(l);$.current=l;let E=(0,o.useCallback)(e=>{l(t=>({...t,viewport:e}))},[l]),Le=(0,o.useRef)(E);Le.current=E,(0,o.useEffect)(()=>{function e(n){let i=A.current;if(!i)return;let u=x.current?.getBoundingClientRect();if(!u)return;let f=Q.current;if(i.type==="pan"){let m=n.clientX-i.startX,c=n.clientY-i.startY;Le.current({...f,x:i.startVpX+m,y:i.startVpY+c})}if(i.type==="table"){let m=(0,a.screenToCanvas)(n.clientX,n.clientY,f,u),c=m.x-i.offsetX,p=m.y-i.offsetY;Xe.current&&(c=(0,a.snapValue)(c,le.current),p=(0,a.snapValue)(p,le.current)),$.current(d=>({...d,tables:d.tables.map(y=>y.id===i.tableId?{...y,x:c,y:p}:y)}))}if(i.type==="relation"){let m=(0,a.screenToCanvas)(n.clientX,n.clientY,f,u);A.current={...i,currentX:m.x,currentY:m.y},ie({fromX:i.fromX,fromY:i.fromY,currentX:m.x,currentY:m.y})}if(i.type==="resize"){let m=(n.clientX-i.startX)/f.zoom,c=(n.clientY-i.startY)/f.zoom,p=180,d=80,y=Math.max(p,i.startWidth+m),h=Math.max(d,i.startHeight+c);$.current(H=>({...H,tables:H.tables.map(X=>X.id===i.tableId?{...X,width:y,height:h}:X)}))}}function t(n,i,u,f){let m=Q.current,c=(0,a.screenToCanvas)(n,i,m,u),p=1/0,d=null,y=null;for(let h of f){if(h.collapsed)continue;let H=h.fields.length;if(H===0)continue;let X=h.width??a.DEFAULT_TABLE_WIDTH,K=a.HEADER_HEIGHT+H*a.FIELD_ROW_HEIGHT+(Ye.current?a.ADD_BUTTON_HEIGHT:0),N=40;if(!(c.x<h.x-N||c.x>h.x+X+N||c.y<h.y-N||c.y>h.y+K+N))for(let j=0;j<h.fields.length;j++){let Ft=h.y+(0,a.getFieldConnectionY)(j,!!h.notes),Ke=Math.abs(c.y-Ft);Ke<p&&(p=Ke,d=h.id,y=h.fields[j].id)}}return d&&y?{tableId:d,fieldId:y}:null}function r(n){let i=A.current;if(i){if(i.type==="relation"){let u=x.current?.getBoundingClientRect();if(u){let f=Me.current,m=xe.current,c=t(n.clientX,n.clientY,u,m);if(c&&c.tableId!==i.fromTableId&&!f.some(d=>d.from.tableId===i.fromTableId&&d.from.fieldId===i.fromFieldId&&d.to.tableId===c.tableId&&d.to.fieldId===c.fieldId)){let d=i.fromTableId,y=i.fromFieldId,h=c.tableId,H=c.fieldId;$.current(X=>({...X,tables:X.tables.map(K=>K.id===h?{...K,fields:K.fields.map(N=>N.id===H?{...N,foreignKey:{tableId:d,fieldId:y}}:N)}:K),relations:[...X.relations,{id:(0,_.generateRelationId)(),from:{tableId:d,fieldId:y},to:{tableId:h,fieldId:H},cardinality:"1:n"}]}))}}ie(null),De(null)}A.current=null}}return document.addEventListener("mousemove",e),document.addEventListener("mouseup",r),()=>{document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",r)}},[]);let st=(0,o.useCallback)(e=>{if(!Se||b)return;e.preventDefault();let t=x.current?.getBoundingClientRect();if(!t)return;let r=e.clientX-t.left,n=e.clientY-t.top,i=e.deltaY<0?1:-1,u=(0,a.clampZoom)(s.zoom+i*Ie,L,C),f=u/s.zoom;E({x:r-(r-s.x)*f,y:n-(n-s.y)*f,zoom:u})},[Se,b,s,L,C,E]),lt=(0,o.useCallback)(e=>{if(b)return;let t=e.target,r=t.tagName,n=r==="INPUT"||r==="SELECT"||r==="TEXTAREA"||r==="BUTTON";if(t.closest("[data-resize-handle]"))return;let i=t.closest("[data-connection-side]");if(i&&!n){if(D)return;e.preventDefault();let f=i.getAttribute("data-table-id"),m=i.getAttribute("data-field-id");if(!f||!m)return;let c=T.find(y=>y.id===f);if(!c)return;let p=i.getAttribute("data-connection-side"),d=(0,a.getFieldConnectionPosition)(c,m,p);if(!d)return;A.current={type:"relation",fromTableId:f,fromFieldId:m,fromX:d.x,fromY:d.y,currentX:d.x,currentY:d.y},ie({fromX:d.x,fromY:d.y,currentX:d.x,currentY:d.y}),De(f);return}let u=t.closest("[data-table-id]");if(u){if(D)return;let f=u.getAttribute("data-table-id");if(B(null),O(f),n)return;if(Re){let m=x.current?.getBoundingClientRect();if(!m)return;let c=T.find(d=>d.id===f);if(!c||c.locked)return;let p=(0,a.screenToCanvas)(e.clientX,e.clientY,s,m);A.current={type:"table",tableId:f,offsetX:p.x-c.x,offsetY:p.y-c.y}}return}O(null),B(null),Te&&e.button===0&&(A.current={type:"pan",startX:e.clientX,startY:e.clientY,startVpX:s.x,startVpY:s.y})},[b,D,Re,Te,s,T]),V=(0,o.useCallback)(e=>{let t=e.target;if(t.closest("[data-connection-side]"))return null;let r=t.closest("[data-table-id]");if(!r)return null;let n=r.getAttribute("data-table-id");return T.find(i=>i.id===n)??null},[T]),at=(0,o.useCallback)(e=>{if(b)return;let t=V(e);t&&F&&F({table:t,nativeEvent:e.nativeEvent})},[F,b,V]),ct=(0,o.useCallback)(e=>{if(b)return;let t=V(e);t&&Z&&Z({table:t,nativeEvent:e.nativeEvent})},[Z,b,V]),dt=(0,o.useCallback)(e=>{if(b)return;let t=V(e);t&&ee&&(e.preventDefault(),ee({table:t,nativeEvent:e.nativeEvent}))},[ee,b,V]),ut=(0,o.useCallback)((e,t)=>{b||(t.stopPropagation(),O(null),B(e))},[b]),ft=(0,o.useCallback)((e,t)=>{l(r=>({...r,relations:r.relations.map(n=>n.id===e?{...n,cardinality:t}:n)}))},[l]),mt=w.current>0,bt=w.current<v.current.length-1,ce=(0,o.useCallback)(()=>{if(w.current<=0)return;W.current=!0,w.current--;let e=v.current[w.current];k||re(e),g?.(e),W.current=!1},[k,g]),de=(0,o.useCallback)(()=>{if(w.current>=v.current.length-1)return;W.current=!0,w.current++;let e=v.current[w.current];k||re(e),g?.(e),W.current=!1},[k,g]),ht=(0,o.useCallback)(()=>(0,Ee.generateSQL)(z),[z]),gt=(0,o.useCallback)(()=>{l(e=>({...e,tables:(0,qe.autoLayoutTables)(e.tables,Y)}))},[l,Y]),pt=(0,o.useCallback)((e,t,r)=>{t!==r&&l(n=>({...n,tables:n.tables.map(i=>{if(i.id!==e)return i;let u=[...i.fields],[f]=u.splice(t,1);return u.splice(r,0,f),{...i,fields:u}})}))},[l]);(0,o.useEffect)(()=>{let e=x.current;if(!e)return;let t=new ResizeObserver(r=>{for(let n of r)it({width:n.contentRect.width,height:n.contentRect.height})});return t.observe(e),()=>t.disconnect()},[]);let Ce=(0,o.useRef)(!1);Ce.current||(Ce.current=!0,v.current=[z],w.current=0);let yt=(0,o.useCallback)(e=>{if(!(D||b)){if((e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey){e.preventDefault(),ce();return}if((e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey)){e.preventDefault(),de();return}if(e.key==="Delete"||e.key==="Backspace"){let t=e.target;if(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT")return;U&&(l(r=>({...r,tables:r.tables.filter(n=>n.id!==U),relations:r.relations.filter(n=>n.from.tableId!==U&&n.to.tableId!==U)})),O(null)),P&&(l(r=>{let n=r.relations.find(i=>i.id===P);return{...r,tables:n?r.tables.map(i=>i.id===n.to.tableId?{...i,fields:i.fields.map(u=>u.id===n.to.fieldId?{...u,foreignKey:void 0}:u)}:i):r.tables,relations:r.relations.filter(i=>i.id!==P)}}),B(null))}e.key==="Escape"&&(O(null),B(null))}},[D,b,U,P,l,ce,de]),It=(0,o.useCallback)((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,name:t}:n)}))},[l]),Et=(0,o.useCallback)((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,notes:t}:n)}))},[l]),Rt=(0,o.useCallback)(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e?{...r,collapsed:!r.collapsed}:r)}))},[l]),Tt=(0,o.useCallback)((e,t,r)=>{l(n=>({...n,tables:n.tables.map(i=>i.id===e?{...i,fields:i.fields.map(u=>u.id===t?{...u,...r}:u)}:i)}))},[l]),St=(0,o.useCallback)(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e?{...r,fields:[...r.fields,(0,_.createDefaultField)()]}:r)}))},[l]),ue=(0,o.useCallback)((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,fields:n.fields.filter(i=>i.id!==t)}:n),relations:r.relations.filter(n=>!(n.from.tableId===e&&n.from.fieldId===t)&&!(n.to.tableId===e&&n.to.fieldId===t))}))},[l]),vt=(0,o.useCallback)((e,t,r,n,i)=>{A.current={type:"resize",tableId:e,startX:t,startY:r,startWidth:n,startHeight:i}},[]),fe=(0,o.useCallback)(()=>{let e=(0,a.clampZoom)(s.zoom+Ie,L,C);E({...s,zoom:e})},[s,L,C,E]),me=(0,o.useCallback)(()=>{let e=(0,a.clampZoom)(s.zoom-Ie,L,C);E({...s,zoom:e})},[s,L,C,E]),be=(0,o.useCallback)(()=>{E({...ye})},[E]),G=(0,o.useCallback)(()=>{let e=x.current?.getBoundingClientRect();if(!e)return;let t=(0,a.fitViewport)(T,e.width,e.height,Y),r=(0,a.clampZoom)(t.zoom,L,C);E({...t,zoom:r})},[T,Y,L,C,E]),q=(0,o.useCallback)(e=>{l(t=>({...t,tables:[...t.tables,e]}))},[l]),Ae=(0,o.useCallback)(e=>{l(t=>({...t,tables:t.tables.filter(r=>r.id!==e),relations:t.relations.filter(r=>r.from.tableId!==e&&r.to.tableId!==e)}))},[l]),He=(0,o.useCallback)((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,fields:[...n.fields,t]}:n)}))},[l]),Ne=(0,o.useCallback)((e,t)=>{ue(e,t)},[ue]),_e=(0,o.useCallback)(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e.to.tableId?{...r,fields:r.fields.map(n=>n.id===e.to.fieldId?{...n,foreignKey:{tableId:e.from.tableId,fieldId:e.from.fieldId}}:n)}:r),relations:[...t.relations,e]}))},[l]),ke=(0,o.useCallback)(e=>{l(t=>{let r=t.relations.find(n=>n.id===e);return{...t,tables:r?t.tables.map(n=>n.id===r.to.tableId?{...n,fields:n.fields.map(i=>i.id===r.to.fieldId?{...i,foreignKey:void 0}:i)}:n):t.tables,relations:t.relations.filter(n=>n.id!==e)}})},[l]),he=(0,o.useCallback)(()=>JSON.stringify(z,null,2),[z]),ge=(0,o.useCallback)(e=>{try{let t=JSON.parse(e);t&&Array.isArray(t.tables)&&Array.isArray(t.relations)&&l(()=>t)}catch{}},[l]),wt=(0,o.useCallback)(()=>{let e=x.current?.getBoundingClientRect(),t=Q.current,r=100,n=100;e&&(r=(e.width/2-t.x)/t.zoom-a.DEFAULT_TABLE_WIDTH/2,n=(e.height/2-t.y)/t.zoom-60),q((0,_.createDefaultTable)(r,n))},[q]),Ue=(0,o.useCallback)(()=>(0,Ee.generateSQL)(z),[z]);(0,o.useImperativeHandle)(rt,()=>({zoomIn:fe,zoomOut:me,resetView:be,fitToContent:G,addTable:q,removeTable:Ae,addField:He,removeField:Ne,addRelation:_e,removeRelation:ke,toJSON:he,loadJSON:ge,toSQL:Ue}),[fe,me,be,G,q,Ae,He,Ne,_e,ke,he,ge,Ue]);let Ve=(0,o.useRef)(!1);(0,o.useEffect)(()=>{ze&&!Ve.current&&x.current&&(Ve.current=!0,G())},[ze,G]);let zt=(0,o.useMemo)(()=>({transform:`translate(${s.x}px, ${s.y}px) scale(${s.zoom})`,transformOrigin:"0 0"}),[s.x,s.y,s.zoom]);return(0,I.jsxs)("div",{ref:x,"data-testid":"schema-editor",className:(0,Oe.cn)("relative w-full overflow-hidden bg-gray-50 dark:bg-gray-900 select-none",b&&"opacity-60 pointer-events-none",nt),tabIndex:0,onWheel:st,onMouseDown:lt,onClick:at,onDoubleClick:ct,onContextMenu:dt,onKeyDown:yt,children:[Ze&&(0,I.jsx)(Be.GridLayer,{gridSize:te,zoom:s.zoom}),et&&!D&&(0,I.jsx)(Je.SchemaToolbar,{zoom:s.zoom,onZoomIn:fe,onZoomOut:me,onResetView:be,onFitToContent:G,onAddTable:wt,onExportJSON:he,onImportJSON:ge,onExportSQL:ht,onUndo:ce,onRedo:de,canUndo:mt,canRedo:bt,onAutoLayout:gt,disabled:b,labels:ne}),we&&(0,I.jsx)(Qe.SchemaLegend,{labels:ne}),(0,I.jsx)(Ge.SchemaRelationRenderer,{relations:oe,tables:T,viewport:s,selectedRelationId:P,disabled:b||D,onRelationClick:ut,onCardinalityChange:ft}),(0,I.jsx)("div",{style:zt,children:T.map(e=>(0,I.jsx)(We.SchemaTableRenderer,{table:e,selected:U===e.id,disabled:b||D,readOnly:D,editable:Y,dropTarget:Fe!==null&&Fe!==e.id&&!e.collapsed,fieldTypes:J,onTableNameChange:It,onTableNotesChange:Et,onToggleCollapse:Rt,onFieldChange:Tt,onFieldAdd:St,onFieldRemove:ue,onFieldReorder:pt,onResizeStart:vt,labels:ne},e.id))}),M&&(0,I.jsxs)("svg",{"data-testid":"drag-relation-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:1e3,overflow:"visible"},children:[(0,I.jsx)("path",{d:(0,a.computeBezierPath)(M.fromX*s.zoom+s.x,M.fromY*s.zoom+s.y,M.currentX*s.zoom+s.x,M.currentY*s.zoom+s.y),fill:"none",stroke:"#3b82f6",strokeWidth:2.5,strokeDasharray:"8 4"}),(0,I.jsx)("circle",{cx:M.fromX*s.zoom+s.x,cy:M.fromY*s.zoom+s.y,r:5,fill:"#3b82f6"}),(0,I.jsx)("circle",{cx:M.currentX*s.zoom+s.x,cy:M.currentY*s.zoom+s.y,r:4,fill:"#3b82f6",opacity:.6})]}),we&&se.width>0&&(0,I.jsx)($e.SchemaMinimap,{tables:T,viewport:s,containerWidth:se.width,containerHeight:se.height,editable:Y,onViewportChange:E})]})}var je=(0,o.forwardRef)(_t);je.displayName="SchemaEditor";0&&(module.exports={SchemaEditor});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{forwardRef as Rt,useCallback as s,useEffect as ge,useImperativeHandle as Tt,useMemo as St,useRef as b,useState as k}from"react";import{cn as vt}from"../../lib/cn.js";import{GridLayer as wt}from"./canvas/GridLayer.js";import{SchemaTableRenderer as zt}from"./tables/SchemaTableRenderer.js";import{SchemaRelationRenderer as Ft}from"./relations/SchemaRelationRenderer.js";import{SchemaToolbar as Dt}from"./toolbar/SchemaToolbar.js";import{SchemaLegend as xt}from"./legend/SchemaLegend.js";import{SchemaMinimap as Mt}from"./minimap/SchemaMinimap.js";import{ADD_BUTTON_HEIGHT as Xt,clampZoom as $,computeBezierPath as Yt,DEFAULT_TABLE_WIDTH as Ve,FIELD_ROW_HEIGHT as Ct,fitViewport as Lt,getFieldConnectionPosition as At,getFieldConnectionY as Ht,HEADER_HEIGHT as Nt,screenToCanvas as q,snapValue as Ke}from"./utils/geometry.js";import{createDefaultField as _t,createDefaultTable as kt,DEFAULT_FIELD_TYPES as Ut,generateRelationId as Vt}from"./utils/schema-helpers.js";import{generateSQL as Oe}from"./utils/sql-export.js";import{autoLayoutTables as Kt}from"./utils/auto-layout.js";import{jsx as S,jsxs as Pe}from"react/jsx-runtime";var pe={x:0,y:0,zoom:1},ye=.1,Ot=.1,Pt=3,Bt=20,Wt=50;function Gt({value:B,defaultValue:Be,onValueChange:v,fieldTypes:We=Ut,onTableClick:j,onTableDoubleClick:Z,onTableContextMenu:ee,onFieldClick:Qt,onFieldDoubleClick:$t,readOnly:w=!1,disabled:m=!1,draggableTables:Ie=!0,panOnDrag:Ee=!0,zoomOnWheel:Re=!0,editable:x=!0,minZoom:M=Ot,maxZoom:X=Pt,snapToGrid:Te=!1,gridSize:te=Bt,showGrid:Ge=!0,toolbar:Je=!0,legend:Se=!0,autoFit:ve=!1,className:Qe},$e){let A=B!==void 0,[qe,ne]=k(()=>Be??{tables:[],relations:[],viewport:{...pe}}),T=A?B:qe,I=T.tables,re=T.relations,i=T.viewport??pe,z=b(null),Y=b(null),[H,U]=k(null),[V,K]=k(null),[F,oe]=k(null),[we,ze]=k(null),[ie,je]=k({width:0,height:0}),E=b([]),R=b(-1),O=b(!1),W=b(i);W.current=i;let Fe=b(I);Fe.current=I;let De=b(re);De.current=re;let xe=b(Te);xe.current=Te;let se=b(te);se.current=te;let Me=b(x);Me.current=x;let le=s(e=>{if(O.current)return;let t=E.current,r=R.current;E.current=t.slice(0,r+1),E.current.push(e),E.current.length>Wt&&E.current.shift(),R.current=E.current.length-1},[]),l=s(e=>{if(A){let t=e(B);le(t),v?.(t)}else ne(t=>{let r=e(t);return le(r),v?.(r),r})},[A,B,v,le]),G=b(l);G.current=l;let y=s(e=>{l(t=>({...t,viewport:e}))},[l]),Xe=b(y);Xe.current=y,ge(()=>{function e(n){let o=Y.current;if(!o)return;let d=z.current?.getBoundingClientRect();if(!d)return;let u=W.current;if(o.type==="pan"){let f=n.clientX-o.startX,a=n.clientY-o.startY;Xe.current({...u,x:o.startVpX+f,y:o.startVpY+a})}if(o.type==="table"){let f=q(n.clientX,n.clientY,u,d),a=f.x-o.offsetX,g=f.y-o.offsetY;xe.current&&(a=Ke(a,se.current),g=Ke(g,se.current)),G.current(c=>({...c,tables:c.tables.map(p=>p.id===o.tableId?{...p,x:a,y:g}:p)}))}if(o.type==="relation"){let f=q(n.clientX,n.clientY,u,d);Y.current={...o,currentX:f.x,currentY:f.y},oe({fromX:o.fromX,fromY:o.fromY,currentX:f.x,currentY:f.y})}if(o.type==="resize"){let f=(n.clientX-o.startX)/u.zoom,a=(n.clientY-o.startY)/u.zoom,g=180,c=80,p=Math.max(g,o.startWidth+f),h=Math.max(c,o.startHeight+a);G.current(C=>({...C,tables:C.tables.map(D=>D.id===o.tableId?{...D,width:p,height:h}:D)}))}}function t(n,o,d,u){let f=W.current,a=q(n,o,f,d),g=1/0,c=null,p=null;for(let h of u){if(h.collapsed)continue;let C=h.fields.length;if(C===0)continue;let D=h.width??Ve,_=Nt+C*Ct+(Me.current?Xt:0),L=40;if(!(a.x<h.x-L||a.x>h.x+D+L||a.y<h.y-L||a.y>h.y+_+L))for(let Q=0;Q<h.fields.length;Q++){let Et=h.y+Ht(Q,!!h.notes),Ue=Math.abs(a.y-Et);Ue<g&&(g=Ue,c=h.id,p=h.fields[Q].id)}}return c&&p?{tableId:c,fieldId:p}:null}function r(n){let o=Y.current;if(o){if(o.type==="relation"){let d=z.current?.getBoundingClientRect();if(d){let u=De.current,f=Fe.current,a=t(n.clientX,n.clientY,d,f);if(a&&a.tableId!==o.fromTableId&&!u.some(c=>c.from.tableId===o.fromTableId&&c.from.fieldId===o.fromFieldId&&c.to.tableId===a.tableId&&c.to.fieldId===a.fieldId)){let c=o.fromTableId,p=o.fromFieldId,h=a.tableId,C=a.fieldId;G.current(D=>({...D,tables:D.tables.map(_=>_.id===h?{..._,fields:_.fields.map(L=>L.id===C?{...L,foreignKey:{tableId:c,fieldId:p}}:L)}:_),relations:[...D.relations,{id:Vt(),from:{tableId:c,fieldId:p},to:{tableId:h,fieldId:C},cardinality:"1:n"}]}))}}oe(null),ze(null)}Y.current=null}}return document.addEventListener("mousemove",e),document.addEventListener("mouseup",r),()=>{document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",r)}},[]);let Ze=s(e=>{if(!Re||m)return;e.preventDefault();let t=z.current?.getBoundingClientRect();if(!t)return;let r=e.clientX-t.left,n=e.clientY-t.top,o=e.deltaY<0?1:-1,d=$(i.zoom+o*ye,M,X),u=d/i.zoom;y({x:r-(r-i.x)*u,y:n-(n-i.y)*u,zoom:d})},[Re,m,i,M,X,y]),et=s(e=>{if(m)return;let t=e.target,r=t.tagName,n=r==="INPUT"||r==="SELECT"||r==="TEXTAREA"||r==="BUTTON";if(t.closest("[data-resize-handle]"))return;let o=t.closest("[data-connection-side]");if(o&&!n){if(w)return;e.preventDefault();let u=o.getAttribute("data-table-id"),f=o.getAttribute("data-field-id");if(!u||!f)return;let a=I.find(p=>p.id===u);if(!a)return;let g=o.getAttribute("data-connection-side"),c=At(a,f,g);if(!c)return;Y.current={type:"relation",fromTableId:u,fromFieldId:f,fromX:c.x,fromY:c.y,currentX:c.x,currentY:c.y},oe({fromX:c.x,fromY:c.y,currentX:c.x,currentY:c.y}),ze(u);return}let d=t.closest("[data-table-id]");if(d){if(w)return;let u=d.getAttribute("data-table-id");if(K(null),U(u),n)return;if(Ie){let f=z.current?.getBoundingClientRect();if(!f)return;let a=I.find(c=>c.id===u);if(!a||a.locked)return;let g=q(e.clientX,e.clientY,i,f);Y.current={type:"table",tableId:u,offsetX:g.x-a.x,offsetY:g.y-a.y}}return}U(null),K(null),Ee&&e.button===0&&(Y.current={type:"pan",startX:e.clientX,startY:e.clientY,startVpX:i.x,startVpY:i.y})},[m,w,Ie,Ee,i,I]),N=s(e=>{let t=e.target;if(t.closest("[data-connection-side]"))return null;let r=t.closest("[data-table-id]");if(!r)return null;let n=r.getAttribute("data-table-id");return I.find(o=>o.id===n)??null},[I]),tt=s(e=>{if(m)return;let t=N(e);t&&j&&j({table:t,nativeEvent:e.nativeEvent})},[j,m,N]),nt=s(e=>{if(m)return;let t=N(e);t&&Z&&Z({table:t,nativeEvent:e.nativeEvent})},[Z,m,N]),rt=s(e=>{if(m)return;let t=N(e);t&&ee&&(e.preventDefault(),ee({table:t,nativeEvent:e.nativeEvent}))},[ee,m,N]),ot=s((e,t)=>{m||(t.stopPropagation(),U(null),K(e))},[m]),it=s((e,t)=>{l(r=>({...r,relations:r.relations.map(n=>n.id===e?{...n,cardinality:t}:n)}))},[l]),st=R.current>0,lt=R.current<E.current.length-1,ae=s(()=>{if(R.current<=0)return;O.current=!0,R.current--;let e=E.current[R.current];A||ne(e),v?.(e),O.current=!1},[A,v]),ce=s(()=>{if(R.current>=E.current.length-1)return;O.current=!0,R.current++;let e=E.current[R.current];A||ne(e),v?.(e),O.current=!1},[A,v]),at=s(()=>Oe(T),[T]),ct=s(()=>{l(e=>({...e,tables:Kt(e.tables,x)}))},[l,x]),dt=s((e,t,r)=>{t!==r&&l(n=>({...n,tables:n.tables.map(o=>{if(o.id!==e)return o;let d=[...o.fields],[u]=d.splice(t,1);return d.splice(r,0,u),{...o,fields:d}})}))},[l]);ge(()=>{let e=z.current;if(!e)return;let t=new ResizeObserver(r=>{for(let n of r)je({width:n.contentRect.width,height:n.contentRect.height})});return t.observe(e),()=>t.disconnect()},[]);let Ye=b(!1);Ye.current||(Ye.current=!0,E.current=[T],R.current=0);let ut=s(e=>{if(!(w||m)){if((e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey){e.preventDefault(),ae();return}if((e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey)){e.preventDefault(),ce();return}if(e.key==="Delete"||e.key==="Backspace"){let t=e.target;if(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT")return;H&&(l(r=>({...r,tables:r.tables.filter(n=>n.id!==H),relations:r.relations.filter(n=>n.from.tableId!==H&&n.to.tableId!==H)})),U(null)),V&&(l(r=>{let n=r.relations.find(o=>o.id===V);return{...r,tables:n?r.tables.map(o=>o.id===n.to.tableId?{...o,fields:o.fields.map(d=>d.id===n.to.fieldId?{...d,foreignKey:void 0}:d)}:o):r.tables,relations:r.relations.filter(o=>o.id!==V)}}),K(null))}e.key==="Escape"&&(U(null),K(null))}},[w,m,H,V,l,ae,ce]),ft=s((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,name:t}:n)}))},[l]),mt=s((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,notes:t}:n)}))},[l]),ht=s(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e?{...r,collapsed:!r.collapsed}:r)}))},[l]),bt=s((e,t,r)=>{l(n=>({...n,tables:n.tables.map(o=>o.id===e?{...o,fields:o.fields.map(d=>d.id===t?{...d,...r}:d)}:o)}))},[l]),gt=s(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e?{...r,fields:[...r.fields,_t()]}:r)}))},[l]),de=s((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,fields:n.fields.filter(o=>o.id!==t)}:n),relations:r.relations.filter(n=>!(n.from.tableId===e&&n.from.fieldId===t)&&!(n.to.tableId===e&&n.to.fieldId===t))}))},[l]),pt=s((e,t,r,n,o)=>{Y.current={type:"resize",tableId:e,startX:t,startY:r,startWidth:n,startHeight:o}},[]),ue=s(()=>{let e=$(i.zoom+ye,M,X);y({...i,zoom:e})},[i,M,X,y]),fe=s(()=>{let e=$(i.zoom-ye,M,X);y({...i,zoom:e})},[i,M,X,y]),me=s(()=>{y({...pe})},[y]),P=s(()=>{let e=z.current?.getBoundingClientRect();if(!e)return;let t=Lt(I,e.width,e.height,x),r=$(t.zoom,M,X);y({...t,zoom:r})},[I,x,M,X,y]),J=s(e=>{l(t=>({...t,tables:[...t.tables,e]}))},[l]),Ce=s(e=>{l(t=>({...t,tables:t.tables.filter(r=>r.id!==e),relations:t.relations.filter(r=>r.from.tableId!==e&&r.to.tableId!==e)}))},[l]),Le=s((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,fields:[...n.fields,t]}:n)}))},[l]),Ae=s((e,t)=>{de(e,t)},[de]),He=s(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e.to.tableId?{...r,fields:r.fields.map(n=>n.id===e.to.fieldId?{...n,foreignKey:{tableId:e.from.tableId,fieldId:e.from.fieldId}}:n)}:r),relations:[...t.relations,e]}))},[l]),Ne=s(e=>{l(t=>{let r=t.relations.find(n=>n.id===e);return{...t,tables:r?t.tables.map(n=>n.id===r.to.tableId?{...n,fields:n.fields.map(o=>o.id===r.to.fieldId?{...o,foreignKey:void 0}:o)}:n):t.tables,relations:t.relations.filter(n=>n.id!==e)}})},[l]),he=s(()=>JSON.stringify(T,null,2),[T]),be=s(e=>{try{let t=JSON.parse(e);t&&Array.isArray(t.tables)&&Array.isArray(t.relations)&&l(()=>t)}catch{}},[l]),yt=s(()=>{let e=z.current?.getBoundingClientRect(),t=W.current,r=100,n=100;e&&(r=(e.width/2-t.x)/t.zoom-Ve/2,n=(e.height/2-t.y)/t.zoom-60),J(kt(r,n))},[J]),_e=s(()=>Oe(T),[T]);Tt($e,()=>({zoomIn:ue,zoomOut:fe,resetView:me,fitToContent:P,addTable:J,removeTable:Ce,addField:Le,removeField:Ae,addRelation:He,removeRelation:Ne,toJSON:he,loadJSON:be,toSQL:_e}),[ue,fe,me,P,J,Ce,Le,Ae,He,Ne,he,be,_e]);let ke=b(!1);ge(()=>{ve&&!ke.current&&z.current&&(ke.current=!0,P())},[ve,P]);let It=St(()=>({transform:`translate(${i.x}px, ${i.y}px) scale(${i.zoom})`,transformOrigin:"0 0"}),[i.x,i.y,i.zoom]);return Pe("div",{ref:z,"data-testid":"schema-editor",className:vt("relative w-full overflow-hidden bg-gray-50 dark:bg-gray-900 select-none",m&&"opacity-60 pointer-events-none",Qe),tabIndex:0,onWheel:Ze,onMouseDown:et,onClick:tt,onDoubleClick:nt,onContextMenu:rt,onKeyDown:ut,children:[Ge&&S(wt,{gridSize:te,zoom:i.zoom}),Je&&!w&&S(Dt,{zoom:i.zoom,onZoomIn:ue,onZoomOut:fe,onResetView:me,onFitToContent:P,onAddTable:yt,onExportJSON:he,onImportJSON:be,onExportSQL:at,onUndo:ae,onRedo:ce,canUndo:st,canRedo:lt,onAutoLayout:ct,disabled:m}),Se&&S(xt,{}),S(Ft,{relations:re,tables:I,viewport:i,selectedRelationId:V,disabled:m||w,onRelationClick:ot,onCardinalityChange:it}),S("div",{style:It,children:I.map(e=>S(zt,{table:e,selected:H===e.id,disabled:m||w,readOnly:w,editable:x,dropTarget:we!==null&&we!==e.id&&!e.collapsed,fieldTypes:We,onTableNameChange:ft,onTableNotesChange:mt,onToggleCollapse:ht,onFieldChange:bt,onFieldAdd:gt,onFieldRemove:de,onFieldReorder:dt,onResizeStart:pt},e.id))}),F&&Pe("svg",{"data-testid":"drag-relation-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:1e3,overflow:"visible"},children:[S("path",{d:Yt(F.fromX*i.zoom+i.x,F.fromY*i.zoom+i.y,F.currentX*i.zoom+i.x,F.currentY*i.zoom+i.y),fill:"none",stroke:"#3b82f6",strokeWidth:2.5,strokeDasharray:"8 4"}),S("circle",{cx:F.fromX*i.zoom+i.x,cy:F.fromY*i.zoom+i.y,r:5,fill:"#3b82f6"}),S("circle",{cx:F.currentX*i.zoom+i.x,cy:F.currentY*i.zoom+i.y,r:4,fill:"#3b82f6",opacity:.6})]}),Se&&ie.width>0&&S(Mt,{tables:I,viewport:i,containerWidth:ie.width,containerHeight:ie.height,editable:x,onViewportChange:y})]})}var Jt=Rt(Gt);Jt.displayName="SchemaEditor";export{Jt as SchemaEditor};
|
|
1
|
+
"use client";import{forwardRef as St,useCallback as s,useEffect as pe,useImperativeHandle as vt,useMemo as wt,useRef as h,useState as k}from"react";import{cn as zt}from"../../lib/cn.js";import{useUILabels as Ft}from"../../lib/i18n.js";import{GridLayer as Dt}from"./canvas/GridLayer.js";import{SchemaTableRenderer as xt}from"./tables/SchemaTableRenderer.js";import{SchemaRelationRenderer as Mt}from"./relations/SchemaRelationRenderer.js";import{SchemaToolbar as Xt}from"./toolbar/SchemaToolbar.js";import{SchemaLegend as Yt}from"./legend/SchemaLegend.js";import{SchemaMinimap as Lt}from"./minimap/SchemaMinimap.js";import{ADD_BUTTON_HEIGHT as Ct,clampZoom as $,computeBezierPath as At,DEFAULT_TABLE_WIDTH as Ke,FIELD_ROW_HEIGHT as Ht,fitViewport as Nt,getFieldConnectionPosition as _t,getFieldConnectionY as kt,HEADER_HEIGHT as Ut,screenToCanvas as q,snapValue as Oe}from"./utils/geometry.js";import{createDefaultField as Vt,createDefaultTable as Kt,DEFAULT_FIELD_TYPES as Ot,generateRelationId as Pt}from"./utils/schema-helpers.js";import{generateSQL as Pe}from"./utils/sql-export.js";import{autoLayoutTables as Bt}from"./utils/auto-layout.js";import{jsx as S,jsxs as Be}from"react/jsx-runtime";var ye={x:0,y:0,zoom:1},Ie=.1,Wt=.1,Gt=3,Jt=20,Qt=50;function $t({value:B,defaultValue:We,onValueChange:v,fieldTypes:Ge=Ot,onTableClick:j,onTableDoubleClick:Z,onTableContextMenu:ee,onFieldClick:jt,onFieldDoubleClick:Zt,readOnly:w=!1,disabled:m=!1,draggableTables:Ee=!0,panOnDrag:Re=!0,zoomOnWheel:Te=!0,editable:x=!0,minZoom:M=Wt,maxZoom:X=Gt,snapToGrid:Se=!1,gridSize:te=Jt,showGrid:Je=!0,toolbar:Qe=!0,legend:ve=!0,autoFit:we=!1,labels:$e,className:qe},je){let ne=Ft($e),A=B!==void 0,[Ze,re]=k(()=>We??{tables:[],relations:[],viewport:{...ye}}),T=A?B:Ze,I=T.tables,oe=T.relations,i=T.viewport??ye,z=h(null),Y=h(null),[H,U]=k(null),[V,K]=k(null),[F,ie]=k(null),[ze,Fe]=k(null),[se,et]=k({width:0,height:0}),E=h([]),R=h(-1),O=h(!1),W=h(i);W.current=i;let De=h(I);De.current=I;let xe=h(oe);xe.current=oe;let Me=h(Se);Me.current=Se;let le=h(te);le.current=te;let Xe=h(x);Xe.current=x;let ae=s(e=>{if(O.current)return;let t=E.current,r=R.current;E.current=t.slice(0,r+1),E.current.push(e),E.current.length>Qt&&E.current.shift(),R.current=E.current.length-1},[]),l=s(e=>{if(A){let t=e(B);ae(t),v?.(t)}else re(t=>{let r=e(t);return ae(r),v?.(r),r})},[A,B,v,ae]),G=h(l);G.current=l;let y=s(e=>{l(t=>({...t,viewport:e}))},[l]),Ye=h(y);Ye.current=y,pe(()=>{function e(n){let o=Y.current;if(!o)return;let d=z.current?.getBoundingClientRect();if(!d)return;let u=W.current;if(o.type==="pan"){let f=n.clientX-o.startX,a=n.clientY-o.startY;Ye.current({...u,x:o.startVpX+f,y:o.startVpY+a})}if(o.type==="table"){let f=q(n.clientX,n.clientY,u,d),a=f.x-o.offsetX,g=f.y-o.offsetY;Me.current&&(a=Oe(a,le.current),g=Oe(g,le.current)),G.current(c=>({...c,tables:c.tables.map(p=>p.id===o.tableId?{...p,x:a,y:g}:p)}))}if(o.type==="relation"){let f=q(n.clientX,n.clientY,u,d);Y.current={...o,currentX:f.x,currentY:f.y},ie({fromX:o.fromX,fromY:o.fromY,currentX:f.x,currentY:f.y})}if(o.type==="resize"){let f=(n.clientX-o.startX)/u.zoom,a=(n.clientY-o.startY)/u.zoom,g=180,c=80,p=Math.max(g,o.startWidth+f),b=Math.max(c,o.startHeight+a);G.current(L=>({...L,tables:L.tables.map(D=>D.id===o.tableId?{...D,width:p,height:b}:D)}))}}function t(n,o,d,u){let f=W.current,a=q(n,o,f,d),g=1/0,c=null,p=null;for(let b of u){if(b.collapsed)continue;let L=b.fields.length;if(L===0)continue;let D=b.width??Ke,_=Ut+L*Ht+(Xe.current?Ct:0),C=40;if(!(a.x<b.x-C||a.x>b.x+D+C||a.y<b.y-C||a.y>b.y+_+C))for(let Q=0;Q<b.fields.length;Q++){let Tt=b.y+kt(Q,!!b.notes),Ve=Math.abs(a.y-Tt);Ve<g&&(g=Ve,c=b.id,p=b.fields[Q].id)}}return c&&p?{tableId:c,fieldId:p}:null}function r(n){let o=Y.current;if(o){if(o.type==="relation"){let d=z.current?.getBoundingClientRect();if(d){let u=xe.current,f=De.current,a=t(n.clientX,n.clientY,d,f);if(a&&a.tableId!==o.fromTableId&&!u.some(c=>c.from.tableId===o.fromTableId&&c.from.fieldId===o.fromFieldId&&c.to.tableId===a.tableId&&c.to.fieldId===a.fieldId)){let c=o.fromTableId,p=o.fromFieldId,b=a.tableId,L=a.fieldId;G.current(D=>({...D,tables:D.tables.map(_=>_.id===b?{..._,fields:_.fields.map(C=>C.id===L?{...C,foreignKey:{tableId:c,fieldId:p}}:C)}:_),relations:[...D.relations,{id:Pt(),from:{tableId:c,fieldId:p},to:{tableId:b,fieldId:L},cardinality:"1:n"}]}))}}ie(null),Fe(null)}Y.current=null}}return document.addEventListener("mousemove",e),document.addEventListener("mouseup",r),()=>{document.removeEventListener("mousemove",e),document.removeEventListener("mouseup",r)}},[]);let tt=s(e=>{if(!Te||m)return;e.preventDefault();let t=z.current?.getBoundingClientRect();if(!t)return;let r=e.clientX-t.left,n=e.clientY-t.top,o=e.deltaY<0?1:-1,d=$(i.zoom+o*Ie,M,X),u=d/i.zoom;y({x:r-(r-i.x)*u,y:n-(n-i.y)*u,zoom:d})},[Te,m,i,M,X,y]),nt=s(e=>{if(m)return;let t=e.target,r=t.tagName,n=r==="INPUT"||r==="SELECT"||r==="TEXTAREA"||r==="BUTTON";if(t.closest("[data-resize-handle]"))return;let o=t.closest("[data-connection-side]");if(o&&!n){if(w)return;e.preventDefault();let u=o.getAttribute("data-table-id"),f=o.getAttribute("data-field-id");if(!u||!f)return;let a=I.find(p=>p.id===u);if(!a)return;let g=o.getAttribute("data-connection-side"),c=_t(a,f,g);if(!c)return;Y.current={type:"relation",fromTableId:u,fromFieldId:f,fromX:c.x,fromY:c.y,currentX:c.x,currentY:c.y},ie({fromX:c.x,fromY:c.y,currentX:c.x,currentY:c.y}),Fe(u);return}let d=t.closest("[data-table-id]");if(d){if(w)return;let u=d.getAttribute("data-table-id");if(K(null),U(u),n)return;if(Ee){let f=z.current?.getBoundingClientRect();if(!f)return;let a=I.find(c=>c.id===u);if(!a||a.locked)return;let g=q(e.clientX,e.clientY,i,f);Y.current={type:"table",tableId:u,offsetX:g.x-a.x,offsetY:g.y-a.y}}return}U(null),K(null),Re&&e.button===0&&(Y.current={type:"pan",startX:e.clientX,startY:e.clientY,startVpX:i.x,startVpY:i.y})},[m,w,Ee,Re,i,I]),N=s(e=>{let t=e.target;if(t.closest("[data-connection-side]"))return null;let r=t.closest("[data-table-id]");if(!r)return null;let n=r.getAttribute("data-table-id");return I.find(o=>o.id===n)??null},[I]),rt=s(e=>{if(m)return;let t=N(e);t&&j&&j({table:t,nativeEvent:e.nativeEvent})},[j,m,N]),ot=s(e=>{if(m)return;let t=N(e);t&&Z&&Z({table:t,nativeEvent:e.nativeEvent})},[Z,m,N]),it=s(e=>{if(m)return;let t=N(e);t&&ee&&(e.preventDefault(),ee({table:t,nativeEvent:e.nativeEvent}))},[ee,m,N]),st=s((e,t)=>{m||(t.stopPropagation(),U(null),K(e))},[m]),lt=s((e,t)=>{l(r=>({...r,relations:r.relations.map(n=>n.id===e?{...n,cardinality:t}:n)}))},[l]),at=R.current>0,ct=R.current<E.current.length-1,ce=s(()=>{if(R.current<=0)return;O.current=!0,R.current--;let e=E.current[R.current];A||re(e),v?.(e),O.current=!1},[A,v]),de=s(()=>{if(R.current>=E.current.length-1)return;O.current=!0,R.current++;let e=E.current[R.current];A||re(e),v?.(e),O.current=!1},[A,v]),dt=s(()=>Pe(T),[T]),ut=s(()=>{l(e=>({...e,tables:Bt(e.tables,x)}))},[l,x]),ft=s((e,t,r)=>{t!==r&&l(n=>({...n,tables:n.tables.map(o=>{if(o.id!==e)return o;let d=[...o.fields],[u]=d.splice(t,1);return d.splice(r,0,u),{...o,fields:d}})}))},[l]);pe(()=>{let e=z.current;if(!e)return;let t=new ResizeObserver(r=>{for(let n of r)et({width:n.contentRect.width,height:n.contentRect.height})});return t.observe(e),()=>t.disconnect()},[]);let Le=h(!1);Le.current||(Le.current=!0,E.current=[T],R.current=0);let mt=s(e=>{if(!(w||m)){if((e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey){e.preventDefault(),ce();return}if((e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey)){e.preventDefault(),de();return}if(e.key==="Delete"||e.key==="Backspace"){let t=e.target;if(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT")return;H&&(l(r=>({...r,tables:r.tables.filter(n=>n.id!==H),relations:r.relations.filter(n=>n.from.tableId!==H&&n.to.tableId!==H)})),U(null)),V&&(l(r=>{let n=r.relations.find(o=>o.id===V);return{...r,tables:n?r.tables.map(o=>o.id===n.to.tableId?{...o,fields:o.fields.map(d=>d.id===n.to.fieldId?{...d,foreignKey:void 0}:d)}:o):r.tables,relations:r.relations.filter(o=>o.id!==V)}}),K(null))}e.key==="Escape"&&(U(null),K(null))}},[w,m,H,V,l,ce,de]),bt=s((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,name:t}:n)}))},[l]),ht=s((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,notes:t}:n)}))},[l]),gt=s(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e?{...r,collapsed:!r.collapsed}:r)}))},[l]),pt=s((e,t,r)=>{l(n=>({...n,tables:n.tables.map(o=>o.id===e?{...o,fields:o.fields.map(d=>d.id===t?{...d,...r}:d)}:o)}))},[l]),yt=s(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e?{...r,fields:[...r.fields,Vt()]}:r)}))},[l]),ue=s((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,fields:n.fields.filter(o=>o.id!==t)}:n),relations:r.relations.filter(n=>!(n.from.tableId===e&&n.from.fieldId===t)&&!(n.to.tableId===e&&n.to.fieldId===t))}))},[l]),It=s((e,t,r,n,o)=>{Y.current={type:"resize",tableId:e,startX:t,startY:r,startWidth:n,startHeight:o}},[]),fe=s(()=>{let e=$(i.zoom+Ie,M,X);y({...i,zoom:e})},[i,M,X,y]),me=s(()=>{let e=$(i.zoom-Ie,M,X);y({...i,zoom:e})},[i,M,X,y]),be=s(()=>{y({...ye})},[y]),P=s(()=>{let e=z.current?.getBoundingClientRect();if(!e)return;let t=Nt(I,e.width,e.height,x),r=$(t.zoom,M,X);y({...t,zoom:r})},[I,x,M,X,y]),J=s(e=>{l(t=>({...t,tables:[...t.tables,e]}))},[l]),Ce=s(e=>{l(t=>({...t,tables:t.tables.filter(r=>r.id!==e),relations:t.relations.filter(r=>r.from.tableId!==e&&r.to.tableId!==e)}))},[l]),Ae=s((e,t)=>{l(r=>({...r,tables:r.tables.map(n=>n.id===e?{...n,fields:[...n.fields,t]}:n)}))},[l]),He=s((e,t)=>{ue(e,t)},[ue]),Ne=s(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e.to.tableId?{...r,fields:r.fields.map(n=>n.id===e.to.fieldId?{...n,foreignKey:{tableId:e.from.tableId,fieldId:e.from.fieldId}}:n)}:r),relations:[...t.relations,e]}))},[l]),_e=s(e=>{l(t=>{let r=t.relations.find(n=>n.id===e);return{...t,tables:r?t.tables.map(n=>n.id===r.to.tableId?{...n,fields:n.fields.map(o=>o.id===r.to.fieldId?{...o,foreignKey:void 0}:o)}:n):t.tables,relations:t.relations.filter(n=>n.id!==e)}})},[l]),he=s(()=>JSON.stringify(T,null,2),[T]),ge=s(e=>{try{let t=JSON.parse(e);t&&Array.isArray(t.tables)&&Array.isArray(t.relations)&&l(()=>t)}catch{}},[l]),Et=s(()=>{let e=z.current?.getBoundingClientRect(),t=W.current,r=100,n=100;e&&(r=(e.width/2-t.x)/t.zoom-Ke/2,n=(e.height/2-t.y)/t.zoom-60),J(Kt(r,n))},[J]),ke=s(()=>Pe(T),[T]);vt(je,()=>({zoomIn:fe,zoomOut:me,resetView:be,fitToContent:P,addTable:J,removeTable:Ce,addField:Ae,removeField:He,addRelation:Ne,removeRelation:_e,toJSON:he,loadJSON:ge,toSQL:ke}),[fe,me,be,P,J,Ce,Ae,He,Ne,_e,he,ge,ke]);let Ue=h(!1);pe(()=>{we&&!Ue.current&&z.current&&(Ue.current=!0,P())},[we,P]);let Rt=wt(()=>({transform:`translate(${i.x}px, ${i.y}px) scale(${i.zoom})`,transformOrigin:"0 0"}),[i.x,i.y,i.zoom]);return Be("div",{ref:z,"data-testid":"schema-editor",className:zt("relative w-full overflow-hidden bg-gray-50 dark:bg-gray-900 select-none",m&&"opacity-60 pointer-events-none",qe),tabIndex:0,onWheel:tt,onMouseDown:nt,onClick:rt,onDoubleClick:ot,onContextMenu:it,onKeyDown:mt,children:[Je&&S(Dt,{gridSize:te,zoom:i.zoom}),Qe&&!w&&S(Xt,{zoom:i.zoom,onZoomIn:fe,onZoomOut:me,onResetView:be,onFitToContent:P,onAddTable:Et,onExportJSON:he,onImportJSON:ge,onExportSQL:dt,onUndo:ce,onRedo:de,canUndo:at,canRedo:ct,onAutoLayout:ut,disabled:m,labels:ne}),ve&&S(Yt,{labels:ne}),S(Mt,{relations:oe,tables:I,viewport:i,selectedRelationId:V,disabled:m||w,onRelationClick:st,onCardinalityChange:lt}),S("div",{style:Rt,children:I.map(e=>S(xt,{table:e,selected:H===e.id,disabled:m||w,readOnly:w,editable:x,dropTarget:ze!==null&&ze!==e.id&&!e.collapsed,fieldTypes:Ge,onTableNameChange:bt,onTableNotesChange:ht,onToggleCollapse:gt,onFieldChange:pt,onFieldAdd:yt,onFieldRemove:ue,onFieldReorder:ft,onResizeStart:It,labels:ne},e.id))}),F&&Be("svg",{"data-testid":"drag-relation-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:1e3,overflow:"visible"},children:[S("path",{d:At(F.fromX*i.zoom+i.x,F.fromY*i.zoom+i.y,F.currentX*i.zoom+i.x,F.currentY*i.zoom+i.y),fill:"none",stroke:"#3b82f6",strokeWidth:2.5,strokeDasharray:"8 4"}),S("circle",{cx:F.fromX*i.zoom+i.x,cy:F.fromY*i.zoom+i.y,r:5,fill:"#3b82f6"}),S("circle",{cx:F.currentX*i.zoom+i.x,cy:F.currentY*i.zoom+i.y,r:4,fill:"#3b82f6",opacity:.6})]}),ve&&se.width>0&&S(Lt,{tables:I,viewport:i,containerWidth:se.width,containerHeight:se.height,editable:x,onViewportChange:y})]})}var qt=St($t);qt.displayName="SchemaEditor";export{qt as SchemaEditor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var o=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var x=(s,t)=>{for(var a in t)o(s,a,{get:t[a],enumerable:!0})},g=(s,t,a,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of l(t))!m.call(s,r)&&r!==a&&o(s,r,{get:()=>t[r],enumerable:!(n=d(t,r))||n.enumerable});return s};var p=s=>g(o({},"__esModule",{value:!0}),s);var f={};x(f,{SchemaLegend:()=>N});module.exports=p(f);var i=require("react"),c=require("../../../lib/cn.cjs"),e=require("react/jsx-runtime"),h=()=>(0,e.jsxs)("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),(0,e.jsx)("circle",{cx:"4.5",cy:"11.5",r:"3"})]}),v=()=>(0,e.jsx)("span",{className:"text-xs font-bold text-gray-500 w-3.5 text-center",children:"?"}),y=()=>(0,e.jsxs)("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"currentColor",children:[(0,e.jsx)("circle",{cx:"8",cy:"8",r:"6",className:"fill-blue-500"}),(0,e.jsx)("path",{d:"M5 8h6M8 5l3 3-3 3",stroke:"white",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})]}),k=()=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5 text-amber-500",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"M3 2v12M7 4h6M7 8h4M7 12h5"})}),u=()=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5 text-purple-500",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"M4 2v8a4 4 0 008 0V2"})}),N=(0,i.memo)(function({className:t,labels:a}){return(0,e.jsxs)("div",{className:(0,c.cn)("absolute top-3 right-3 z-20 flex items-center gap-4 bg-white dark:bg-gray-800 rounded-lg shadow-md border border-gray-200 dark:border-gray-600 px-3 py-2",t),"data-testid":"schema-legend",children:[(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,e.jsx)(h,{}),(0,e.jsx)("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorPrimaryKey})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,e.jsx)(v,{}),(0,e.jsx)("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorNullable})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,e.jsx)(y,{}),(0,e.jsx)("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorForeignKey})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,e.jsx)(k,{}),(0,e.jsx)("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorIndex})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,e.jsx)(u,{}),(0,e.jsx)("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorUnique})]})]})});0&&(module.exports={SchemaLegend});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{memo as
|
|
1
|
+
import{memo as r}from"react";import{cn as o}from"../../../lib/cn.js";import{jsx as e,jsxs as t}from"react/jsx-runtime";var n=()=>t("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),e("circle",{cx:"4.5",cy:"11.5",r:"3"})]}),i=()=>e("span",{className:"text-xs font-bold text-gray-500 w-3.5 text-center",children:"?"}),c=()=>t("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"currentColor",children:[e("circle",{cx:"8",cy:"8",r:"6",className:"fill-blue-500"}),e("path",{d:"M5 8h6M8 5l3 3-3 3",stroke:"white",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})]}),d=()=>e("svg",{className:"w-3.5 h-3.5 text-amber-500",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e("path",{d:"M3 2v12M7 4h6M7 8h4M7 12h5"})}),l=()=>e("svg",{className:"w-3.5 h-3.5 text-purple-500",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e("path",{d:"M4 2v8a4 4 0 008 0V2"})}),p=r(function({className:s,labels:a}){return t("div",{className:o("absolute top-3 right-3 z-20 flex items-center gap-4 bg-white dark:bg-gray-800 rounded-lg shadow-md border border-gray-200 dark:border-gray-600 px-3 py-2",s),"data-testid":"schema-legend",children:[t("div",{className:"flex items-center gap-1.5",children:[e(n,{}),e("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorPrimaryKey})]}),t("div",{className:"flex items-center gap-1.5",children:[e(i,{}),e("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorNullable})]}),t("div",{className:"flex items-center gap-1.5",children:[e(c,{}),e("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorForeignKey})]}),t("div",{className:"flex items-center gap-1.5",children:[e(d,{}),e("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorIndex})]}),t("div",{className:"flex items-center gap-1.5",children:[e(l,{}),e("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorUnique})]})]})});export{p as SchemaLegend};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var T=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var Y=Object.prototype.hasOwnProperty;var $=(d,o)=>{for(var h in o)T(d,h,{get:o[h],enumerable:!0})},X=(d,o,h,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of G(o))!Y.call(d,a)&&a!==h&&T(d,a,{get:()=>o[a],enumerable:!(s=U(o,a))||s.enumerable});return d};var J=d=>X(T({},"__esModule",{value:!0}),d);var oe={};$(oe,{SchemaTableRenderer:()=>te});module.exports=J(oe);var i=require("react"),g=require("../../../lib/cn.cjs"),c=require("../utils/geometry.cjs"),_=require("../utils/schema-helpers.cjs"),e=require("react/jsx-runtime"),D=()=>(0,e.jsxs)("svg",{className:"w-3.5 h-3.5 text-indigo-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),(0,e.jsx)("circle",{cx:"4.5",cy:"11.5",r:"3"})]}),S=()=>(0,e.jsxs)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[(0,e.jsx)("circle",{cx:"8",cy:"8",r:"6",className:"fill-blue-500"}),(0,e.jsx)("path",{d:"M5 8h6M8 5l3 3-3 3",stroke:"white",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})]}),Q=({collapsed:d})=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"currentColor",children:d?(0,e.jsx)("path",{d:"M6 3l5 5-5 5V3z"}):(0,e.jsx)("path",{d:"M3 6l5 5 5-5H3z"})}),E=()=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5 text-amber-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"M3 2v12M7 4h6M7 8h4M7 12h5"})}),H=()=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5 text-purple-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"M4 2v8a4 4 0 008 0V2"})}),Z=()=>(0,e.jsx)("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:(0,e.jsx)("path",{d:"M4 8h8"})}),O=()=>(0,e.jsxs)("svg",{className:"w-3 h-3 text-gray-300",viewBox:"0 0 16 16",fill:"currentColor",children:[(0,e.jsx)("circle",{cx:"5",cy:"4",r:"1.5"}),(0,e.jsx)("circle",{cx:"11",cy:"4",r:"1.5"}),(0,e.jsx)("circle",{cx:"5",cy:"8",r:"1.5"}),(0,e.jsx)("circle",{cx:"11",cy:"8",r:"1.5"}),(0,e.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,e.jsx)("circle",{cx:"11",cy:"12",r:"1.5"})]}),ee=(0,i.memo)(function({field:o,tableId:h,editable:s,readOnly:a,disabled:l,onFieldChange:y}){let[k,x]=(0,i.useState)(!1),[f,b]=(0,i.useState)(o.defaultValue??""),p=s&&!a&&!l,v=()=>{x(!1),y?.(h,o.id,{defaultValue:f||void 0})};return p?k?(0,e.jsx)("input",{className:"text-xs w-16 text-emerald-500 bg-transparent border-b border-emerald-300 outline-none focus:ring-0 p-0 flex-shrink-0","aria-label":`Default value for ${o.name}`,value:f,onChange:u=>b(u.target.value),onBlur:v,onKeyDown:u=>{u.key==="Enter"&&v(),u.key==="Escape"&&x(!1)},onMouseDown:u=>u.stopPropagation(),autoFocus:!0}):o.defaultValue?(0,e.jsxs)("button",{type:"button",className:"text-xs text-emerald-500 flex-shrink-0 truncate max-w-16 cursor-pointer",onClick:u=>{u.stopPropagation(),b(o.defaultValue??""),x(!0)},onMouseDown:u=>u.stopPropagation(),title:`Default: ${o.defaultValue}`,children:["= ",o.defaultValue]}):(0,e.jsx)("button",{type:"button",className:"text-xs text-gray-300 flex-shrink-0 opacity-0 group-hover:opacity-30 hover:!opacity-100 cursor-pointer transition-opacity",onClick:u=>{u.stopPropagation(),b(""),x(!0)},onMouseDown:u=>u.stopPropagation(),title:"Set default value",children:"= \u2205"}):o.defaultValue?(0,e.jsxs)("span",{className:"text-xs text-emerald-500 flex-shrink-0 truncate max-w-16",title:`Default: ${o.defaultValue}`,children:["= ",o.defaultValue]}):null}),te=(0,i.memo)(function({table:o,selected:h,disabled:s,readOnly:a,editable:l,dropTarget:y,fieldTypes:k,onTableNameChange:x,onTableNotesChange:f,onToggleCollapse:b,onFieldChange:p,onFieldAdd:v,onFieldRemove:u,onFieldReorder:R,onResizeStart:V}){let I=o.width??c.DEFAULT_TABLE_WIDTH,w=o.collapsed??!1,C=k.length>0?k:_.DEFAULT_FIELD_TYPES,[F,P]=(0,i.useState)(null),[L,N]=(0,i.useState)(null),m=(0,i.useRef)(null),K=(0,i.useCallback)(t=>{x?.(o.id,t.target.value)},[o.id,x]),B=(0,i.useCallback)((t,n)=>{p?.(o.id,t,{name:n})},[o.id,p]),z=(0,i.useCallback)((t,n)=>{p?.(o.id,t,{type:n})},[o.id,p]),M=(0,i.useCallback)((t,n)=>{p?.(o.id,t,{primaryKey:!n})},[o.id,p]),W=(0,i.useCallback)((t,n)=>{p?.(o.id,t,{nullable:!n})},[o.id,p]),A=(0,i.useCallback)((t,n)=>{p?.(o.id,t,{indexed:!n})},[o.id,p]),q=(0,i.useCallback)((t,n)=>{p?.(o.id,t,{unique:!n})},[o.id,p]),j=(0,i.useCallback)(()=>{v?.(o.id)},[o.id,v]);return(0,e.jsxs)("div",{"data-table-id":o.id,className:(0,g.cn)("absolute bg-white dark:bg-gray-800 border-2 border-dashed rounded-lg shadow-sm cursor-grab active:cursor-grabbing",o.height?"flex flex-col":void 0,y?"border-green-400 shadow-green-100 dark:shadow-green-900/30 shadow-md":h?"border-blue-500 shadow-blue-100 dark:shadow-blue-900/30":"border-gray-300 dark:border-gray-600",s&&"opacity-60",o.locked&&"!cursor-default"),style:{left:o.x,top:o.y,width:I,height:o.height,userSelect:"none",overflow:o.height?"hidden":void 0},children:[(0,e.jsxs)("div",{className:(0,g.cn)("flex items-center justify-between px-3 gap-2","bg-gray-50 dark:bg-gray-700 border-b border-gray-200 dark:border-gray-600"),style:{height:c.HEADER_HEIGHT},children:[l&&!a&&!s?(0,e.jsx)("input",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text","aria-label":"Table name",value:o.name,onChange:K,onMouseDown:t=>t.stopPropagation()}):(0,e.jsx)("span",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 truncate",children:o.name}),(0,e.jsx)("button",{type:"button",className:"flex-shrink-0 p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-500 dark:text-gray-400",onClick:t=>{t.stopPropagation(),b?.(o.id)},onMouseDown:t=>t.stopPropagation(),"aria-label":w?"Expand table":"Collapse table",children:(0,e.jsx)(Q,{collapsed:w})})]}),!w&&(l&&!a&&!s?(0,e.jsx)("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:c.NOTES_ROW_HEIGHT},children:(0,e.jsx)("input",{className:"w-full text-xs italic text-gray-400 dark:text-gray-500 bg-transparent border-none outline-none focus:ring-0 p-0 placeholder-gray-400 dark:placeholder-gray-500","aria-label":"Table notes",placeholder:"Add notes...",value:o.notes??"",onChange:t=>f?.(o.id,t.target.value),onMouseDown:t=>t.stopPropagation()})}):o.notes?(0,e.jsx)("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:c.NOTES_ROW_HEIGHT},children:(0,e.jsx)("span",{className:"text-xs italic text-gray-400 dark:text-gray-500 truncate",children:o.notes})}):null),!w&&(0,e.jsxs)("div",{className:o.height?"overflow-y-auto flex-1 min-h-0":void 0,children:[o.fields.map((t,n)=>(0,e.jsxs)("div",{"data-field-id":t.id,"data-table-id":o.id,className:(0,g.cn)("flex items-center gap-1.5 pr-2 relative group",l&&!a&&!s?"pl-[18px]":"pl-2","border-b border-gray-100 dark:border-gray-700 last:border-b-0",y?"bg-blue-50/50 dark:bg-blue-900/10":"hover:bg-gray-50 dark:hover:bg-gray-750",F===n&&"opacity-40",L===n&&"!border-t-2 !border-t-blue-400"),style:{height:c.FIELD_ROW_HEIGHT},draggable:l&&!a&&!s,onDragStart:r=>{!l||a||s||(r.stopPropagation(),m.current=n,P(n),r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",String(n)))},onDragOver:r=>{m.current!==null&&(r.preventDefault(),r.stopPropagation(),N(n))},onDragLeave:()=>{L===n&&N(null)},onDrop:r=>{r.preventDefault(),r.stopPropagation(),m.current!==null&&m.current!==n&&R?.(o.id,m.current,n),m.current=null,P(null),N(null)},onDragEnd:()=>{m.current=null,P(null),N(null)},children:[(0,e.jsx)("div",{"data-connection-side":"left","data-field-id":t.id,"data-table-id":o.id,className:(0,g.cn)("absolute -left-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",y?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-blue-400"),style:{top:c.FIELD_ROW_HEIGHT/2-5}}),l&&!a&&!s&&(0,e.jsx)("span",{className:"absolute left-[3px] cursor-grab active:cursor-grabbing opacity-0 group-hover:opacity-100 transition-opacity z-10",style:{top:c.FIELD_ROW_HEIGHT/2-6},children:(0,e.jsx)(O,{})}),l&&!a&&!s?(0,e.jsx)("button",{type:"button",className:(0,g.cn)("w-4 text-xs font-bold flex-shrink-0 text-center cursor-pointer",t.nullable?"text-gray-400":"text-transparent"),onClick:r=>{r.stopPropagation(),W(t.id,t.nullable??!1)},onMouseDown:r=>r.stopPropagation(),title:t.nullable?"Nullable":"Not nullable",children:"?"}):(0,e.jsx)("span",{className:(0,g.cn)("w-4 text-xs font-bold flex-shrink-0 text-center",t.nullable?"text-gray-400":"text-transparent"),children:t.nullable?"?":""}),t.primaryKey&&t.foreignKey?(0,e.jsxs)("span",{className:"flex items-center gap-0.5 flex-shrink-0",children:[l&&!a&&!s?(0,e.jsx)("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:r=>{r.stopPropagation(),M(t.id,!0)},onMouseDown:r=>r.stopPropagation(),title:"Primary Key (click to remove)",children:(0,e.jsx)(D,{})}):(0,e.jsx)(D,{}),(0,e.jsx)(S,{})]}):t.primaryKey?l&&!a&&!s?(0,e.jsx)("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:r=>{r.stopPropagation(),M(t.id,!0)},onMouseDown:r=>r.stopPropagation(),title:"Primary Key (click to remove)",children:(0,e.jsx)(D,{})}):(0,e.jsx)(D,{}):t.foreignKey?(0,e.jsx)(S,{}):l&&!a&&!s?(0,e.jsx)("button",{type:"button",className:"w-3.5 h-3.5 flex-shrink-0 rounded text-gray-300 hover:text-indigo-400 transition-colors cursor-pointer",onClick:r=>{r.stopPropagation(),M(t.id,!1)},onMouseDown:r=>r.stopPropagation(),title:"Set as Primary Key","aria-label":"Set as primary key",children:(0,e.jsxs)("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",opacity:"0.3",children:[(0,e.jsx)("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),(0,e.jsx)("circle",{cx:"4.5",cy:"11.5",r:"3"})]})}):(0,e.jsx)("span",{className:"w-3.5 flex-shrink-0"}),l&&!a&&!s?(0,e.jsx)("input",{className:(0,g.cn)("flex-1 min-w-0 text-xs bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text",t.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),"aria-label":"Field name",value:t.name,onChange:r=>B(t.id,r.target.value),onMouseDown:r=>r.stopPropagation()}):(0,e.jsx)("span",{className:(0,g.cn)("flex-1 min-w-0 text-xs truncate",t.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),children:t.name}),l&&!a&&!s?(0,e.jsxs)("select",{className:"text-xs text-gray-400 dark:text-gray-500 bg-transparent border-none outline-none focus:ring-0 p-0 cursor-pointer text-right",value:t.type,onChange:r=>z(t.id,r.target.value),onMouseDown:r=>r.stopPropagation(),children:[C.map(r=>(0,e.jsx)("option",{value:r,children:r},r)),!C.includes(t.type)&&(0,e.jsx)("option",{value:t.type,children:t.type})]}):(0,e.jsx)("span",{className:"text-xs text-gray-400 dark:text-gray-500 flex-shrink-0",children:t.type}),(0,e.jsx)(ee,{field:t,tableId:o.id,editable:l,readOnly:a,disabled:s,onFieldChange:p}),t.indexed&&(0,e.jsx)(E,{}),t.unique&&(0,e.jsx)(H,{}),l&&!a&&!s&&(0,e.jsxs)("div",{className:"absolute right-1 top-0 bottom-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity bg-gradient-to-l from-white via-white to-transparent dark:from-gray-800 dark:via-gray-800 pl-4 pr-1 z-10",children:[(0,e.jsx)("button",{type:"button",className:(0,g.cn)("cursor-pointer transition-opacity",t.indexed?"opacity-100":"opacity-30 hover:opacity-100"),onClick:r=>{r.stopPropagation(),A(t.id,t.indexed??!1)},onMouseDown:r=>r.stopPropagation(),title:t.indexed?"Indexed (click to remove)":"Add index",children:(0,e.jsx)(E,{})}),(0,e.jsx)("button",{type:"button",className:(0,g.cn)("cursor-pointer transition-opacity",t.unique?"opacity-100":"opacity-30 hover:opacity-100"),onClick:r=>{r.stopPropagation(),q(t.id,t.unique??!1)},onMouseDown:r=>r.stopPropagation(),title:t.unique?"Unique (click to remove)":"Add unique constraint",children:(0,e.jsx)(H,{})}),(0,e.jsx)("button",{type:"button",className:"p-0.5 rounded text-gray-300 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 cursor-pointer",onClick:r=>{r.stopPropagation(),u?.(o.id,t.id)},onMouseDown:r=>r.stopPropagation(),title:"Remove field",children:(0,e.jsx)(Z,{})})]}),(0,e.jsx)("div",{"data-connection-side":"right","data-field-id":t.id,"data-table-id":o.id,className:(0,g.cn)("absolute -right-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",y?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-green-400"),style:{top:c.FIELD_ROW_HEIGHT/2-5}})]},t.id)),l&&!a&&!s&&(0,e.jsxs)("button",{type:"button",className:"flex items-center justify-center w-full gap-1 text-xs text-gray-400 hover:text-blue-500 hover:bg-gray-50 dark:hover:bg-gray-750 transition-colors cursor-pointer",style:{height:c.ADD_BUTTON_HEIGHT},onClick:t=>{t.stopPropagation(),j()},onMouseDown:t=>t.stopPropagation(),children:[(0,e.jsx)("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:(0,e.jsx)("path",{d:"M8 4v8M4 8h8"})}),"Add field"]})]}),!s&&!a&&(0,e.jsx)("div",{"data-resize-handle":"corner",className:"absolute -bottom-[5px] -right-[5px] w-[14px] h-[14px] cursor-nwse-resize z-20 group/resize",onMouseDown:t=>{t.stopPropagation(),t.preventDefault();let n=o.height??(0,c.getTableHeight)(o,l);V?.(o.id,t.clientX,t.clientY,I,n)},children:(0,e.jsxs)("svg",{className:"w-full h-full text-gray-300 group-hover/resize:text-blue-400 transition-colors",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,e.jsx)("path",{d:"M12 2v10H2",opacity:"0"}),(0,e.jsx)("path",{d:"M6 12L12 6"}),(0,e.jsx)("path",{d:"M10 12L12 10"})]})})]})});0&&(module.exports={SchemaTableRenderer});
|
|
1
|
+
"use strict";var C=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var Q=(h,o)=>{for(var m in o)C(h,m,{get:o[m],enumerable:!0})},Z=(h,o,m,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of X(o))!J.call(h,a)&&a!==m&&C(h,a,{get:()=>o[a],enumerable:!(s=Y(o,a))||s.enumerable});return h};var $=h=>Z(C({},"__esModule",{value:!0}),h);var ae={};Q(ae,{SchemaTableRenderer:()=>re});module.exports=$(ae);var l=require("react"),g=require("../../../lib/cn.cjs"),d=require("../utils/geometry.cjs"),_=require("../utils/schema-helpers.cjs"),M=require("../../../lib/ui-labels.cjs"),e=require("react/jsx-runtime"),P=()=>(0,e.jsxs)("svg",{className:"w-3.5 h-3.5 text-indigo-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),(0,e.jsx)("circle",{cx:"4.5",cy:"11.5",r:"3"})]}),V=()=>(0,e.jsxs)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[(0,e.jsx)("circle",{cx:"8",cy:"8",r:"6",className:"fill-blue-500"}),(0,e.jsx)("path",{d:"M5 8h6M8 5l3 3-3 3",stroke:"white",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})]}),O=({collapsed:h})=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"currentColor",children:h?(0,e.jsx)("path",{d:"M6 3l5 5-5 5V3z"}):(0,e.jsx)("path",{d:"M3 6l5 5 5-5H3z"})}),F=()=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5 text-amber-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"M3 2v12M7 4h6M7 8h4M7 12h5"})}),H=()=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5 text-purple-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"M4 2v8a4 4 0 008 0V2"})}),ee=()=>(0,e.jsx)("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:(0,e.jsx)("path",{d:"M4 8h8"})}),te=()=>(0,e.jsxs)("svg",{className:"w-3 h-3 text-gray-300",viewBox:"0 0 16 16",fill:"currentColor",children:[(0,e.jsx)("circle",{cx:"5",cy:"4",r:"1.5"}),(0,e.jsx)("circle",{cx:"11",cy:"4",r:"1.5"}),(0,e.jsx)("circle",{cx:"5",cy:"8",r:"1.5"}),(0,e.jsx)("circle",{cx:"11",cy:"8",r:"1.5"}),(0,e.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,e.jsx)("circle",{cx:"11",cy:"12",r:"1.5"})]}),oe=(0,l.memo)(function({field:o,tableId:m,editable:s,readOnly:a,disabled:c,onFieldChange:b,labels:x}){let[k,v]=(0,l.useState)(!1),[f,u]=(0,l.useState)(o.defaultValue??""),w=s&&!a&&!c,N=()=>{v(!1),b?.(m,o.id,{defaultValue:f||void 0})};return w?k?(0,e.jsx)("input",{className:"text-xs w-16 text-emerald-500 bg-transparent border-b border-emerald-300 outline-none focus:ring-0 p-0 flex-shrink-0","aria-label":(0,M.formatUILabel)(x.schemaEditorDefaultValueFor,{field:o.name}),value:f,onChange:p=>u(p.target.value),onBlur:N,onKeyDown:p=>{p.key==="Enter"&&N(),p.key==="Escape"&&v(!1)},onMouseDown:p=>p.stopPropagation(),autoFocus:!0}):o.defaultValue?(0,e.jsxs)("button",{type:"button",className:"text-xs text-emerald-500 flex-shrink-0 truncate max-w-16 cursor-pointer",onClick:p=>{p.stopPropagation(),u(o.defaultValue??""),v(!0)},onMouseDown:p=>p.stopPropagation(),title:(0,M.formatUILabel)(x.schemaEditorDefaultValue,{value:o.defaultValue}),children:["= ",o.defaultValue]}):(0,e.jsx)("button",{type:"button",className:"text-xs text-gray-300 flex-shrink-0 opacity-0 group-hover:opacity-30 hover:!opacity-100 cursor-pointer transition-opacity",onClick:p=>{p.stopPropagation(),u(""),v(!0)},onMouseDown:p=>p.stopPropagation(),title:x.schemaEditorSetDefaultValue,children:"= \u2205"}):o.defaultValue?(0,e.jsxs)("span",{className:"text-xs text-emerald-500 flex-shrink-0 truncate max-w-16",title:(0,M.formatUILabel)(x.schemaEditorDefaultValue,{value:o.defaultValue}),children:["= ",o.defaultValue]}):null}),re=(0,l.memo)(function({table:o,selected:m,disabled:s,readOnly:a,editable:c,dropTarget:b,fieldTypes:x,onTableNameChange:k,onTableNotesChange:v,onToggleCollapse:f,onFieldChange:u,onFieldAdd:w,onFieldRemove:N,onFieldReorder:p,onResizeStart:K,labels:i}){let L=o.width??d.DEFAULT_TABLE_WIDTH,D=o.collapsed??!1,S=x.length>0?x:_.DEFAULT_FIELD_TYPES,[B,T]=(0,l.useState)(null),[R,E]=(0,l.useState)(null),y=(0,l.useRef)(null),z=(0,l.useCallback)(t=>{k?.(o.id,t.target.value)},[o.id,k]),W=(0,l.useCallback)((t,n)=>{u?.(o.id,t,{name:n})},[o.id,u]),U=(0,l.useCallback)((t,n)=>{u?.(o.id,t,{type:n})},[o.id,u]),I=(0,l.useCallback)((t,n)=>{u?.(o.id,t,{primaryKey:!n})},[o.id,u]),A=(0,l.useCallback)((t,n)=>{u?.(o.id,t,{nullable:!n})},[o.id,u]),q=(0,l.useCallback)((t,n)=>{u?.(o.id,t,{indexed:!n})},[o.id,u]),j=(0,l.useCallback)((t,n)=>{u?.(o.id,t,{unique:!n})},[o.id,u]),G=(0,l.useCallback)(()=>{w?.(o.id)},[o.id,w]);return(0,e.jsxs)("div",{"data-table-id":o.id,className:(0,g.cn)("absolute bg-white dark:bg-gray-800 border-2 border-dashed rounded-lg shadow-sm cursor-grab active:cursor-grabbing",o.height?"flex flex-col":void 0,b?"border-green-400 shadow-green-100 dark:shadow-green-900/30 shadow-md":m?"border-blue-500 shadow-blue-100 dark:shadow-blue-900/30":"border-gray-300 dark:border-gray-600",s&&"opacity-60",o.locked&&"!cursor-default"),style:{left:o.x,top:o.y,width:L,height:o.height,userSelect:"none",overflow:o.height?"hidden":void 0},children:[(0,e.jsxs)("div",{className:(0,g.cn)("flex items-center justify-between px-3 gap-2","bg-gray-50 dark:bg-gray-700 border-b border-gray-200 dark:border-gray-600"),style:{height:d.HEADER_HEIGHT},children:[c&&!a&&!s?(0,e.jsx)("input",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text","aria-label":i.schemaEditorTableName,value:o.name,onChange:z,onMouseDown:t=>t.stopPropagation()}):(0,e.jsx)("span",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 truncate",children:o.name}),(0,e.jsx)("button",{type:"button",className:"flex-shrink-0 p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-500 dark:text-gray-400",onClick:t=>{t.stopPropagation(),f?.(o.id)},onMouseDown:t=>t.stopPropagation(),"aria-label":D?i.schemaEditorExpandTable:i.schemaEditorCollapseTable,children:(0,e.jsx)(O,{collapsed:D})})]}),!D&&(c&&!a&&!s?(0,e.jsx)("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:d.NOTES_ROW_HEIGHT},children:(0,e.jsx)("input",{className:"w-full text-xs italic text-gray-400 dark:text-gray-500 bg-transparent border-none outline-none focus:ring-0 p-0 placeholder-gray-400 dark:placeholder-gray-500","aria-label":i.schemaEditorTableNotes,placeholder:i.schemaEditorNotesPlaceholder,value:o.notes??"",onChange:t=>v?.(o.id,t.target.value),onMouseDown:t=>t.stopPropagation()})}):o.notes?(0,e.jsx)("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:d.NOTES_ROW_HEIGHT},children:(0,e.jsx)("span",{className:"text-xs italic text-gray-400 dark:text-gray-500 truncate",children:o.notes})}):null),!D&&(0,e.jsxs)("div",{className:o.height?"overflow-y-auto flex-1 min-h-0":void 0,children:[o.fields.map((t,n)=>(0,e.jsxs)("div",{"data-field-id":t.id,"data-table-id":o.id,className:(0,g.cn)("flex items-center gap-1.5 pr-2 relative group",c&&!a&&!s?"pl-[18px]":"pl-2","border-b border-gray-100 dark:border-gray-700 last:border-b-0",b?"bg-blue-50/50 dark:bg-blue-900/10":"hover:bg-gray-50 dark:hover:bg-gray-700/50",B===n&&"opacity-40",R===n&&"!border-t-2 !border-t-blue-400"),style:{height:d.FIELD_ROW_HEIGHT},draggable:c&&!a&&!s,onDragStart:r=>{!c||a||s||(r.stopPropagation(),y.current=n,T(n),r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",String(n)))},onDragOver:r=>{y.current!==null&&(r.preventDefault(),r.stopPropagation(),E(n))},onDragLeave:()=>{R===n&&E(null)},onDrop:r=>{r.preventDefault(),r.stopPropagation(),y.current!==null&&y.current!==n&&p?.(o.id,y.current,n),y.current=null,T(null),E(null)},onDragEnd:()=>{y.current=null,T(null),E(null)},children:[(0,e.jsx)("div",{"data-connection-side":"left","data-field-id":t.id,"data-table-id":o.id,className:(0,g.cn)("absolute -left-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",b?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-blue-400"),style:{top:d.FIELD_ROW_HEIGHT/2-5}}),c&&!a&&!s&&(0,e.jsx)("span",{className:"absolute left-[3px] cursor-grab active:cursor-grabbing opacity-0 group-hover:opacity-100 transition-opacity z-10",style:{top:d.FIELD_ROW_HEIGHT/2-6},children:(0,e.jsx)(te,{})}),c&&!a&&!s?(0,e.jsx)("button",{type:"button",className:(0,g.cn)("w-4 text-xs font-bold flex-shrink-0 text-center cursor-pointer",t.nullable?"text-gray-400":"text-transparent"),onClick:r=>{r.stopPropagation(),A(t.id,t.nullable??!1)},onMouseDown:r=>r.stopPropagation(),title:t.nullable?i.schemaEditorNullable:i.schemaEditorNotNullable,children:"?"}):(0,e.jsx)("span",{className:(0,g.cn)("w-4 text-xs font-bold flex-shrink-0 text-center",t.nullable?"text-gray-400":"text-transparent"),children:t.nullable?"?":""}),t.primaryKey&&t.foreignKey?(0,e.jsxs)("span",{className:"flex items-center gap-0.5 flex-shrink-0",children:[c&&!a&&!s?(0,e.jsx)("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:r=>{r.stopPropagation(),I(t.id,!0)},onMouseDown:r=>r.stopPropagation(),title:i.schemaEditorRemovePrimaryKey,children:(0,e.jsx)(P,{})}):(0,e.jsx)(P,{}),(0,e.jsx)(V,{})]}):t.primaryKey?c&&!a&&!s?(0,e.jsx)("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:r=>{r.stopPropagation(),I(t.id,!0)},onMouseDown:r=>r.stopPropagation(),title:i.schemaEditorRemovePrimaryKey,children:(0,e.jsx)(P,{})}):(0,e.jsx)(P,{}):t.foreignKey?(0,e.jsx)(V,{}):c&&!a&&!s?(0,e.jsx)("button",{type:"button",className:"w-3.5 h-3.5 flex-shrink-0 rounded text-gray-300 hover:text-indigo-400 transition-colors cursor-pointer",onClick:r=>{r.stopPropagation(),I(t.id,!1)},onMouseDown:r=>r.stopPropagation(),title:i.schemaEditorSetPrimaryKey,"aria-label":i.schemaEditorSetPrimaryKey,children:(0,e.jsxs)("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",opacity:"0.3",children:[(0,e.jsx)("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),(0,e.jsx)("circle",{cx:"4.5",cy:"11.5",r:"3"})]})}):(0,e.jsx)("span",{className:"w-3.5 flex-shrink-0"}),c&&!a&&!s?(0,e.jsx)("input",{className:(0,g.cn)("flex-1 min-w-0 text-xs bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text",t.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),"aria-label":i.schemaEditorFieldName,value:t.name,onChange:r=>W(t.id,r.target.value),onMouseDown:r=>r.stopPropagation()}):(0,e.jsx)("span",{className:(0,g.cn)("flex-1 min-w-0 text-xs truncate",t.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),children:t.name}),c&&!a&&!s?(0,e.jsxs)("select",{className:"text-xs text-gray-400 dark:text-gray-500 bg-transparent border-none outline-none focus:ring-0 p-0 cursor-pointer text-right",value:t.type,onChange:r=>U(t.id,r.target.value),onMouseDown:r=>r.stopPropagation(),children:[S.map(r=>(0,e.jsx)("option",{value:r,children:r},r)),!S.includes(t.type)&&(0,e.jsx)("option",{value:t.type,children:t.type})]}):(0,e.jsx)("span",{className:"text-xs text-gray-400 dark:text-gray-500 flex-shrink-0",children:t.type}),(0,e.jsx)(oe,{field:t,tableId:o.id,editable:c,readOnly:a,disabled:s,onFieldChange:u,labels:i}),t.indexed&&(0,e.jsx)(F,{}),t.unique&&(0,e.jsx)(H,{}),c&&!a&&!s&&(0,e.jsxs)("div",{className:"absolute right-1 top-0 bottom-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity bg-gradient-to-l from-white via-white to-transparent dark:from-gray-800 dark:via-gray-800 pl-4 pr-1 z-10",children:[(0,e.jsx)("button",{type:"button",className:(0,g.cn)("cursor-pointer transition-opacity",t.indexed?"opacity-100":"opacity-30 hover:opacity-100"),onClick:r=>{r.stopPropagation(),q(t.id,t.indexed??!1)},onMouseDown:r=>r.stopPropagation(),title:t.indexed?i.schemaEditorRemoveIndex:i.schemaEditorAddIndex,children:(0,e.jsx)(F,{})}),(0,e.jsx)("button",{type:"button",className:(0,g.cn)("cursor-pointer transition-opacity",t.unique?"opacity-100":"opacity-30 hover:opacity-100"),onClick:r=>{r.stopPropagation(),j(t.id,t.unique??!1)},onMouseDown:r=>r.stopPropagation(),title:t.unique?i.schemaEditorRemoveUnique:i.schemaEditorAddUnique,children:(0,e.jsx)(H,{})}),(0,e.jsx)("button",{type:"button",className:"p-0.5 rounded text-gray-300 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 cursor-pointer",onClick:r=>{r.stopPropagation(),N?.(o.id,t.id)},onMouseDown:r=>r.stopPropagation(),title:i.schemaEditorRemoveField,children:(0,e.jsx)(ee,{})})]}),(0,e.jsx)("div",{"data-connection-side":"right","data-field-id":t.id,"data-table-id":o.id,className:(0,g.cn)("absolute -right-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",b?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-green-400"),style:{top:d.FIELD_ROW_HEIGHT/2-5}})]},t.id)),c&&!a&&!s&&(0,e.jsxs)("button",{type:"button",className:"flex items-center justify-center w-full gap-1 text-xs text-gray-400 hover:text-blue-500 hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors cursor-pointer",style:{height:d.ADD_BUTTON_HEIGHT},onClick:t=>{t.stopPropagation(),G()},onMouseDown:t=>t.stopPropagation(),children:[(0,e.jsx)("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:(0,e.jsx)("path",{d:"M8 4v8M4 8h8"})}),i.schemaEditorAddField]})]}),!s&&!a&&(0,e.jsx)("div",{"data-resize-handle":"corner",className:"absolute -bottom-[5px] -right-[5px] w-[14px] h-[14px] cursor-nwse-resize z-20 group/resize",onMouseDown:t=>{t.stopPropagation(),t.preventDefault();let n=o.height??(0,d.getTableHeight)(o,c);K?.(o.id,t.clientX,t.clientY,L,n)},children:(0,e.jsxs)("svg",{className:"w-full h-full text-gray-300 group-hover/resize:text-blue-400 transition-colors",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,e.jsx)("path",{d:"M12 2v10H2",opacity:"0"}),(0,e.jsx)("path",{d:"M6 12L12 6"}),(0,e.jsx)("path",{d:"M10 12L12 10"})]})})]})});0&&(module.exports={SchemaTableRenderer});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{memo as V,useCallback as g,useRef as Y,useState as D}from"react";import{cn as p}from"../../../lib/cn.js";import{ADD_BUTTON_HEIGHT as $,DEFAULT_TABLE_WIDTH as X,FIELD_ROW_HEIGHT as w,getTableHeight as J,HEADER_HEIGHT as Q,NOTES_ROW_HEIGHT as E}from"../utils/geometry.js";import{DEFAULT_FIELD_TYPES as Z}from"../utils/schema-helpers.js";import{jsx as t,jsxs as c}from"react/jsx-runtime";var N=()=>c("svg",{className:"w-3.5 h-3.5 text-indigo-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),t("circle",{cx:"4.5",cy:"11.5",r:"3"})]}),H=()=>c("svg",{className:"w-3.5 h-3.5 flex-shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[t("circle",{cx:"8",cy:"8",r:"6",className:"fill-blue-500"}),t("path",{d:"M5 8h6M8 5l3 3-3 3",stroke:"white",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})]}),O=({collapsed:P})=>t("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"currentColor",children:P?t("path",{d:"M6 3l5 5-5 5V3z"}):t("path",{d:"M3 6l5 5 5-5H3z"})}),_=()=>t("svg",{className:"w-3.5 h-3.5 text-amber-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:t("path",{d:"M3 2v12M7 4h6M7 8h4M7 12h5"})}),R=()=>t("svg",{className:"w-3.5 h-3.5 text-purple-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:t("path",{d:"M4 2v8a4 4 0 008 0V2"})}),ee=()=>t("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:t("path",{d:"M4 8h8"})}),te=()=>c("svg",{className:"w-3 h-3 text-gray-300",viewBox:"0 0 16 16",fill:"currentColor",children:[t("circle",{cx:"5",cy:"4",r:"1.5"}),t("circle",{cx:"11",cy:"4",r:"1.5"}),t("circle",{cx:"5",cy:"8",r:"1.5"}),t("circle",{cx:"11",cy:"8",r:"1.5"}),t("circle",{cx:"5",cy:"12",r:"1.5"}),t("circle",{cx:"11",cy:"12",r:"1.5"})]}),oe=V(function({field:o,tableId:M,editable:n,readOnly:s,disabled:i,onFieldChange:x}){let[b,d]=D(!1),[v,m]=D(o.defaultValue??""),u=n&&!s&&!i,y=()=>{d(!1),x?.(M,o.id,{defaultValue:v||void 0})};return u?b?t("input",{className:"text-xs w-16 text-emerald-500 bg-transparent border-b border-emerald-300 outline-none focus:ring-0 p-0 flex-shrink-0","aria-label":`Default value for ${o.name}`,value:v,onChange:l=>m(l.target.value),onBlur:y,onKeyDown:l=>{l.key==="Enter"&&y(),l.key==="Escape"&&d(!1)},onMouseDown:l=>l.stopPropagation(),autoFocus:!0}):o.defaultValue?c("button",{type:"button",className:"text-xs text-emerald-500 flex-shrink-0 truncate max-w-16 cursor-pointer",onClick:l=>{l.stopPropagation(),m(o.defaultValue??""),d(!0)},onMouseDown:l=>l.stopPropagation(),title:`Default: ${o.defaultValue}`,children:["= ",o.defaultValue]}):t("button",{type:"button",className:"text-xs text-gray-300 flex-shrink-0 opacity-0 group-hover:opacity-30 hover:!opacity-100 cursor-pointer transition-opacity",onClick:l=>{l.stopPropagation(),m(""),d(!0)},onMouseDown:l=>l.stopPropagation(),title:"Set default value",children:"= \u2205"}):o.defaultValue?c("span",{className:"text-xs text-emerald-500 flex-shrink-0 truncate max-w-16",title:`Default: ${o.defaultValue}`,children:["= ",o.defaultValue]}):null}),ie=V(function({table:o,selected:M,disabled:n,readOnly:s,editable:i,dropTarget:x,fieldTypes:b,onTableNameChange:d,onTableNotesChange:v,onToggleCollapse:m,onFieldChange:u,onFieldAdd:y,onFieldRemove:l,onFieldReorder:F,onResizeStart:K}){let C=o.width??X,k=o.collapsed??!1,L=b.length>0?b:Z,[B,T]=D(null),[S,f]=D(null),h=Y(null),z=g(e=>{d?.(o.id,e.target.value)},[o.id,d]),W=g((e,a)=>{u?.(o.id,e,{name:a})},[o.id,u]),A=g((e,a)=>{u?.(o.id,e,{type:a})},[o.id,u]),I=g((e,a)=>{u?.(o.id,e,{primaryKey:!a})},[o.id,u]),q=g((e,a)=>{u?.(o.id,e,{nullable:!a})},[o.id,u]),j=g((e,a)=>{u?.(o.id,e,{indexed:!a})},[o.id,u]),U=g((e,a)=>{u?.(o.id,e,{unique:!a})},[o.id,u]),G=g(()=>{y?.(o.id)},[o.id,y]);return c("div",{"data-table-id":o.id,className:p("absolute bg-white dark:bg-gray-800 border-2 border-dashed rounded-lg shadow-sm cursor-grab active:cursor-grabbing",o.height?"flex flex-col":void 0,x?"border-green-400 shadow-green-100 dark:shadow-green-900/30 shadow-md":M?"border-blue-500 shadow-blue-100 dark:shadow-blue-900/30":"border-gray-300 dark:border-gray-600",n&&"opacity-60",o.locked&&"!cursor-default"),style:{left:o.x,top:o.y,width:C,height:o.height,userSelect:"none",overflow:o.height?"hidden":void 0},children:[c("div",{className:p("flex items-center justify-between px-3 gap-2","bg-gray-50 dark:bg-gray-700 border-b border-gray-200 dark:border-gray-600"),style:{height:Q},children:[i&&!s&&!n?t("input",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text","aria-label":"Table name",value:o.name,onChange:z,onMouseDown:e=>e.stopPropagation()}):t("span",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 truncate",children:o.name}),t("button",{type:"button",className:"flex-shrink-0 p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-500 dark:text-gray-400",onClick:e=>{e.stopPropagation(),m?.(o.id)},onMouseDown:e=>e.stopPropagation(),"aria-label":k?"Expand table":"Collapse table",children:t(O,{collapsed:k})})]}),!k&&(i&&!s&&!n?t("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:E},children:t("input",{className:"w-full text-xs italic text-gray-400 dark:text-gray-500 bg-transparent border-none outline-none focus:ring-0 p-0 placeholder-gray-400 dark:placeholder-gray-500","aria-label":"Table notes",placeholder:"Add notes...",value:o.notes??"",onChange:e=>v?.(o.id,e.target.value),onMouseDown:e=>e.stopPropagation()})}):o.notes?t("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:E},children:t("span",{className:"text-xs italic text-gray-400 dark:text-gray-500 truncate",children:o.notes})}):null),!k&&c("div",{className:o.height?"overflow-y-auto flex-1 min-h-0":void 0,children:[o.fields.map((e,a)=>c("div",{"data-field-id":e.id,"data-table-id":o.id,className:p("flex items-center gap-1.5 pr-2 relative group",i&&!s&&!n?"pl-[18px]":"pl-2","border-b border-gray-100 dark:border-gray-700 last:border-b-0",x?"bg-blue-50/50 dark:bg-blue-900/10":"hover:bg-gray-50 dark:hover:bg-gray-750",B===a&&"opacity-40",S===a&&"!border-t-2 !border-t-blue-400"),style:{height:w},draggable:i&&!s&&!n,onDragStart:r=>{!i||s||n||(r.stopPropagation(),h.current=a,T(a),r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",String(a)))},onDragOver:r=>{h.current!==null&&(r.preventDefault(),r.stopPropagation(),f(a))},onDragLeave:()=>{S===a&&f(null)},onDrop:r=>{r.preventDefault(),r.stopPropagation(),h.current!==null&&h.current!==a&&F?.(o.id,h.current,a),h.current=null,T(null),f(null)},onDragEnd:()=>{h.current=null,T(null),f(null)},children:[t("div",{"data-connection-side":"left","data-field-id":e.id,"data-table-id":o.id,className:p("absolute -left-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",x?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-blue-400"),style:{top:w/2-5}}),i&&!s&&!n&&t("span",{className:"absolute left-[3px] cursor-grab active:cursor-grabbing opacity-0 group-hover:opacity-100 transition-opacity z-10",style:{top:w/2-6},children:t(te,{})}),i&&!s&&!n?t("button",{type:"button",className:p("w-4 text-xs font-bold flex-shrink-0 text-center cursor-pointer",e.nullable?"text-gray-400":"text-transparent"),onClick:r=>{r.stopPropagation(),q(e.id,e.nullable??!1)},onMouseDown:r=>r.stopPropagation(),title:e.nullable?"Nullable":"Not nullable",children:"?"}):t("span",{className:p("w-4 text-xs font-bold flex-shrink-0 text-center",e.nullable?"text-gray-400":"text-transparent"),children:e.nullable?"?":""}),e.primaryKey&&e.foreignKey?c("span",{className:"flex items-center gap-0.5 flex-shrink-0",children:[i&&!s&&!n?t("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:r=>{r.stopPropagation(),I(e.id,!0)},onMouseDown:r=>r.stopPropagation(),title:"Primary Key (click to remove)",children:t(N,{})}):t(N,{}),t(H,{})]}):e.primaryKey?i&&!s&&!n?t("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:r=>{r.stopPropagation(),I(e.id,!0)},onMouseDown:r=>r.stopPropagation(),title:"Primary Key (click to remove)",children:t(N,{})}):t(N,{}):e.foreignKey?t(H,{}):i&&!s&&!n?t("button",{type:"button",className:"w-3.5 h-3.5 flex-shrink-0 rounded text-gray-300 hover:text-indigo-400 transition-colors cursor-pointer",onClick:r=>{r.stopPropagation(),I(e.id,!1)},onMouseDown:r=>r.stopPropagation(),title:"Set as Primary Key","aria-label":"Set as primary key",children:c("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",opacity:"0.3",children:[t("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),t("circle",{cx:"4.5",cy:"11.5",r:"3"})]})}):t("span",{className:"w-3.5 flex-shrink-0"}),i&&!s&&!n?t("input",{className:p("flex-1 min-w-0 text-xs bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text",e.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),"aria-label":"Field name",value:e.name,onChange:r=>W(e.id,r.target.value),onMouseDown:r=>r.stopPropagation()}):t("span",{className:p("flex-1 min-w-0 text-xs truncate",e.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),children:e.name}),i&&!s&&!n?c("select",{className:"text-xs text-gray-400 dark:text-gray-500 bg-transparent border-none outline-none focus:ring-0 p-0 cursor-pointer text-right",value:e.type,onChange:r=>A(e.id,r.target.value),onMouseDown:r=>r.stopPropagation(),children:[L.map(r=>t("option",{value:r,children:r},r)),!L.includes(e.type)&&t("option",{value:e.type,children:e.type})]}):t("span",{className:"text-xs text-gray-400 dark:text-gray-500 flex-shrink-0",children:e.type}),t(oe,{field:e,tableId:o.id,editable:i,readOnly:s,disabled:n,onFieldChange:u}),e.indexed&&t(_,{}),e.unique&&t(R,{}),i&&!s&&!n&&c("div",{className:"absolute right-1 top-0 bottom-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity bg-gradient-to-l from-white via-white to-transparent dark:from-gray-800 dark:via-gray-800 pl-4 pr-1 z-10",children:[t("button",{type:"button",className:p("cursor-pointer transition-opacity",e.indexed?"opacity-100":"opacity-30 hover:opacity-100"),onClick:r=>{r.stopPropagation(),j(e.id,e.indexed??!1)},onMouseDown:r=>r.stopPropagation(),title:e.indexed?"Indexed (click to remove)":"Add index",children:t(_,{})}),t("button",{type:"button",className:p("cursor-pointer transition-opacity",e.unique?"opacity-100":"opacity-30 hover:opacity-100"),onClick:r=>{r.stopPropagation(),U(e.id,e.unique??!1)},onMouseDown:r=>r.stopPropagation(),title:e.unique?"Unique (click to remove)":"Add unique constraint",children:t(R,{})}),t("button",{type:"button",className:"p-0.5 rounded text-gray-300 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 cursor-pointer",onClick:r=>{r.stopPropagation(),l?.(o.id,e.id)},onMouseDown:r=>r.stopPropagation(),title:"Remove field",children:t(ee,{})})]}),t("div",{"data-connection-side":"right","data-field-id":e.id,"data-table-id":o.id,className:p("absolute -right-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",x?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-green-400"),style:{top:w/2-5}})]},e.id)),i&&!s&&!n&&c("button",{type:"button",className:"flex items-center justify-center w-full gap-1 text-xs text-gray-400 hover:text-blue-500 hover:bg-gray-50 dark:hover:bg-gray-750 transition-colors cursor-pointer",style:{height:$},onClick:e=>{e.stopPropagation(),G()},onMouseDown:e=>e.stopPropagation(),children:[t("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:t("path",{d:"M8 4v8M4 8h8"})}),"Add field"]})]}),!n&&!s&&t("div",{"data-resize-handle":"corner",className:"absolute -bottom-[5px] -right-[5px] w-[14px] h-[14px] cursor-nwse-resize z-20 group/resize",onMouseDown:e=>{e.stopPropagation(),e.preventDefault();let a=o.height??J(o,i);K?.(o.id,e.clientX,e.clientY,C,a)},children:c("svg",{className:"w-full h-full text-gray-300 group-hover/resize:text-blue-400 transition-colors",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[t("path",{d:"M12 2v10H2",opacity:"0"}),t("path",{d:"M6 12L12 6"}),t("path",{d:"M10 12L12 10"})]})})]})});export{ie as SchemaTableRenderer};
|
|
1
|
+
import{memo as B,useCallback as g,useRef as J,useState as P}from"react";import{cn as d}from"../../../lib/cn.js";import{ADD_BUTTON_HEIGHT as Q,DEFAULT_TABLE_WIDTH as Z,FIELD_ROW_HEIGHT as D,getTableHeight as $,HEADER_HEIGHT as O,NOTES_ROW_HEIGHT as F}from"../utils/geometry.js";import{DEFAULT_FIELD_TYPES as ee}from"../utils/schema-helpers.js";import{formatUILabel as L}from"../../../lib/ui-labels.js";import{jsx as t,jsxs as p}from"react/jsx-runtime";var E=()=>p("svg",{className:"w-3.5 h-3.5 text-indigo-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),t("circle",{cx:"4.5",cy:"11.5",r:"3"})]}),H=()=>p("svg",{className:"w-3.5 h-3.5 flex-shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[t("circle",{cx:"8",cy:"8",r:"6",className:"fill-blue-500"}),t("path",{d:"M5 8h6M8 5l3 3-3 3",stroke:"white",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})]}),te=({collapsed:M})=>t("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"currentColor",children:M?t("path",{d:"M6 3l5 5-5 5V3z"}):t("path",{d:"M3 6l5 5 5-5H3z"})}),_=()=>t("svg",{className:"w-3.5 h-3.5 text-amber-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:t("path",{d:"M3 2v12M7 4h6M7 8h4M7 12h5"})}),K=()=>t("svg",{className:"w-3.5 h-3.5 text-purple-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:t("path",{d:"M4 2v8a4 4 0 008 0V2"})}),oe=()=>t("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:t("path",{d:"M4 8h8"})}),re=()=>p("svg",{className:"w-3 h-3 text-gray-300",viewBox:"0 0 16 16",fill:"currentColor",children:[t("circle",{cx:"5",cy:"4",r:"1.5"}),t("circle",{cx:"11",cy:"4",r:"1.5"}),t("circle",{cx:"5",cy:"8",r:"1.5"}),t("circle",{cx:"11",cy:"8",r:"1.5"}),t("circle",{cx:"5",cy:"12",r:"1.5"}),t("circle",{cx:"11",cy:"12",r:"1.5"})]}),ae=B(function({field:o,tableId:T,editable:n,readOnly:i,disabled:l,onFieldChange:x,labels:h}){let[b,y]=P(!1),[v,c]=P(o.defaultValue??""),k=n&&!i&&!l,f=()=>{y(!1),x?.(T,o.id,{defaultValue:v||void 0})};return k?b?t("input",{className:"text-xs w-16 text-emerald-500 bg-transparent border-b border-emerald-300 outline-none focus:ring-0 p-0 flex-shrink-0","aria-label":L(h.schemaEditorDefaultValueFor,{field:o.name}),value:v,onChange:u=>c(u.target.value),onBlur:f,onKeyDown:u=>{u.key==="Enter"&&f(),u.key==="Escape"&&y(!1)},onMouseDown:u=>u.stopPropagation(),autoFocus:!0}):o.defaultValue?p("button",{type:"button",className:"text-xs text-emerald-500 flex-shrink-0 truncate max-w-16 cursor-pointer",onClick:u=>{u.stopPropagation(),c(o.defaultValue??""),y(!0)},onMouseDown:u=>u.stopPropagation(),title:L(h.schemaEditorDefaultValue,{value:o.defaultValue}),children:["= ",o.defaultValue]}):t("button",{type:"button",className:"text-xs text-gray-300 flex-shrink-0 opacity-0 group-hover:opacity-30 hover:!opacity-100 cursor-pointer transition-opacity",onClick:u=>{u.stopPropagation(),c(""),y(!0)},onMouseDown:u=>u.stopPropagation(),title:h.schemaEditorSetDefaultValue,children:"= \u2205"}):o.defaultValue?p("span",{className:"text-xs text-emerald-500 flex-shrink-0 truncate max-w-16",title:L(h.schemaEditorDefaultValue,{value:o.defaultValue}),children:["= ",o.defaultValue]}):null}),ue=B(function({table:o,selected:T,disabled:n,readOnly:i,editable:l,dropTarget:x,fieldTypes:h,onTableNameChange:b,onTableNotesChange:y,onToggleCollapse:v,onFieldChange:c,onFieldAdd:k,onFieldRemove:f,onFieldReorder:u,onResizeStart:z,labels:s}){let S=o.width??Z,w=o.collapsed??!1,R=h.length>0?h:ee,[W,I]=P(null),[V,N]=P(null),m=J(null),U=g(e=>{b?.(o.id,e.target.value)},[o.id,b]),A=g((e,a)=>{c?.(o.id,e,{name:a})},[o.id,c]),q=g((e,a)=>{c?.(o.id,e,{type:a})},[o.id,c]),C=g((e,a)=>{c?.(o.id,e,{primaryKey:!a})},[o.id,c]),j=g((e,a)=>{c?.(o.id,e,{nullable:!a})},[o.id,c]),G=g((e,a)=>{c?.(o.id,e,{indexed:!a})},[o.id,c]),Y=g((e,a)=>{c?.(o.id,e,{unique:!a})},[o.id,c]),X=g(()=>{k?.(o.id)},[o.id,k]);return p("div",{"data-table-id":o.id,className:d("absolute bg-white dark:bg-gray-800 border-2 border-dashed rounded-lg shadow-sm cursor-grab active:cursor-grabbing",o.height?"flex flex-col":void 0,x?"border-green-400 shadow-green-100 dark:shadow-green-900/30 shadow-md":T?"border-blue-500 shadow-blue-100 dark:shadow-blue-900/30":"border-gray-300 dark:border-gray-600",n&&"opacity-60",o.locked&&"!cursor-default"),style:{left:o.x,top:o.y,width:S,height:o.height,userSelect:"none",overflow:o.height?"hidden":void 0},children:[p("div",{className:d("flex items-center justify-between px-3 gap-2","bg-gray-50 dark:bg-gray-700 border-b border-gray-200 dark:border-gray-600"),style:{height:O},children:[l&&!i&&!n?t("input",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text","aria-label":s.schemaEditorTableName,value:o.name,onChange:U,onMouseDown:e=>e.stopPropagation()}):t("span",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 truncate",children:o.name}),t("button",{type:"button",className:"flex-shrink-0 p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-500 dark:text-gray-400",onClick:e=>{e.stopPropagation(),v?.(o.id)},onMouseDown:e=>e.stopPropagation(),"aria-label":w?s.schemaEditorExpandTable:s.schemaEditorCollapseTable,children:t(te,{collapsed:w})})]}),!w&&(l&&!i&&!n?t("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:F},children:t("input",{className:"w-full text-xs italic text-gray-400 dark:text-gray-500 bg-transparent border-none outline-none focus:ring-0 p-0 placeholder-gray-400 dark:placeholder-gray-500","aria-label":s.schemaEditorTableNotes,placeholder:s.schemaEditorNotesPlaceholder,value:o.notes??"",onChange:e=>y?.(o.id,e.target.value),onMouseDown:e=>e.stopPropagation()})}):o.notes?t("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:F},children:t("span",{className:"text-xs italic text-gray-400 dark:text-gray-500 truncate",children:o.notes})}):null),!w&&p("div",{className:o.height?"overflow-y-auto flex-1 min-h-0":void 0,children:[o.fields.map((e,a)=>p("div",{"data-field-id":e.id,"data-table-id":o.id,className:d("flex items-center gap-1.5 pr-2 relative group",l&&!i&&!n?"pl-[18px]":"pl-2","border-b border-gray-100 dark:border-gray-700 last:border-b-0",x?"bg-blue-50/50 dark:bg-blue-900/10":"hover:bg-gray-50 dark:hover:bg-gray-700/50",W===a&&"opacity-40",V===a&&"!border-t-2 !border-t-blue-400"),style:{height:D},draggable:l&&!i&&!n,onDragStart:r=>{!l||i||n||(r.stopPropagation(),m.current=a,I(a),r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",String(a)))},onDragOver:r=>{m.current!==null&&(r.preventDefault(),r.stopPropagation(),N(a))},onDragLeave:()=>{V===a&&N(null)},onDrop:r=>{r.preventDefault(),r.stopPropagation(),m.current!==null&&m.current!==a&&u?.(o.id,m.current,a),m.current=null,I(null),N(null)},onDragEnd:()=>{m.current=null,I(null),N(null)},children:[t("div",{"data-connection-side":"left","data-field-id":e.id,"data-table-id":o.id,className:d("absolute -left-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",x?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-blue-400"),style:{top:D/2-5}}),l&&!i&&!n&&t("span",{className:"absolute left-[3px] cursor-grab active:cursor-grabbing opacity-0 group-hover:opacity-100 transition-opacity z-10",style:{top:D/2-6},children:t(re,{})}),l&&!i&&!n?t("button",{type:"button",className:d("w-4 text-xs font-bold flex-shrink-0 text-center cursor-pointer",e.nullable?"text-gray-400":"text-transparent"),onClick:r=>{r.stopPropagation(),j(e.id,e.nullable??!1)},onMouseDown:r=>r.stopPropagation(),title:e.nullable?s.schemaEditorNullable:s.schemaEditorNotNullable,children:"?"}):t("span",{className:d("w-4 text-xs font-bold flex-shrink-0 text-center",e.nullable?"text-gray-400":"text-transparent"),children:e.nullable?"?":""}),e.primaryKey&&e.foreignKey?p("span",{className:"flex items-center gap-0.5 flex-shrink-0",children:[l&&!i&&!n?t("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:r=>{r.stopPropagation(),C(e.id,!0)},onMouseDown:r=>r.stopPropagation(),title:s.schemaEditorRemovePrimaryKey,children:t(E,{})}):t(E,{}),t(H,{})]}):e.primaryKey?l&&!i&&!n?t("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:r=>{r.stopPropagation(),C(e.id,!0)},onMouseDown:r=>r.stopPropagation(),title:s.schemaEditorRemovePrimaryKey,children:t(E,{})}):t(E,{}):e.foreignKey?t(H,{}):l&&!i&&!n?t("button",{type:"button",className:"w-3.5 h-3.5 flex-shrink-0 rounded text-gray-300 hover:text-indigo-400 transition-colors cursor-pointer",onClick:r=>{r.stopPropagation(),C(e.id,!1)},onMouseDown:r=>r.stopPropagation(),title:s.schemaEditorSetPrimaryKey,"aria-label":s.schemaEditorSetPrimaryKey,children:p("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",opacity:"0.3",children:[t("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),t("circle",{cx:"4.5",cy:"11.5",r:"3"})]})}):t("span",{className:"w-3.5 flex-shrink-0"}),l&&!i&&!n?t("input",{className:d("flex-1 min-w-0 text-xs bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text",e.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),"aria-label":s.schemaEditorFieldName,value:e.name,onChange:r=>A(e.id,r.target.value),onMouseDown:r=>r.stopPropagation()}):t("span",{className:d("flex-1 min-w-0 text-xs truncate",e.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),children:e.name}),l&&!i&&!n?p("select",{className:"text-xs text-gray-400 dark:text-gray-500 bg-transparent border-none outline-none focus:ring-0 p-0 cursor-pointer text-right",value:e.type,onChange:r=>q(e.id,r.target.value),onMouseDown:r=>r.stopPropagation(),children:[R.map(r=>t("option",{value:r,children:r},r)),!R.includes(e.type)&&t("option",{value:e.type,children:e.type})]}):t("span",{className:"text-xs text-gray-400 dark:text-gray-500 flex-shrink-0",children:e.type}),t(ae,{field:e,tableId:o.id,editable:l,readOnly:i,disabled:n,onFieldChange:c,labels:s}),e.indexed&&t(_,{}),e.unique&&t(K,{}),l&&!i&&!n&&p("div",{className:"absolute right-1 top-0 bottom-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity bg-gradient-to-l from-white via-white to-transparent dark:from-gray-800 dark:via-gray-800 pl-4 pr-1 z-10",children:[t("button",{type:"button",className:d("cursor-pointer transition-opacity",e.indexed?"opacity-100":"opacity-30 hover:opacity-100"),onClick:r=>{r.stopPropagation(),G(e.id,e.indexed??!1)},onMouseDown:r=>r.stopPropagation(),title:e.indexed?s.schemaEditorRemoveIndex:s.schemaEditorAddIndex,children:t(_,{})}),t("button",{type:"button",className:d("cursor-pointer transition-opacity",e.unique?"opacity-100":"opacity-30 hover:opacity-100"),onClick:r=>{r.stopPropagation(),Y(e.id,e.unique??!1)},onMouseDown:r=>r.stopPropagation(),title:e.unique?s.schemaEditorRemoveUnique:s.schemaEditorAddUnique,children:t(K,{})}),t("button",{type:"button",className:"p-0.5 rounded text-gray-300 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 cursor-pointer",onClick:r=>{r.stopPropagation(),f?.(o.id,e.id)},onMouseDown:r=>r.stopPropagation(),title:s.schemaEditorRemoveField,children:t(oe,{})})]}),t("div",{"data-connection-side":"right","data-field-id":e.id,"data-table-id":o.id,className:d("absolute -right-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",x?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-green-400"),style:{top:D/2-5}})]},e.id)),l&&!i&&!n&&p("button",{type:"button",className:"flex items-center justify-center w-full gap-1 text-xs text-gray-400 hover:text-blue-500 hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors cursor-pointer",style:{height:Q},onClick:e=>{e.stopPropagation(),X()},onMouseDown:e=>e.stopPropagation(),children:[t("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:t("path",{d:"M8 4v8M4 8h8"})}),s.schemaEditorAddField]})]}),!n&&!i&&t("div",{"data-resize-handle":"corner",className:"absolute -bottom-[5px] -right-[5px] w-[14px] h-[14px] cursor-nwse-resize z-20 group/resize",onMouseDown:e=>{e.stopPropagation(),e.preventDefault();let a=o.height??$(o,l);z?.(o.id,e.clientX,e.clientY,S,a)},children:p("svg",{className:"w-full h-full text-gray-300 group-hover/resize:text-blue-400 transition-colors",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[t("path",{d:"M12 2v10H2",opacity:"0"}),t("path",{d:"M6 12L12 6"}),t("path",{d:"M10 12L12 10"})]})})]})});export{ue as SchemaTableRenderer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var y=Object.defineProperty;var U=Object.getOwnPropertyDescriptor;var Y=Object.getOwnPropertyNames;var j=Object.prototype.hasOwnProperty;var K=(i,r)=>{for(var n in r)y(i,n,{get:r[n],enumerable:!0})},W=(i,r,n,g)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of Y(r))!j.call(i,s)&&s!==n&&y(i,s,{get:()=>r[s],enumerable:!(g=U(r,s))||g.enumerable});return i};var X=i=>W(y({},"__esModule",{value:!0}),i);var d0={};K(d0,{SchemaToolbar:()=>g0});module.exports=X(d0);var a=require("react"),M=require("../../../lib/cn.cjs"),e=require("../../button/Button.cjs"),u=require("../../button-group/ButtonGroup.cjs"),t=require("../../tooltip/Tooltip.cjs"),m=require("../../modal/Modal.cjs"),v=require("../../form/input/Input.cjs"),o=require("react/jsx-runtime"),_=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M10 5a1 1 0 011 1v3h3a1 1 0 110 2h-3v3a1 1 0 11-2 0v-3H6a1 1 0 110-2h3V6a1 1 0 011-1z",clipRule:"evenodd"})}),$=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M5 10a1 1 0 011-1h8a1 1 0 110 2H6a1 1 0 01-1-1z",clipRule:"evenodd"})}),o0=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M4 2a1 1 0 011 1v2.101a7.002 7.002 0 0111.601 2.566 1 1 0 11-1.885.666A5.002 5.002 0 005.999 7H9a1 1 0 010 2H4a1 1 0 01-1-1V3a1 1 0 011-1zm.008 9.057a1 1 0 011.276.61A5.002 5.002 0 0014.001 13H11a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0v-2.101a7.002 7.002 0 01-11.601-2.566 1 1 0 01.61-1.276z",clipRule:"evenodd"})}),a0=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{d:"M3 4a1 1 0 011-1h4a1 1 0 010 2H6.414l2.293 2.293a1 1 0 01-1.414 1.414L5 6.414V8a1 1 0 01-2 0V4zm9 1a1 1 0 010-2h4a1 1 0 011 1v4a1 1 0 01-2 0V6.414l-2.293 2.293a1 1 0 11-1.414-1.414L13.586 5H12zm-9 7a1 1 0 012 0v1.586l2.293-2.293a1 1 0 011.414 1.414L6.414 15H8a1 1 0 010 2H4a1 1 0 01-1-1v-4zm13 0a1 1 0 01-2 0v-1.586l-2.293 2.293a1 1 0 01-1.414-1.414L13.586 9H12a1 1 0 010-2h4a1 1 0 011 1v4z"})}),e0=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M6 2a2 2 0 00-2 2v12a2 2 0 002 2h8a2 2 0 002-2V4a2 2 0 00-2-2H6zm4 5a1 1 0 011 1v1h1a1 1 0 110 2h-1v1a1 1 0 11-2 0v-1H8a1 1 0 110-2h1V8a1 1 0 011-1z",clipRule:"evenodd"})}),t0=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm3.293-7.707a1 1 0 011.414 0L9 10.586V3a1 1 0 112 0v7.586l1.293-1.293a1 1 0 111.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z",clipRule:"evenodd"})}),r0=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM6.293 6.707a1 1 0 010-1.414l3-3a1 1 0 011.414 0l3 3a1 1 0 01-1.414 1.414L11 5.414V13a1 1 0 11-2 0V5.414L7.707 6.707a1 1 0 01-1.414 0z",clipRule:"evenodd"})}),l0=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M2 5a2 2 0 012-2h12a2 2 0 012 2v2a2 2 0 01-2 2H4a2 2 0 01-2-2V5zm14 1a1 1 0 11-2 0 1 1 0 012 0zM2 13a2 2 0 012-2h12a2 2 0 012 2v2a2 2 0 01-2 2H4a2 2 0 01-2-2v-2zm14 1a1 1 0 11-2 0 1 1 0 012 0z",clipRule:"evenodd"})}),i0=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M7.707 3.293a1 1 0 010 1.414L5.414 7H11a7 7 0 017 7v2a1 1 0 11-2 0v-2a5 5 0 00-5-5H5.414l2.293 2.293a1 1 0 11-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",clipRule:"evenodd"})}),s0=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M12.293 3.293a1 1 0 011.414 0l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414-1.414L14.586 9H9a5 5 0 00-5 5v2a1 1 0 11-2 0v-2a7 7 0 017-7h5.586l-2.293-2.293a1 1 0 010-1.414z",clipRule:"evenodd"})}),n0=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{d:"M3 3h4v4H3V3zm0 10h4v4H3v-4zm10-10h4v4h-4V3zm0 10h4v4h-4v-4zM7 5h6v1H7V5zm0 8h6v1H7v-1zM5 7v6h1V7H5zm8 0v6h1V7h-1z"})}),g0=(0,a.memo)(function({zoom:r,onZoomIn:n,onZoomOut:g,onResetView:s,onFitToContent:N,onAddTable:R,onExportJSON:x,onImportJSON:C,onExportSQL:d,onUndo:z,onRedo:k,canUndo:H=!1,canRedo:I=!1,onAutoLayout:f,disabled:l,className:O}){let[L,w]=(0,a.useState)(!1),[T,b]=(0,a.useState)(!1),[V,S]=(0,a.useState)(!1),[B,E]=(0,a.useState)(""),[c,h]=(0,a.useState)(""),[A,Z]=(0,a.useState)(""),J=(0,a.useCallback)(()=>{E(x()),w(!0)},[x]),D=(0,a.useCallback)(()=>{c.trim()&&(C(c.trim()),h(""),b(!1))},[c,C]),P=(0,a.useCallback)(()=>{h(""),b(!1)},[]),Q=(0,a.useCallback)(()=>{w(!1)},[]),q=(0,a.useCallback)(()=>{d&&(Z(d()),S(!0))},[d]),F=(0,a.useCallback)(()=>{S(!1)},[]),G=Math.round(r*100);return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{className:(0,M.cn)("absolute top-3 left-3 z-20 flex items-center gap-2 bg-white dark:bg-gray-800 rounded-lg shadow-md border border-gray-200 dark:border-gray-600 px-2 py-1.5",O),"data-testid":"schema-toolbar",onMouseDown:p=>p.stopPropagation(),children:[(0,o.jsxs)(u.ButtonGroup,{size:"sm",children:[(0,o.jsx)(t.Tooltip,{content:"Zoom in",size:"sm",position:"bottom",children:(0,o.jsx)(e.Button,{icon:(0,o.jsx)(_,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:n,disabled:l,"aria-label":"Zoom in"})}),(0,o.jsx)(t.Tooltip,{content:"Zoom out",size:"sm",position:"bottom",children:(0,o.jsx)(e.Button,{icon:(0,o.jsx)($,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:g,disabled:l,"aria-label":"Zoom out"})})]}),(0,o.jsxs)("span",{className:"text-xs font-mono text-gray-500 dark:text-gray-400 min-w-[3ch] text-center select-none",children:[G,"%"]}),(0,o.jsx)("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),(0,o.jsx)(t.Tooltip,{content:"Reset view",size:"sm",position:"bottom",children:(0,o.jsx)(e.Button,{icon:(0,o.jsx)(o0,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:s,disabled:l,"aria-label":"Reset view"})}),(0,o.jsx)(t.Tooltip,{content:"Fit to content",size:"sm",position:"bottom",children:(0,o.jsx)(e.Button,{icon:(0,o.jsx)(a0,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:N,disabled:l,"aria-label":"Fit to content"})}),(0,o.jsx)("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),(0,o.jsx)(t.Tooltip,{content:"Add table",size:"sm",position:"bottom",children:(0,o.jsx)(e.Button,{icon:(0,o.jsx)(e0,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:R,disabled:l,"aria-label":"Add table"})}),(0,o.jsx)("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),(0,o.jsx)(t.Tooltip,{content:"Export JSON",size:"sm",position:"bottom",children:(0,o.jsx)(e.Button,{icon:(0,o.jsx)(t0,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:J,disabled:l,"aria-label":"Export JSON"})}),(0,o.jsx)(t.Tooltip,{content:"Import JSON",size:"sm",position:"bottom",children:(0,o.jsx)(e.Button,{icon:(0,o.jsx)(r0,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:()=>b(!0),disabled:l,"aria-label":"Import JSON"})}),d&&(0,o.jsx)(t.Tooltip,{content:"Export SQL",size:"sm",position:"bottom",children:(0,o.jsx)(e.Button,{icon:(0,o.jsx)(l0,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:q,disabled:l,"aria-label":"Export SQL"})}),(z||k)&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),(0,o.jsxs)(u.ButtonGroup,{size:"sm",children:[(0,o.jsx)(t.Tooltip,{content:"Undo (Ctrl+Z)",size:"sm",position:"bottom",children:(0,o.jsx)(e.Button,{icon:(0,o.jsx)(i0,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:z,disabled:l||!H,"aria-label":"Undo"})}),(0,o.jsx)(t.Tooltip,{content:"Redo (Ctrl+Y)",size:"sm",position:"bottom",children:(0,o.jsx)(e.Button,{icon:(0,o.jsx)(s0,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:k,disabled:l||!I,"aria-label":"Redo"})})]})]}),f&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),(0,o.jsx)(t.Tooltip,{content:"Auto layout",size:"sm",position:"bottom",children:(0,o.jsx)(e.Button,{icon:(0,o.jsx)(n0,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:f,disabled:l,"aria-label":"Auto layout"})})]})]}),(0,o.jsx)(m.Modal,{isOpen:L,onClose:Q,title:"Export Schema",description:"Copy the JSON below to save your schema.",size:"lg",showSubmit:!1,showCancel:!0,cancelLabel:"Close",children:(0,o.jsx)(v.Input,{label:"Schema JSON",multiline:!0,rows:12,value:B,readOnly:!0,size:"sm"})}),(0,o.jsx)(m.Modal,{isOpen:T,onClose:P,title:"Import Schema",description:"Paste schema JSON to load it into the editor.",size:"lg",showSubmit:!0,submitLabel:"Import",onSubmitClick:D,showCancel:!0,cancelLabel:"Cancel",children:(0,o.jsx)(v.Input,{label:"Schema JSON",multiline:!0,rows:12,value:c,onChange:p=>h(p.target.value),placeholder:'{"tables": [], "relations": []}',size:"sm"})}),(0,o.jsx)(m.Modal,{isOpen:V,onClose:F,title:"Export SQL",description:"Generated PostgreSQL CREATE TABLE statements.",size:"lg",showSubmit:!1,showCancel:!0,cancelLabel:"Close",children:(0,o.jsx)(v.Input,{label:"SQL",multiline:!0,rows:16,value:A,readOnly:!0,size:"sm"})})]})});0&&(module.exports={SchemaToolbar});
|
|
1
|
+
"use strict";var u=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var K=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var X=(n,i)=>{for(var d in i)u(n,d,{get:i[d],enumerable:!0})},Y=(n,i,d,g)=>{if(i&&typeof i=="object"||typeof i=="function")for(let s of K(i))!W.call(n,s)&&s!==d&&u(n,s,{get:()=>i[s],enumerable:!(g=j(i,s))||g.enumerable});return n};var _=n=>Y(u({},"__esModule",{value:!0}),n);var mo={};X(mo,{SchemaToolbar:()=>co});module.exports=_(mo);var e=require("react"),M=require("../../../lib/cn.cjs"),t=require("../../button/Button.cjs"),x=require("../../button-group/ButtonGroup.cjs"),r=require("../../tooltip/Tooltip.cjs"),h=require("../../modal/Modal.cjs"),v=require("../../form/input/Input.cjs"),o=require("react/jsx-runtime"),$=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M10 5a1 1 0 011 1v3h3a1 1 0 110 2h-3v3a1 1 0 11-2 0v-3H6a1 1 0 110-2h3V6a1 1 0 011-1z",clipRule:"evenodd"})}),oo=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M5 10a1 1 0 011-1h8a1 1 0 110 2H6a1 1 0 01-1-1z",clipRule:"evenodd"})}),ao=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M4 2a1 1 0 011 1v2.101a7.002 7.002 0 0111.601 2.566 1 1 0 11-1.885.666A5.002 5.002 0 005.999 7H9a1 1 0 010 2H4a1 1 0 01-1-1V3a1 1 0 011-1zm.008 9.057a1 1 0 011.276.61A5.002 5.002 0 0014.001 13H11a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0v-2.101a7.002 7.002 0 01-11.601-2.566 1 1 0 01.61-1.276z",clipRule:"evenodd"})}),eo=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{d:"M3 4a1 1 0 011-1h4a1 1 0 010 2H6.414l2.293 2.293a1 1 0 01-1.414 1.414L5 6.414V8a1 1 0 01-2 0V4zm9 1a1 1 0 010-2h4a1 1 0 011 1v4a1 1 0 01-2 0V6.414l-2.293 2.293a1 1 0 11-1.414-1.414L13.586 5H12zm-9 7a1 1 0 012 0v1.586l2.293-2.293a1 1 0 011.414 1.414L6.414 15H8a1 1 0 010 2H4a1 1 0 01-1-1v-4zm13 0a1 1 0 01-2 0v-1.586l-2.293 2.293a1 1 0 01-1.414-1.414L13.586 9H12a1 1 0 010-2h4a1 1 0 011 1v4z"})}),to=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M6 2a2 2 0 00-2 2v12a2 2 0 002 2h8a2 2 0 002-2V4a2 2 0 00-2-2H6zm4 5a1 1 0 011 1v1h1a1 1 0 110 2h-1v1a1 1 0 11-2 0v-1H8a1 1 0 110-2h1V8a1 1 0 011-1z",clipRule:"evenodd"})}),ro=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm3.293-7.707a1 1 0 011.414 0L9 10.586V3a1 1 0 112 0v7.586l1.293-1.293a1 1 0 111.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z",clipRule:"evenodd"})}),io=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM6.293 6.707a1 1 0 010-1.414l3-3a1 1 0 011.414 0l3 3a1 1 0 01-1.414 1.414L11 5.414V13a1 1 0 11-2 0V5.414L7.707 6.707a1 1 0 01-1.414 0z",clipRule:"evenodd"})}),lo=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M2 5a2 2 0 012-2h12a2 2 0 012 2v2a2 2 0 01-2 2H4a2 2 0 01-2-2V5zm14 1a1 1 0 11-2 0 1 1 0 012 0zM2 13a2 2 0 012-2h12a2 2 0 012 2v2a2 2 0 01-2 2H4a2 2 0 01-2-2v-2zm14 1a1 1 0 11-2 0 1 1 0 012 0z",clipRule:"evenodd"})}),no=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M7.707 3.293a1 1 0 010 1.414L5.414 7H11a7 7 0 017 7v2a1 1 0 11-2 0v-2a5 5 0 00-5-5H5.414l2.293 2.293a1 1 0 11-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",clipRule:"evenodd"})}),so=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{fillRule:"evenodd",d:"M12.293 3.293a1 1 0 011.414 0l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414-1.414L14.586 9H9a5 5 0 00-5 5v2a1 1 0 11-2 0v-2a7 7 0 017-7h5.586l-2.293-2.293a1 1 0 010-1.414z",clipRule:"evenodd"})}),go=()=>(0,o.jsx)("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,o.jsx)("path",{d:"M3 3h4v4H3V3zm0 10h4v4H3v-4zm10-10h4v4h-4V3zm0 10h4v4h-4v-4zM7 5h6v1H7V5zm0 8h6v1H7v-1zM5 7v6h1V7H5zm8 0v6h1V7h-1z"})}),co=(0,e.memo)(function({zoom:i,onZoomIn:d,onZoomOut:g,onResetView:s,onFitToContent:T,onAddTable:R,onExportJSON:z,onImportJSON:C,onExportSQL:c,onUndo:k,onRedo:f,canUndo:H=!1,canRedo:L=!1,onAutoLayout:w,disabled:l,className:N,labels:a}){let[V,E]=(0,e.useState)(!1),[S,p]=(0,e.useState)(!1),[O,I]=(0,e.useState)(!1),[B,D]=(0,e.useState)(""),[m,b]=(0,e.useState)(""),[A,q]=(0,e.useState)(""),Z=(0,e.useCallback)(()=>{D(z()),E(!0)},[z]),F=(0,e.useCallback)(()=>{m.trim()&&(C(m.trim()),b(""),p(!1))},[m,C]),J=(0,e.useCallback)(()=>{b(""),p(!1)},[]),U=(0,e.useCallback)(()=>{E(!1)},[]),P=(0,e.useCallback)(()=>{c&&(q(c()),I(!0))},[c]),G=(0,e.useCallback)(()=>{I(!1)},[]),Q=Math.round(i*100);return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("div",{className:(0,M.cn)("absolute top-3 left-3 z-20 flex items-center gap-2 bg-white dark:bg-gray-800 rounded-lg shadow-md border border-gray-200 dark:border-gray-600 px-2 py-1.5",N),"data-testid":"schema-toolbar",onMouseDown:y=>y.stopPropagation(),children:[(0,o.jsxs)(x.ButtonGroup,{size:"sm",children:[(0,o.jsx)(r.Tooltip,{content:a.editorZoomIn,size:"sm",position:"bottom",children:(0,o.jsx)(t.Button,{icon:(0,o.jsx)($,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:d,disabled:l,"aria-label":a.editorZoomIn})}),(0,o.jsx)(r.Tooltip,{content:a.editorZoomOut,size:"sm",position:"bottom",children:(0,o.jsx)(t.Button,{icon:(0,o.jsx)(oo,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:g,disabled:l,"aria-label":a.editorZoomOut})})]}),(0,o.jsxs)("span",{className:"text-xs font-mono text-gray-500 dark:text-gray-400 min-w-[3ch] text-center select-none",children:[Q,"%"]}),(0,o.jsx)("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),(0,o.jsx)(r.Tooltip,{content:a.editorResetView,size:"sm",position:"bottom",children:(0,o.jsx)(t.Button,{icon:(0,o.jsx)(ao,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:s,disabled:l,"aria-label":a.editorResetView})}),(0,o.jsx)(r.Tooltip,{content:a.editorFitToContent,size:"sm",position:"bottom",children:(0,o.jsx)(t.Button,{icon:(0,o.jsx)(eo,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:T,disabled:l,"aria-label":a.editorFitToContent})}),(0,o.jsx)("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),(0,o.jsx)(r.Tooltip,{content:a.schemaEditorAddTable,size:"sm",position:"bottom",children:(0,o.jsx)(t.Button,{icon:(0,o.jsx)(to,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:R,disabled:l,"aria-label":a.schemaEditorAddTable})}),(0,o.jsx)("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),(0,o.jsx)(r.Tooltip,{content:a.editorExportJson,size:"sm",position:"bottom",children:(0,o.jsx)(t.Button,{icon:(0,o.jsx)(ro,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:Z,disabled:l,"aria-label":a.editorExportJson})}),(0,o.jsx)(r.Tooltip,{content:a.editorImportJson,size:"sm",position:"bottom",children:(0,o.jsx)(t.Button,{icon:(0,o.jsx)(io,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:()=>p(!0),disabled:l,"aria-label":a.editorImportJson})}),c&&(0,o.jsx)(r.Tooltip,{content:a.schemaEditorExportSql,size:"sm",position:"bottom",children:(0,o.jsx)(t.Button,{icon:(0,o.jsx)(lo,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:P,disabled:l,"aria-label":a.schemaEditorExportSql})}),(k||f)&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),(0,o.jsxs)(x.ButtonGroup,{size:"sm",children:[(0,o.jsx)(r.Tooltip,{content:a.schemaEditorUndoTooltip,size:"sm",position:"bottom",children:(0,o.jsx)(t.Button,{icon:(0,o.jsx)(no,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:k,disabled:l||!H,"aria-label":a.schemaEditorUndo})}),(0,o.jsx)(r.Tooltip,{content:a.schemaEditorRedoTooltip,size:"sm",position:"bottom",children:(0,o.jsx)(t.Button,{icon:(0,o.jsx)(so,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:f,disabled:l||!L,"aria-label":a.schemaEditorRedo})})]})]}),w&&(0,o.jsxs)(o.Fragment,{children:[(0,o.jsx)("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),(0,o.jsx)(r.Tooltip,{content:a.schemaEditorAutoLayout,size:"sm",position:"bottom",children:(0,o.jsx)(t.Button,{icon:(0,o.jsx)(go,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:w,disabled:l,"aria-label":a.schemaEditorAutoLayout})})]})]}),(0,o.jsx)(h.Modal,{isOpen:V,onClose:U,title:a.schemaEditorExportTitle,description:a.schemaEditorExportDescription,size:"lg",showSubmit:!1,showCancel:!0,cancelLabel:a.editorClose,children:(0,o.jsx)(v.Input,{label:a.schemaEditorJsonField,multiline:!0,rows:12,value:B,readOnly:!0,size:"sm"})}),(0,o.jsx)(h.Modal,{isOpen:S,onClose:J,title:a.schemaEditorImportTitle,description:a.schemaEditorImportDescription,size:"lg",showSubmit:!0,submitLabel:a.editorImport,onSubmitClick:F,showCancel:!0,cancelLabel:a.cancel,children:(0,o.jsx)(v.Input,{label:a.schemaEditorJsonField,multiline:!0,rows:12,value:m,onChange:y=>b(y.target.value),placeholder:'{"tables": [], "relations": []}',size:"sm"})}),(0,o.jsx)(h.Modal,{isOpen:O,onClose:G,title:a.schemaEditorExportSql,description:a.schemaEditorSqlDescription,size:"lg",showSubmit:!1,showCancel:!0,cancelLabel:a.editorClose,children:(0,o.jsx)(v.Input,{label:"SQL",multiline:!0,rows:16,value:A,readOnly:!0,size:"sm"})})]})});0&&(module.exports={SchemaToolbar});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{memo as
|
|
1
|
+
import{memo as j,useState as l,useCallback as n}from"react";import{cn as K}from"../../../lib/cn.js";import{Button as t}from"../../button/Button.js";import{ButtonGroup as f}from"../../button-group/ButtonGroup.js";import{Tooltip as r}from"../../tooltip/Tooltip.js";import{Modal as h}from"../../modal/Modal.js";import{Input as v}from"../../form/input/Input.js";import{Fragment as p,jsx as o,jsxs as i}from"react/jsx-runtime";var W=()=>o("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:o("path",{fillRule:"evenodd",d:"M10 5a1 1 0 011 1v3h3a1 1 0 110 2h-3v3a1 1 0 11-2 0v-3H6a1 1 0 110-2h3V6a1 1 0 011-1z",clipRule:"evenodd"})}),X=()=>o("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:o("path",{fillRule:"evenodd",d:"M5 10a1 1 0 011-1h8a1 1 0 110 2H6a1 1 0 01-1-1z",clipRule:"evenodd"})}),Y=()=>o("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:o("path",{fillRule:"evenodd",d:"M4 2a1 1 0 011 1v2.101a7.002 7.002 0 0111.601 2.566 1 1 0 11-1.885.666A5.002 5.002 0 005.999 7H9a1 1 0 010 2H4a1 1 0 01-1-1V3a1 1 0 011-1zm.008 9.057a1 1 0 011.276.61A5.002 5.002 0 0014.001 13H11a1 1 0 110-2h5a1 1 0 011 1v5a1 1 0 11-2 0v-2.101a7.002 7.002 0 01-11.601-2.566 1 1 0 01.61-1.276z",clipRule:"evenodd"})}),_=()=>o("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:o("path",{d:"M3 4a1 1 0 011-1h4a1 1 0 010 2H6.414l2.293 2.293a1 1 0 01-1.414 1.414L5 6.414V8a1 1 0 01-2 0V4zm9 1a1 1 0 010-2h4a1 1 0 011 1v4a1 1 0 01-2 0V6.414l-2.293 2.293a1 1 0 11-1.414-1.414L13.586 5H12zm-9 7a1 1 0 012 0v1.586l2.293-2.293a1 1 0 011.414 1.414L6.414 15H8a1 1 0 010 2H4a1 1 0 01-1-1v-4zm13 0a1 1 0 01-2 0v-1.586l-2.293 2.293a1 1 0 01-1.414-1.414L13.586 9H12a1 1 0 010-2h4a1 1 0 011 1v4z"})}),$=()=>o("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:o("path",{fillRule:"evenodd",d:"M6 2a2 2 0 00-2 2v12a2 2 0 002 2h8a2 2 0 002-2V4a2 2 0 00-2-2H6zm4 5a1 1 0 011 1v1h1a1 1 0 110 2h-1v1a1 1 0 11-2 0v-1H8a1 1 0 110-2h1V8a1 1 0 011-1z",clipRule:"evenodd"})}),oo=()=>o("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:o("path",{fillRule:"evenodd",d:"M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zm3.293-7.707a1 1 0 011.414 0L9 10.586V3a1 1 0 112 0v7.586l1.293-1.293a1 1 0 111.414 1.414l-3 3a1 1 0 01-1.414 0l-3-3a1 1 0 010-1.414z",clipRule:"evenodd"})}),ao=()=>o("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:o("path",{fillRule:"evenodd",d:"M3 17a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM6.293 6.707a1 1 0 010-1.414l3-3a1 1 0 011.414 0l3 3a1 1 0 01-1.414 1.414L11 5.414V13a1 1 0 11-2 0V5.414L7.707 6.707a1 1 0 01-1.414 0z",clipRule:"evenodd"})}),eo=()=>o("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:o("path",{fillRule:"evenodd",d:"M2 5a2 2 0 012-2h12a2 2 0 012 2v2a2 2 0 01-2 2H4a2 2 0 01-2-2V5zm14 1a1 1 0 11-2 0 1 1 0 012 0zM2 13a2 2 0 012-2h12a2 2 0 012 2v2a2 2 0 01-2 2H4a2 2 0 01-2-2v-2zm14 1a1 1 0 11-2 0 1 1 0 012 0z",clipRule:"evenodd"})}),to=()=>o("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:o("path",{fillRule:"evenodd",d:"M7.707 3.293a1 1 0 010 1.414L5.414 7H11a7 7 0 017 7v2a1 1 0 11-2 0v-2a5 5 0 00-5-5H5.414l2.293 2.293a1 1 0 11-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",clipRule:"evenodd"})}),ro=()=>o("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:o("path",{fillRule:"evenodd",d:"M12.293 3.293a1 1 0 011.414 0l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414-1.414L14.586 9H9a5 5 0 00-5 5v2a1 1 0 11-2 0v-2a7 7 0 017-7h5.586l-2.293-2.293a1 1 0 010-1.414z",clipRule:"evenodd"})}),io=()=>o("svg",{className:"w-4 h-4",viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:o("path",{d:"M3 3h4v4H3V3zm0 10h4v4H3v-4zm10-10h4v4h-4V3zm0 10h4v4h-4v-4zM7 5h6v1H7V5zm0 8h6v1H7v-1zM5 7v6h1V7H5zm8 0v6h1V7h-1z"})}),po=j(function({zoom:w,onZoomIn:E,onZoomOut:I,onResetView:M,onFitToContent:T,onAddTable:R,onExportJSON:b,onImportJSON:y,onExportSQL:s,onUndo:u,onRedo:x,canUndo:H=!1,canRedo:L=!1,onAutoLayout:z,disabled:e,className:N,labels:a}){let[V,C]=l(!1),[S,g]=l(!1),[O,k]=l(!1),[B,D]=l(""),[d,c]=l(""),[A,q]=l(""),Z=n(()=>{D(b()),C(!0)},[b]),F=n(()=>{d.trim()&&(y(d.trim()),c(""),g(!1))},[d,y]),J=n(()=>{c(""),g(!1)},[]),U=n(()=>{C(!1)},[]),P=n(()=>{s&&(q(s()),k(!0))},[s]),G=n(()=>{k(!1)},[]),Q=Math.round(w*100);return i(p,{children:[i("div",{className:K("absolute top-3 left-3 z-20 flex items-center gap-2 bg-white dark:bg-gray-800 rounded-lg shadow-md border border-gray-200 dark:border-gray-600 px-2 py-1.5",N),"data-testid":"schema-toolbar",onMouseDown:m=>m.stopPropagation(),children:[i(f,{size:"sm",children:[o(r,{content:a.editorZoomIn,size:"sm",position:"bottom",children:o(t,{icon:o(W,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:E,disabled:e,"aria-label":a.editorZoomIn})}),o(r,{content:a.editorZoomOut,size:"sm",position:"bottom",children:o(t,{icon:o(X,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:I,disabled:e,"aria-label":a.editorZoomOut})})]}),i("span",{className:"text-xs font-mono text-gray-500 dark:text-gray-400 min-w-[3ch] text-center select-none",children:[Q,"%"]}),o("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),o(r,{content:a.editorResetView,size:"sm",position:"bottom",children:o(t,{icon:o(Y,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:M,disabled:e,"aria-label":a.editorResetView})}),o(r,{content:a.editorFitToContent,size:"sm",position:"bottom",children:o(t,{icon:o(_,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:T,disabled:e,"aria-label":a.editorFitToContent})}),o("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),o(r,{content:a.schemaEditorAddTable,size:"sm",position:"bottom",children:o(t,{icon:o($,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:R,disabled:e,"aria-label":a.schemaEditorAddTable})}),o("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),o(r,{content:a.editorExportJson,size:"sm",position:"bottom",children:o(t,{icon:o(oo,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:Z,disabled:e,"aria-label":a.editorExportJson})}),o(r,{content:a.editorImportJson,size:"sm",position:"bottom",children:o(t,{icon:o(ao,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:()=>g(!0),disabled:e,"aria-label":a.editorImportJson})}),s&&o(r,{content:a.schemaEditorExportSql,size:"sm",position:"bottom",children:o(t,{icon:o(eo,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:P,disabled:e,"aria-label":a.schemaEditorExportSql})}),(u||x)&&i(p,{children:[o("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),i(f,{size:"sm",children:[o(r,{content:a.schemaEditorUndoTooltip,size:"sm",position:"bottom",children:o(t,{icon:o(to,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:u,disabled:e||!H,"aria-label":a.schemaEditorUndo})}),o(r,{content:a.schemaEditorRedoTooltip,size:"sm",position:"bottom",children:o(t,{icon:o(ro,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:x,disabled:e||!L,"aria-label":a.schemaEditorRedo})})]})]}),z&&i(p,{children:[o("div",{className:"w-px h-5 bg-gray-200 dark:bg-gray-600"}),o(r,{content:a.schemaEditorAutoLayout,size:"sm",position:"bottom",children:o(t,{icon:o(io,{}),size:"sm",bgColor:"bg-gray-100 hover:bg-gray-200 dark:bg-gray-700 dark:hover:bg-gray-600",textColor:"text-gray-700 dark:text-gray-200",onClick:z,disabled:e,"aria-label":a.schemaEditorAutoLayout})})]})]}),o(h,{isOpen:V,onClose:U,title:a.schemaEditorExportTitle,description:a.schemaEditorExportDescription,size:"lg",showSubmit:!1,showCancel:!0,cancelLabel:a.editorClose,children:o(v,{label:a.schemaEditorJsonField,multiline:!0,rows:12,value:B,readOnly:!0,size:"sm"})}),o(h,{isOpen:S,onClose:J,title:a.schemaEditorImportTitle,description:a.schemaEditorImportDescription,size:"lg",showSubmit:!0,submitLabel:a.editorImport,onSubmitClick:F,showCancel:!0,cancelLabel:a.cancel,children:o(v,{label:a.schemaEditorJsonField,multiline:!0,rows:12,value:d,onChange:m=>c(m.target.value),placeholder:'{"tables": [], "relations": []}',size:"sm"})}),o(h,{isOpen:O,onClose:G,title:a.schemaEditorExportSql,description:a.schemaEditorSqlDescription,size:"lg",showSubmit:!1,showCancel:!0,cancelLabel:a.editorClose,children:o(v,{label:"SQL",multiline:!0,rows:16,value:A,readOnly:!0,size:"sm"})})]})});export{po as SchemaToolbar};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var U=Object.defineProperty;var ye=Object.getOwnPropertyDescriptor;var Ee=Object.getOwnPropertyNames;var Ne=Object.prototype.hasOwnProperty;var Le=(a,o)=>{for(var c in o)U(a,c,{get:o[c],enumerable:!0})},Ie=(a,o,c,l)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of Ee(o))!Ne.call(a,i)&&i!==c&&U(a,i,{get:()=>o[i],enumerable:!(l=ye(o,i))||l.enumerable});return a};var De=a=>Ie(U({},"__esModule",{value:!0}),a);var Ke={};Le(Ke,{Select:()=>He});module.exports=De(Ke);var r=require("react"),ce=require("react-dom"),ue=require("../../lib/aria-hide.cjs"),n=require("react/jsx-runtime"),_=()=>{},Ce=[],Se=(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,n.jsx)("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Me=(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,n.jsx)("path",{d:"M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Ae=(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0 animate-spin",children:[(0,n.jsx)("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",strokeOpacity:"0.25"}),(0,n.jsx)("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),Oe=(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,n.jsx)("path",{d:"M11.5 3.5L5.5 10.5L2.5 7.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),O={sm:{trigger:"h-8 px-2.5 text-xs gap-1.5",content:"text-xs",option:"px-2.5 py-1.5",searchInput:"px-2.5 py-1.5 text-xs"},md:{trigger:"h-10 px-3 text-sm gap-2",content:"text-sm",option:"px-3 py-2",searchInput:"px-3 py-2 text-sm"},lg:{trigger:"h-12 px-4 text-base gap-2.5",content:"text-base",option:"px-4 py-2.5",searchInput:"px-4 py-2.5 text-base"}},ie={default:{trigger:"border border-gray-300 bg-white dark:border-gray-600 dark:bg-gray-800",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"},outlined:{trigger:"border-2 border-gray-300 bg-transparent dark:border-gray-600",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"},filled:{trigger:"border border-transparent bg-gray-100 dark:bg-gray-700",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}};function k(...a){let o="";for(let c=0;c<a.length;c++){let l=a[c];l&&(o&&(o+=" "),o+=l)}return o}function Re(a,o){if(!o)return a;let c=o.toLowerCase();return a.filter(l=>{if(l.label.toLowerCase().includes(c)||l.value.toLowerCase().includes(c))return!0;if(l.keywords){for(let i of l.keywords)if(i.toLowerCase().includes(c))return!0}return!1})}var Te=(0,r.memo)((0,r.forwardRef)(function({option:o,isSelected:c,isHighlighted:l,isDisabled:i,sizeKey:P,optionId:g,onClick:m,onMouseEnter:I,index:w},R){let V=()=>{i||m(o.value)},E=()=>{i||I(w)};return(0,n.jsxs)("div",{ref:R,id:g,role:"option","aria-selected":c,"aria-disabled":i||void 0,"data-highlighted":l||void 0,className:k(O[P].option,"flex items-center gap-2 cursor-pointer select-none transition-colors",l&&!i&&"bg-blue-50 dark:bg-blue-900/30",c&&!l&&"bg-gray-50 dark:bg-gray-700/50",i&&"opacity-50 cursor-not-allowed"),onClick:V,onMouseEnter:E,children:[o.icon?(0,n.jsx)("span",{className:"flex shrink-0 items-center",children:o.icon}):null,(0,n.jsxs)("span",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"truncate",children:o.label}),o.description?(0,n.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:o.description}):null]}),c?(0,n.jsx)("span",{className:"ml-auto text-blue-600 dark:text-blue-400",children:Oe}):null]})}));function He({options:a=Ce,value:o,defaultValue:c,onValueChange:l,searchable:i=!1,clearable:P=!1,disabled:g=!1,readOnly:m=!1,loading:I=!1,size:w="md",variant:R="default",placeholder:V="Select...",label:E,description:q,helperText:F,error:D,required:Q=!1,noOptionsText:de="No options",onSearchChange:X,name:Z,className:pe,triggerClassName:fe,contentClassName:ge,maxHeight:B=256}){let C=(0,r.useId)(),$=`${C}-label`,G=`${C}-trigger`,J=`${C}-listbox`,v=(0,r.useRef)(null),W=(0,r.useRef)(null),ee=(0,r.useRef)(null),te=(0,r.useRef)([]),S=o!==void 0,[be,ne]=(0,r.useState)(c??""),N=S?o:be,[u,Y]=(0,r.useState)(!1),[j,M]=(0,r.useState)(""),[s,f]=(0,r.useState)(-1),[T,re]=(0,r.useState)(null),p=(0,r.useMemo)(()=>i?Re(a,j):a,[a,j,i]),H=(0,r.useMemo)(()=>a.find(e=>e.value===N)??null,[a,N]),x=(0,r.useMemo)(()=>{let e=new Set;for(let t of a)t.disabled&&e.add(t.value);return e},[a]),L=(0,r.useCallback)(e=>{S||ne(e),(l??_)(e),Y(!1),M(""),f(-1),v.current?.focus()},[S,l]),me=(0,r.useCallback)(e=>{e.stopPropagation(),S||ne(""),(l??_)(""),M(""),v.current?.focus()},[S,l]),A=(0,r.useCallback)(()=>{g||m||(Y(!0),M(""),f(-1))},[g,m]),b=(0,r.useCallback)(()=>{Y(!1),M(""),f(-1),v.current?.focus()},[]),he=(0,r.useCallback)(()=>{u?b():A()},[u,b,A]),h=(0,r.useCallback)((e,t)=>{let d=p.length;if(d===0)return-1;let y=e;for(let K=0;K<d;K++)if(y=((y+t)%d+d)%d,!x.has(p[y].value))return y;return-1},[p,x]),ve=(0,r.useCallback)(e=>{if(!(g||m)){if(u){switch(e.key){case"ArrowDown":{e.preventDefault();let t=h(s,1);t!==-1&&f(t);break}case"ArrowUp":{e.preventDefault();let t=h(s,-1);t!==-1&&f(t);break}case"Home":{e.preventDefault();let t=h(-1,1);t!==-1&&f(t);break}case"End":{e.preventDefault();let t=h(p.length,-1);t!==-1&&f(t);break}case"Enter":{if(e.preventDefault(),s>=0&&s<p.length){let t=p[s];x.has(t.value)||L(t.value)}break}case" ":if(e.preventDefault(),s>=0&&s<p.length){let t=p[s];x.has(t.value)||L(t.value)}else b();break;case"Escape":e.preventDefault(),b();break;case"Tab":b();break}return}switch(e.key){case"ArrowDown":case"ArrowUp":e.preventDefault(),A();break;case"Enter":case" ":e.preventDefault(),A();break}}},[g,m,u,A,b,s,p,x,h,L]),oe=(0,r.useCallback)(e=>{switch(e.key){case"ArrowDown":{e.preventDefault();let t=h(s,1);t!==-1&&f(t);break}case"ArrowUp":{e.preventDefault();let t=h(s,-1);t!==-1&&f(t);break}case"Home":{e.preventDefault();let t=h(-1,1);t!==-1&&f(t);break}case"End":{e.preventDefault();let t=h(p.length,-1);t!==-1&&f(t);break}case"Enter":{if(e.preventDefault(),s>=0&&s<p.length){let t=p[s];x.has(t.value)||L(t.value)}break}case"Escape":e.preventDefault(),b();break;case"Tab":b();break}},[s,p,x,h,L,b]),xe=(0,r.useCallback)(e=>{let t=e.target.value;M(t),f(-1),(X??_)(t)},[X]);(0,r.useEffect)(()=>{if(!u)return;let e=t=>{let d=t.target;v.current?.contains(d)||W.current?.contains(d)||b()};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e,{passive:!0}),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)}},[u,b]),(0,r.useEffect)(()=>{if(!u||!v.current){re(null);return}let e=()=>{let t=v.current;if(!t)return;let d=t.getBoundingClientRect(),y=window.innerHeight-d.bottom,K=d.top,se=B+8,le=y<se&&K>y?"top":"bottom";re({top:le==="bottom"?d.bottom+window.scrollY+4:d.top+window.scrollY-se,left:d.left+window.scrollX,width:d.width,placement:le})};return e(),window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[u,B]),(0,r.useEffect)(()=>{u&&i&&ee.current?.focus()},[u,i]),(0,r.useEffect)(()=>{let e=W.current;if(!(!u||!e))return(0,ue.registerFloatingLayer)(e,()=>v.current)},[u]),(0,r.useEffect)(()=>{if(s>=0){let e=te.current[s];e&&typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest"})}},[s]);let z=N!==""&&N!==void 0,ke=P&&z&&!g&&!m&&!I,ae=!g&&!m,we=k("w-full flex items-center justify-between rounded-md transition-colors","text-gray-900 dark:text-gray-100",O[w].trigger,ie[R].trigger,!D&&ae&&ie[R].focus,D&&"border-red-500 dark:border-red-400 focus:ring-2 focus:ring-red-500 focus:border-red-500",g&&"opacity-50 cursor-not-allowed bg-gray-50 dark:bg-gray-900",m&&"cursor-default",!g&&!m&&"cursor-pointer",fe);return(0,n.jsxs)("div",{className:k("flex flex-col gap-1",pe),children:[E?(0,n.jsxs)("label",{id:$,htmlFor:G,className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:[E,Q?(0,n.jsx)("span",{className:"text-red-500 ml-0.5","aria-hidden":"true",children:"*"}):null]}):null,q?(0,n.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:q}):null,(0,n.jsxs)("button",{ref:v,id:G,type:"button",role:"combobox","aria-expanded":u,"aria-haspopup":"listbox","aria-controls":u?J:void 0,"aria-labelledby":E?$:void 0,"aria-required":Q||void 0,"aria-invalid":D?!0:void 0,"aria-activedescendant":u&&s>=0?`${C}-option-${s}`:void 0,disabled:g,className:we,onClick:ae?he:void 0,onKeyDown:ve,children:[(0,n.jsxs)("span",{className:k("flex items-center gap-2 min-w-0 flex-1 truncate",!z&&"text-gray-400 dark:text-gray-500"),children:[H?.icon?(0,n.jsx)("span",{className:"flex shrink-0 items-center",children:H.icon}):null,(0,n.jsx)("span",{className:"truncate",children:z&&H?H.label:V})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1 shrink-0",children:[I?(0,n.jsx)("span",{className:"text-gray-400",children:Ae}):null,ke?(0,n.jsx)("span",{role:"button",tabIndex:-1,"aria-label":"Clear selection",className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 p-0.5 rounded transition-colors",onClick:me,onMouseDown:e=>e.preventDefault(),children:Me}):null,(0,n.jsx)("span",{className:k("text-gray-400 transition-transform duration-200",u&&"rotate-180"),children:Se})]})]}),D?(0,n.jsx)("p",{role:"alert",className:"text-xs text-red-500 dark:text-red-400",children:D}):F?(0,n.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:F}):null,Z?(0,n.jsx)("input",{type:"hidden",name:Z,value:N??""}):null,u&&T?(0,ce.createPortal)((0,n.jsxs)("div",{ref:W,role:"listbox",id:J,"aria-labelledby":E?$:void 0,className:k("fixed z-50 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700","rounded-md shadow-lg overflow-hidden","animate-in fade-in-0 zoom-in-95",O[w].content,ge),style:{top:T.top,left:T.left,width:T.width,position:"absolute"},onKeyDown:oe,children:[i?(0,n.jsx)("div",{className:"border-b border-gray-200 dark:border-gray-700",children:(0,n.jsx)("input",{ref:ee,type:"text",role:"searchbox","aria-label":"Search options",className:k(O[w].searchInput,"w-full outline-none bg-transparent text-gray-900 dark:text-gray-100","placeholder:text-gray-400 dark:placeholder:text-gray-500"),placeholder:"Search...",value:j,onChange:xe,onKeyDown:oe})}):null,(0,n.jsx)("div",{className:"overflow-y-auto",style:{maxHeight:B},children:p.length===0?(0,n.jsx)("div",{className:k(O[w].option,"text-gray-500 dark:text-gray-400 text-center py-4"),children:de}):p.map((e,t)=>(0,n.jsx)(Te,{option:e,isSelected:e.value===N,isHighlighted:t===s,isDisabled:I||x.has(e.value),sizeKey:w,optionId:`${C}-option-${t}`,onClick:L,onMouseEnter:f,index:t,ref:d=>{te.current[t]=d}},e.value))})]}),document.body):null]})}0&&(module.exports={Select});
|
|
1
|
+
"use strict";"use client";var q=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var Te=Object.prototype.hasOwnProperty;var Ae=(s,o)=>{for(var c in o)q(s,c,{get:o[c],enumerable:!0})},Pe=(s,o,c,l)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of Oe(o))!Te.call(s,i)&&i!==c&&q(s,i,{get:()=>o[i],enumerable:!(l=Me(o,i))||l.enumerable});return s};var Re=s=>Pe(q({},"__esModule",{value:!0}),s);var je={};Ae(je,{Select:()=>Ye});module.exports=Re(je);var r=require("react"),ue=require("react-dom"),de=require("../../lib/aria-hide.cjs"),pe=require("../../lib/i18n.cjs"),n=require("react/jsx-runtime"),F=()=>{},He=[],Ke=(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,n.jsx)("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Ve=(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,n.jsx)("path",{d:"M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Be=(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0 animate-spin",children:[(0,n.jsx)("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",strokeOpacity:"0.25"}),(0,n.jsx)("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),$e=(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,n.jsx)("path",{d:"M11.5 3.5L5.5 10.5L2.5 7.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),P={sm:{trigger:"h-8 px-2.5 text-xs gap-1.5",content:"text-xs",option:"px-2.5 py-1.5",searchInput:"px-2.5 py-1.5 text-xs"},md:{trigger:"h-10 px-3 text-sm gap-2",content:"text-sm",option:"px-3 py-2",searchInput:"px-3 py-2 text-sm"},lg:{trigger:"h-12 px-4 text-base gap-2.5",content:"text-base",option:"px-4 py-2.5",searchInput:"px-4 py-2.5 text-base"}},ce={default:{trigger:"border border-gray-300 bg-white dark:border-gray-600 dark:bg-gray-800",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"},outlined:{trigger:"border-2 border-gray-300 bg-transparent dark:border-gray-600",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"},filled:{trigger:"border border-transparent bg-gray-100 dark:bg-gray-700",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}};function w(...s){let o="";for(let c=0;c<s.length;c++){let l=s[c];l&&(o&&(o+=" "),o+=l)}return o}function We(s,o){if(!o)return s;let c=o.toLowerCase();return s.filter(l=>{if(l.label.toLowerCase().includes(c)||l.value.toLowerCase().includes(c))return!0;if(l.keywords){for(let i of l.keywords)if(i.toLowerCase().includes(c))return!0}return!1})}var Ue=(0,r.memo)((0,r.forwardRef)(function({option:o,isSelected:c,isHighlighted:l,isDisabled:i,sizeKey:B,optionId:g,onClick:m,onMouseEnter:I,index:k},R){let $=()=>{i||m(o.value)},E=()=>{i||I(k)};return(0,n.jsxs)("div",{ref:R,id:g,role:"option","aria-selected":c,"aria-disabled":i||void 0,"data-highlighted":l||void 0,className:w(P[B].option,"flex items-center gap-2 cursor-pointer select-none transition-colors",l&&!i&&"bg-blue-50 dark:bg-blue-900/30",c&&!l&&"bg-gray-50 dark:bg-gray-700/50",i&&"opacity-50 cursor-not-allowed"),onClick:$,onMouseEnter:E,children:[o.icon?(0,n.jsx)("span",{className:"flex shrink-0 items-center",children:o.icon}):null,(0,n.jsxs)("span",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"truncate",children:o.label}),o.description?(0,n.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:o.description}):null]}),c?(0,n.jsx)("span",{className:"ml-auto text-blue-600 dark:text-blue-400",children:$e}):null]})}));function Ye({options:s=He,value:o,defaultValue:c,onValueChange:l,searchable:i=!1,clearable:B=!1,disabled:g=!1,readOnly:m=!1,loading:I=!1,size:k="md",variant:R="default",placeholder:$,label:E,description:Q,helperText:X,error:D,required:Z=!1,noOptionsText:fe,clearLabel:ge,searchLabel:be,searchPlaceholder:me,onSearchChange:G,name:J,className:he,triggerClassName:ve,contentClassName:xe,maxHeight:W=256}){let C=(0,pe.useUILabels)(),we=$??C.selectPlaceholder,ke=fe??C.selectNoOptions,S=(0,r.useId)(),U=`${S}-label`,ee=`${S}-trigger`,te=`${S}-listbox`,v=(0,r.useRef)(null),Y=(0,r.useRef)(null),ne=(0,r.useRef)(null),re=(0,r.useRef)([]),M=o!==void 0,[ye,oe]=(0,r.useState)(c??""),L=M?o:ye,[p,j]=(0,r.useState)(!1),[z,O]=(0,r.useState)(""),[a,f]=(0,r.useState)(-1),[T,se]=(0,r.useState)(null),d=(0,r.useMemo)(()=>i?We(s,z):s,[s,z,i]),H=(0,r.useMemo)(()=>s.find(e=>e.value===L)??null,[s,L]),x=(0,r.useMemo)(()=>{let e=new Set;for(let t of s)t.disabled&&e.add(t.value);return e},[s]),N=(0,r.useCallback)(e=>{M||oe(e),(l??F)(e),j(!1),O(""),f(-1),v.current?.focus()},[M,l]),Ee=(0,r.useCallback)(e=>{e.stopPropagation(),M||oe(""),(l??F)(""),O(""),v.current?.focus()},[M,l]),A=(0,r.useCallback)(()=>{g||m||(j(!0),O(""),f(-1))},[g,m]),b=(0,r.useCallback)(()=>{j(!1),O(""),f(-1),v.current?.focus()},[]),Le=(0,r.useCallback)(()=>{p?b():A()},[p,b,A]),h=(0,r.useCallback)((e,t)=>{let u=d.length;if(u===0)return-1;let y=e;for(let V=0;V<u;V++)if(y=((y+t)%u+u)%u,!x.has(d[y].value))return y;return-1},[d,x]),Ne=(0,r.useCallback)(e=>{if(!(g||m)){if(p){switch(e.key){case"ArrowDown":{e.preventDefault();let t=h(a,1);t!==-1&&f(t);break}case"ArrowUp":{e.preventDefault();let t=h(a,-1);t!==-1&&f(t);break}case"Home":{e.preventDefault();let t=h(-1,1);t!==-1&&f(t);break}case"End":{e.preventDefault();let t=h(d.length,-1);t!==-1&&f(t);break}case"Enter":{if(e.preventDefault(),a>=0&&a<d.length){let t=d[a];x.has(t.value)||N(t.value)}break}case" ":if(e.preventDefault(),a>=0&&a<d.length){let t=d[a];x.has(t.value)||N(t.value)}else b();break;case"Escape":e.preventDefault(),b();break;case"Tab":b();break}return}switch(e.key){case"ArrowDown":case"ArrowUp":e.preventDefault(),A();break;case"Enter":case" ":e.preventDefault(),A();break}}},[g,m,p,A,b,a,d,x,h,N]),Ie=(0,r.useCallback)(e=>{switch(e.key){case"ArrowDown":{e.preventDefault();let t=h(a,1);t!==-1&&f(t);break}case"ArrowUp":{e.preventDefault();let t=h(a,-1);t!==-1&&f(t);break}case"Home":{e.preventDefault();let t=h(-1,1);t!==-1&&f(t);break}case"End":{e.preventDefault();let t=h(d.length,-1);t!==-1&&f(t);break}case"Enter":{if(e.preventDefault(),a>=0&&a<d.length){let t=d[a];x.has(t.value)||N(t.value)}break}case"Escape":e.preventDefault(),b();break;case"Tab":b();break}},[a,d,x,h,N,b]),De=(0,r.useCallback)(e=>{let t=e.target.value;O(t),f(-1),(G??F)(t)},[G]);(0,r.useEffect)(()=>{if(!p)return;let e=t=>{let u=t.target;v.current?.contains(u)||Y.current?.contains(u)||b()};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e,{passive:!0}),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)}},[p,b]),(0,r.useEffect)(()=>{if(!p||!v.current){se(null);return}let e=()=>{let t=v.current;if(!t)return;let u=t.getBoundingClientRect(),y=window.innerHeight-u.bottom,V=u.top,le=W+8,ie=y<le&&V>y?"top":"bottom";se({top:ie==="bottom"?u.bottom+window.scrollY+4:u.top+window.scrollY-le,left:u.left+window.scrollX,width:u.width,placement:ie})};return e(),window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[p,W]);let K=p&&T!==null;(0,r.useEffect)(()=>{K&&i&&ne.current?.focus()},[K,i]),(0,r.useEffect)(()=>{let e=Y.current;if(!(!K||!e))return(0,de.registerFloatingLayer)(e,()=>v.current)},[K]),(0,r.useEffect)(()=>{if(a>=0){let e=re.current[a];e&&typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest"})}},[a]);let _=L!==""&&L!==void 0,Ce=B&&_&&!g&&!m&&!I,ae=!g&&!m,Se=w("w-full flex items-center justify-between rounded-md transition-colors","text-gray-900 dark:text-gray-100",P[k].trigger,ce[R].trigger,!D&&ae&&ce[R].focus,D&&"border-red-500 dark:border-red-400 focus:ring-2 focus:ring-red-500 focus:border-red-500",g&&"opacity-50 cursor-not-allowed bg-gray-50 dark:bg-gray-900",m&&"cursor-default",!g&&!m&&"cursor-pointer",ve);return(0,n.jsxs)("div",{className:w("flex flex-col gap-1",he),children:[E?(0,n.jsxs)("label",{id:U,htmlFor:ee,className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:[E,Z?(0,n.jsx)("span",{className:"text-red-500 ml-0.5","aria-hidden":"true",children:"*"}):null]}):null,Q?(0,n.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:Q}):null,(0,n.jsxs)("button",{ref:v,id:ee,type:"button",role:"combobox","aria-expanded":p,"aria-haspopup":"listbox","aria-controls":p?te:void 0,"aria-labelledby":E?U:void 0,"aria-required":Z||void 0,"aria-invalid":D?!0:void 0,"aria-activedescendant":p&&a>=0?`${S}-option-${a}`:void 0,disabled:g,className:Se,onClick:ae?Le:void 0,onKeyDown:Ne,children:[(0,n.jsxs)("span",{className:w("flex items-center gap-2 min-w-0 flex-1 truncate",!_&&"text-gray-400 dark:text-gray-500"),children:[H?.icon?(0,n.jsx)("span",{className:"flex shrink-0 items-center",children:H.icon}):null,(0,n.jsx)("span",{className:"truncate",children:_&&H?H.label:we})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1 shrink-0",children:[I?(0,n.jsx)("span",{className:"text-gray-400",children:Be}):null,Ce?(0,n.jsx)("span",{role:"button",tabIndex:-1,"aria-label":ge??C.selectClear,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 p-0.5 rounded transition-colors",onClick:Ee,onMouseDown:e=>e.preventDefault(),children:Ve}):null,(0,n.jsx)("span",{className:w("text-gray-400 transition-transform duration-200",p&&"rotate-180"),children:Ke})]})]}),D?(0,n.jsx)("p",{role:"alert",className:"text-xs text-red-500 dark:text-red-400",children:D}):X?(0,n.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:X}):null,J?(0,n.jsx)("input",{type:"hidden",name:J,value:L??""}):null,p&&T?(0,ue.createPortal)((0,n.jsxs)("div",{ref:Y,role:"listbox",id:te,"aria-labelledby":E?U:void 0,className:w("fixed z-50 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700","rounded-md shadow-lg overflow-hidden","animate-in fade-in-0 zoom-in-95",P[k].content,xe),style:{top:T.top,left:T.left,width:T.width,position:"absolute"},onKeyDown:Ie,children:[i?(0,n.jsx)("div",{className:"border-b border-gray-200 dark:border-gray-700",children:(0,n.jsx)("input",{ref:ne,type:"text",role:"searchbox","aria-label":be??C.selectSearch,className:w(P[k].searchInput,"w-full outline-none bg-transparent text-gray-900 dark:text-gray-100","placeholder:text-gray-400 dark:placeholder:text-gray-500"),placeholder:me??C.selectSearchPlaceholder,value:z,onChange:De})}):null,(0,n.jsx)("div",{className:"overflow-y-auto",style:{maxHeight:W},children:d.length===0?(0,n.jsx)("div",{className:w(P[k].option,"text-gray-500 dark:text-gray-400 text-center py-4"),children:ke}):d.map((e,t)=>(0,n.jsx)(Ue,{option:e,isSelected:e.value===L,isHighlighted:t===a,isDisabled:I||x.has(e.value),sizeKey:k,optionId:`${S}-option-${t}`,onClick:N,onMouseEnter:f,index:t,ref:u=>{re.current[t]=u}},e.value))})]}),document.body):null]})}0&&(module.exports={Select});
|