@synertech/ui 0.55.0 → 0.56.1
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 +66 -3
- package/README.md +55 -187
- package/dist/components/accordion/Accordion.cjs +1 -1
- package/dist/components/accordion/Accordion.js +1 -1
- package/dist/components/area-chart/AreaChart.cjs +1 -1
- package/dist/components/area-chart/AreaChart.js +1 -1
- package/dist/components/chart/ChartExportButton.cjs +1 -1
- package/dist/components/chart/ChartExportButton.js +1 -1
- package/dist/components/datagrid/ActiveFilters.cjs +1 -0
- package/dist/components/datagrid/ActiveFilters.js +1 -0
- package/dist/components/datagrid/BulkActionsBar.cjs +1 -0
- package/dist/components/datagrid/BulkActionsBar.js +1 -0
- package/dist/components/datagrid/ColumnToggle.cjs +1 -0
- package/dist/components/datagrid/ColumnToggle.js +1 -0
- package/dist/components/datagrid/DataGrid.cjs +1 -1
- package/dist/components/datagrid/DataGrid.js +1 -1
- package/dist/components/datagrid/DataGridPagination.cjs +1 -0
- package/dist/components/datagrid/DataGridPagination.js +1 -0
- package/dist/components/datagrid/EditableCell.cjs +1 -0
- package/dist/components/datagrid/EditableCell.js +1 -0
- package/dist/components/datagrid/FilterPopover.cjs +1 -0
- package/dist/components/datagrid/FilterPopover.js +1 -0
- package/dist/components/datagrid/export.cjs +1 -0
- package/dist/components/datagrid/export.js +1 -0
- package/dist/components/datagrid/icons.cjs +1 -0
- package/dist/components/datagrid/icons.js +1 -0
- package/dist/components/datagrid/index.cjs +1 -1
- package/dist/components/datagrid/types.cjs +1 -0
- package/dist/components/datagrid/types.js +0 -0
- package/dist/components/datagrid/utils.cjs +1 -0
- package/dist/components/datagrid/utils.js +1 -0
- package/dist/components/dropdown/DropdownContent.cjs +1 -1
- package/dist/components/dropdown/DropdownContent.js +1 -1
- package/dist/components/dropdown/DropdownSubMenu.cjs +1 -1
- package/dist/components/dropdown/DropdownSubMenu.js +1 -1
- package/dist/components/dropdown/hooks/usePositioning.cjs +1 -1
- package/dist/components/dropdown/hooks/usePositioning.js +1 -1
- package/dist/components/form/mention-input/MentionInput.cjs +5 -5
- package/dist/components/form/mention-input/MentionInput.js +5 -5
- package/dist/components/help-button/HelpButton.cjs +2 -2
- package/dist/components/help-button/HelpButton.js +2 -2
- package/dist/components/indicator/Indicator.cjs +1 -1
- package/dist/components/indicator/Indicator.js +1 -1
- package/dist/components/line-chart/LineChart.cjs +1 -1
- package/dist/components/line-chart/LineChart.js +1 -1
- package/dist/components/progress-bar/ProgressBar.cjs +1 -1
- package/dist/components/progress-bar/ProgressBar.js +1 -1
- package/dist/components/schema-editor/SchemaEditor.cjs +1 -1
- package/dist/components/schema-editor/SchemaEditor.js +1 -1
- package/dist/components/select/Select.cjs +1 -1
- package/dist/components/select/Select.js +1 -1
- package/dist/components/skeleton/Skeleton.cjs +1 -1
- package/dist/components/skeleton/Skeleton.js +1 -1
- package/dist/components/workflow-editor/WorkflowEditor.cjs +1 -1
- package/dist/components/workflow-editor/WorkflowEditor.js +1 -1
- package/dist/index.d.cts +158 -8
- package/dist/index.d.ts +158 -8
- package/dist/lib/ui-labels.cjs +1 -1
- package/dist/lib/ui-labels.js +1 -1
- package/dist/styles-no-preflight.css +935 -891
- package/dist/styles.css +935 -891
- package/package.json +26 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var Te=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var ze=Object.getOwnPropertyNames;var Fe=Object.prototype.hasOwnProperty;var Ye=(l,s)=>{for(var n in s)Te(l,n,{get:s[n],enumerable:!0})},qe=(l,s,n,a)=>{if(s&&typeof s=="object"||typeof s=="function")for(let c of ze(s))!Fe.call(l,c)&&c!==n&&Te(l,c,{get:()=>s[c],enumerable:!(a=je(s,c))||a.enumerable});return l};var Je=l=>qe(Te({},"__esModule",{value:!0}),l);var it={};Ye(it,{LineChart:()=>st,resetLineChartWarnings:()=>nt});module.exports=Je(it);var u=require("react"),Ne=require("../../lib/cn.cjs"),pe=require("../../lib/i18n.cjs"),Q=require("../chart/ChartAnnotations.cjs"),Be=require("../chart/ChartAxis.cjs"),G=require("../chart/ChartBrush.cjs"),Me=require("../chart/ChartContainer.cjs"),De=require("../chart/ChartGrid.cjs"),Ke=require("../chart/ChartLegend.cjs"),Xe=require("../chart/ChartSync.cjs"),Ge=require("../chart/ChartTableView.cjs"),ye=require("../chart/ChartTooltip.cjs"),P=require("../chart/palette.cjs"),m=require("../chart/utils/cartesian.cjs"),Z=require("../chart/utils/data.cjs"),Ce=require("../chart/utils/decimate.cjs"),O=require("../chart/utils/format.cjs"),be=require("../chart/utils/keyboard.cjs"),M=require("../chart/utils/path.cjs"),E=require("../chart/utils/scales.cjs"),Oe=require("../chart/utils/ticks.cjs"),ee=require("../chart/utils/timestamp.cjs"),_e=require("../chart/utils/touch.cjs"),o=require("react/jsx-runtime"),Qe=6,Ze=24,et=10,tt=10,He=!1;function nt(){He=!1}function rt(l,s){let n=(0,E.toKey)(s),a=l.findIndex(C=>(0,E.toKey)(C)===n);if(a>=0)return a;let c=(0,ee.toTimestamp)(s);return c===null?-1:l.findIndex(C=>{let b=(0,ee.toTimestamp)(C);return b!==null&&b>=c})}var ot=(0,u.memo)(function({lines:s,showMarkers:n}){return(0,o.jsx)("g",{children:s.map(a=>(0,o.jsxs)("g",{children:[a.solid?(0,o.jsx)("path",{d:a.solid,fill:"none",stroke:a.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}):null,a.dashed?(0,o.jsx)("path",{d:a.dashed,fill:"none",stroke:a.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"5 4"}):null,(n?a.markers:a.isolated).map((c,C)=>(0,o.jsx)("circle",{cx:c.x,cy:c.y,r:3,fill:a.color,strokeWidth:2,stroke:P.CHART_SURFACE_COLOR},C))]},a.key))})});function at({width:l,height:s,data:n,resolvedSeries:a,x:c,y:C,grid:b,size:te,curve:w,forecastFrom:T,forecastLabel:B,markers:H,connectNulls:W,referenceLines:_,annotations:L,annotationsLabel:xe,overlay:ve,maxPoints:I,brush:ne,onBrush:re,brushLabel:ke,syncEnabled:Pe,margin:oe,tooltip:N,onPointClick:S,plotLabel:Le,formatValue:$,formatExact:ae,formatX:D,locale:se}){let[U,j]=(0,u.useState)(null),d=U!==null&&U<n.length?U:null,[Se,we]=(0,u.useState)(null),Re=(0,Xe.useChartSync)(),f=Pe?Re:null,e=(0,u.useMemo)(()=>{let t=a.filter(p=>!p.hidden),r=(0,m.buildCartesianGeometry)({locale:se,width:l,height:s,data:n,x:c,y:C,bounds:(0,m.widenBounds)((0,Oe.extent)((0,Z.collectAllValues)(n,t.map(p=>p.key))),(0,m.annotationValues)(n,c.key,_,L)),margin:oe,placement:"point",formatValue:$,formatX:D,extraTop:B?et:0}),h=r.categoryCenters,g=r.valueScale,V=T===void 0?-1:rt(r.xValues,T);T!==void 0&&V<0&&n.length>0&&!He&&(He=!0,console.warn(`[@synertech/ui] LineChart was given \`forecastFrom\` = ${String(T)}, which no row is on or after. Nothing is drawn as a forecast: pass the x value of the first projected row, in the form the rows carry it.`));let me=t.map(p=>{let Y=n.map((ge,Ue)=>{let Ee=(0,Z.readNumber)(ge,p.key);return{x:h[Ue],y:Ee===null?Number.NaN:g(Ee),defined:Ee!==null}}),We={connectNulls:W},fe=V>=0,Ae=ge=>I&&I>0?(0,Ce.decimatePath)(ge,I):ge,q=p.dashed?[]:Ae(fe?Y.slice(0,V+1):Y),J=p.dashed?Ae(Y):fe?Ae(Y.slice(V)):[];I||(0,Ce.warnPointBudget)("LineChart",Y.length);let $e=q[q.length-1],Ie=p.dashed?J:fe?[...q,...J[0]===$e?J.slice(1):J]:q;return{key:p.key,color:p.color,solid:p.dashed?"":(0,M.buildLinePath)(q,w,We),dashed:p.dashed||fe?(0,M.buildLinePath)(J,w,We):"",markers:Ie.filter(M.isDrawable),isolated:(0,M.isolatedPoints)(Ie,W)}}),A=n.length>1?r.innerWidth/(n.length-1):0;return{visible:t,locate:(0,m.createCategoryLocator)(r),span:(0,m.createSpanLocator)(r),plot:(0,m.createPlotContext)({geometry:r,width:l,height:s,data:n,series:t,formatValue:$,formatX:D}),xValues:r.xValues,xPositions:h,xTicks:r.categoryTicks,yTicks:r.valueTicks,yScale:g,innerWidth:r.innerWidth,innerHeight:r.innerHeight,margin:r.margin,lines:me,forecastIndex:V,showMarkers:H==="always"||H==="auto"&&A>=Ze&&n.length>1}},[se,n,a,c,C,l,s,oe,w,W,T,B,H,I,_,L,$,D]),z=(0,u.useCallback)(t=>e.visible.map(r=>{let h=(0,Z.readNumber)(n[t],r.key);return{seriesKey:r.key,seriesLabel:(0,P.getSeriesLabel)(r),color:r.color,value:h,formattedValue:h===null?"\u2014":ae(h),datum:n[t]}}),[n,e.visible,ae]),ie=f?f.brush:Se,x=(0,u.useCallback)(t=>{we(t),f?.setBrush(t),re?.(t)},[f,re]),y=(0,G.useChartBrush)({enabled:ne,active:ie!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:x}),le=(0,u.useCallback)(t=>{if(y.onPointerMove(t),N===!1||n.length===0)return;let r=t.currentTarget.getBoundingClientRect(),h=t.clientX-r.left-e.margin.left,g=(0,E.nearestIndex)(e.xPositions,h);j(g>=0?g:null),f?.setHovered(g>=0?e.xValues[g]:null)},[y,N,n.length,e.margin.left,e.xPositions,e.xValues,f]),ue=(0,u.useCallback)(()=>{j(null),f?.setHovered(null)},[f]),v=(0,u.useCallback)((t,r)=>{if(!S)return;let h=z(t),g=h.filter(A=>A.value!==null),V=A=>r===null?0:Math.abs(e.yScale(A.value)-r.y),me=g.length>0?g.reduce((A,p)=>V(p)<V(A)?p:A):h[0];me&&S({...me,index:t,x:e.xValues[t]})},[S,z,e.yScale,e.xValues]),Ve=(0,u.useCallback)(t=>{if(n.length===0)return;let r=S&&d!==null&&e.visible.length>0;if((0,be.pressChartMark)(t,r?()=>v(d,null):null))return;let h=y.onKeyDown(t,d),g=(0,be.chartCursorTarget)(t.key,d,n.length,"x");if(g===void 0){h&&t.preventDefault();return}t.preventDefault(),j(g),f?.setHovered(g===null?null:e.xValues[g])},[n.length,d,y,f,e.xValues,e.visible.length,S,v]),ce=(0,u.useCallback)(t=>{if(y.consumedClick()||!S||n.length===0)return;let r=(0,m.plotPointer)(t,e),h=d??(r===null?-1:(0,E.nearestIndex)(e.xPositions,r.x));h<0||v(h,r)},[y,S,n.length,e,d,v]),he=d!==null||f===null||f.hovered===null?null:(()=>{let t=(0,E.toKey)(f.hovered),r=e.xValues.findIndex(h=>(0,E.toKey)(h)===t);return r<0?null:r})(),R=d??he,F=R===null?null:z(R),K=(F??[]).filter(t=>t.value!==null),de=y.dragging??ie,i=de?(0,G.locateBrush)(de,e.xValues,e.xPositions,e.locate):null,X=(0,m.splitOverlay)(ve),k=d===null||F===null?null:{x:e.xValues[d],xLabel:D(e.xValues[d],d),index:d,points:F};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("svg",{width:l,height:s,role:"img","aria-label":Le??[e.visible.map(t=>(0,P.getSeriesLabel)(t)).join(", "),(0,Q.describeAnnotations)(L,xe)].filter(Boolean).join(". "),tabIndex:0,className:(0,Ne.cn)(_e.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",ne&&"select-none"),onPointerDown:y.onPointerDown,onPointerMove:le,onPointerUp:y.onPointerUp,onPointerCancel:y.onPointerUp,onPointerLeave:ue,onKeyDown:Ve,onBlur:ue,onClick:ce,children:[(0,o.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,o.jsx)(De.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:b==="y"||b==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:b==="x"||b==="both"?e.xTicks.map(t=>t.offset):void 0}),L?(0,o.jsx)(Q.ChartAnnotationLayer,{layer:"under",annotations:L,xAt:e.locate,spanAt:e.span,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,i?(0,o.jsx)(G.ChartBrushLayer,{from:i.from,to:i.to,width:e.innerWidth,height:e.innerHeight,live:y.dragging!==null,label:ke,minSpan:Qe}):null,X.under?.(e.plot),_?.map(t=>{let r=e.yScale(t.value),h=r<tt?r+12:r-4;return(0,o.jsxs)("g",{children:[(0,o.jsx)("line",{x1:0,y1:r,x2:e.innerWidth,y2:r,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,o.jsx)("text",{x:e.innerWidth,y:h,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),e.forecastIndex>=0?(0,o.jsxs)("g",{children:[(0,o.jsx)("line",{x1:e.xPositions[e.forecastIndex],y1:0,x2:e.xPositions[e.forecastIndex],y2:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,strokeDasharray:"3 3"}),B?(0,o.jsx)("text",{x:e.xPositions[e.forecastIndex]+4,y:-2,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:B}):null]}):null,(0,o.jsx)(ot,{lines:e.lines,showMarkers:e.showMarkers}),L?(0,o.jsx)(Q.ChartAnnotationLayer,{annotations:L,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,X.over?.(e.plot),R!==null?(0,o.jsxs)("g",{"aria-hidden":"true",children:[(0,o.jsx)("line",{x1:e.xPositions[R],y1:0,x2:e.xPositions[R],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:d===null?"3 3":void 0}),K.map(t=>(0,o.jsx)("circle",{cx:e.xPositions[R],cy:e.yScale(t.value),r:4,fill:t.color,strokeWidth:2,stroke:P.CHART_SURFACE_COLOR},t.seriesKey))]}):null]}),(0,o.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:c.hidden?null:(0,o.jsx)(Be.ChartAxis,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:c.label,size:te})}),(0,o.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:C?.hidden?null:(0,o.jsx)(Be.ChartAxis,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:C?.label,size:te})})]}),k&&N!==!1?(0,o.jsx)(ye.ChartTooltip,{x:e.margin.left+e.xPositions[k.index],y:e.margin.top+(K.length>0?Math.min(...K.map(t=>e.yScale(t.value))):e.innerHeight/2),containerWidth:l,children:typeof N=="function"?N(k):(0,o.jsx)(ye.ChartTooltipContent,{title:k.xLabel,points:k.points})}):null]})}function st({data:l,series:s,x:n,y:a,height:c=240,width:C,size:b="md",grid:te="y",legend:w,tooltip:T=!0,tableView:B=!1,emphasis:H,title:W,description:_,loading:L=!1,emptyState:xe,error:ve=!1,errorState:I,onRetry:ne,actions:re,onPointClick:ke,curve:Pe="monotone",forecastFrom:oe,forecastLabel:N,markers:S="auto",connectNulls:Le=!1,referenceLines:$,annotations:ae,overlay:D,legendToggle:se=!0,maxPoints:U,brush:j=!1,onBrush:d,brushLabel:Se,sync:we=!0,margin:Re,locale:f,plotLabel:e,className:z,...ie}){let x=(0,pe.useUILocale)(f),y=(0,pe.useUILabels)(),[le,ue]=(0,u.useState)(()=>new Set),v=(0,u.useMemo)(()=>s.map((i,X)=>({...i,hidden:i.hidden||le.has(i.key),color:(0,P.resolveSeriesColor)(i,X,H)})),[s,le,H]),Ve=(0,u.useMemo)(()=>a?.format??(i=>(0,O.formatAuto)(i,x)),[a?.format,x]),ce=(0,u.useMemo)(()=>a?.format??(i=>(0,O.formatExact)(i,x)),[a?.format,x]),he=(0,u.useMemo)(()=>n.format??(i=>n.scale==="time"?(0,ee.formatTimeValue)(i,x):(0,O.formatXValue)(i,x)),[n.format,n.scale,x]),R=(0,u.useCallback)(i=>{ue(X=>{let k=new Set(X);return k.has(i)?k.delete(i):k.add(i),k})},[]),F=w===void 0?s.length>=2:w!==!1,K=typeof w=="string"?w:"bottom",de=v.filter(i=>!i.hidden).length;return(0,o.jsx)(Me.ChartContainer,{title:W,description:_,height:c,width:C,size:b,loading:L,empty:l.length===0||de===0,emptyState:xe,error:ve,errorState:I,onRetry:ne,actions:re,exportSource:{data:l,series:v,xKey:n.key,xLabel:n.label??n.key,formatX:n.format},tableView:B,legendPosition:K,legend:F?(0,o.jsx)(Ke.ChartLegend,{items:(0,P.toLegendItems)(v,H),position:K,marker:"line",size:b,onToggle:se?R:void 0}):void 0,table:B?(0,o.jsx)(Ge.ChartTableView,{data:l,series:v,xKey:n.key,xLabel:n.label??n.key,formatX:he,formatValue:ce,caption:typeof W=="string"?W:void 0}):void 0,className:z,...ie,children:({width:i})=>(0,o.jsx)(at,{locale:x,width:i,height:c,data:l,resolvedSeries:v,x:n,y:a,grid:te,size:b,curve:Pe,forecastFrom:oe,forecastLabel:N,markers:S,connectNulls:Le,referenceLines:$,annotations:ae,annotationsLabel:y.chartAnnotations,overlay:D,maxPoints:U,brush:j,onBrush:d,brushLabel:Se??y.chartBrush,syncEnabled:we,margin:Re,tooltip:T,onPointClick:ke,plotLabel:e,formatValue:Ve,formatExact:ce,formatX:he})})}0&&(module.exports={LineChart,resetLineChartWarnings});
|
|
1
|
+
"use strict";"use client";var Te=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var ze=Object.getOwnPropertyNames;var Fe=Object.prototype.hasOwnProperty;var Ye=(l,s)=>{for(var n in s)Te(l,n,{get:s[n],enumerable:!0})},qe=(l,s,n,a)=>{if(s&&typeof s=="object"||typeof s=="function")for(let c of ze(s))!Fe.call(l,c)&&c!==n&&Te(l,c,{get:()=>s[c],enumerable:!(a=je(s,c))||a.enumerable});return l};var Je=l=>qe(Te({},"__esModule",{value:!0}),l);var it={};Ye(it,{LineChart:()=>st,resetLineChartWarnings:()=>nt});module.exports=Je(it);var u=require("react"),Ne=require("../../lib/cn.cjs"),pe=require("../../lib/i18n.cjs"),Q=require("../chart/ChartAnnotations.cjs"),Be=require("../chart/ChartAxis.cjs"),G=require("../chart/ChartBrush.cjs"),Me=require("../chart/ChartContainer.cjs"),De=require("../chart/ChartGrid.cjs"),Ke=require("../chart/ChartLegend.cjs"),Xe=require("../chart/ChartSync.cjs"),Ge=require("../chart/ChartTableView.cjs"),ye=require("../chart/ChartTooltip.cjs"),P=require("../chart/palette.cjs"),m=require("../chart/utils/cartesian.cjs"),Z=require("../chart/utils/data.cjs"),Ce=require("../chart/utils/decimate.cjs"),O=require("../chart/utils/format.cjs"),be=require("../chart/utils/keyboard.cjs"),M=require("../chart/utils/path.cjs"),E=require("../chart/utils/scales.cjs"),Oe=require("../chart/utils/ticks.cjs"),ee=require("../chart/utils/timestamp.cjs"),_e=require("../chart/utils/touch.cjs"),o=require("react/jsx-runtime"),Qe=6,Ze=24,et=10,tt=10,He=!1;function nt(){He=!1}function rt(l,s){let n=(0,E.toKey)(s),a=l.findIndex(C=>(0,E.toKey)(C)===n);if(a>=0)return a;let c=(0,ee.toTimestamp)(s);return c===null?-1:l.findIndex(C=>{let b=(0,ee.toTimestamp)(C);return b!==null&&b>=c})}var ot=(0,u.memo)(function({lines:s,showMarkers:n}){return(0,o.jsx)("g",{children:s.map(a=>(0,o.jsxs)("g",{children:[a.solid?(0,o.jsx)("path",{d:a.solid,fill:"none",stroke:a.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}):null,a.dashed?(0,o.jsx)("path",{d:a.dashed,fill:"none",stroke:a.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"5 4"}):null,(n?a.markers:a.isolated).map((c,C)=>(0,o.jsx)("circle",{cx:c.x,cy:c.y,r:3,fill:a.color,strokeWidth:2,stroke:P.CHART_SURFACE_COLOR},C))]},a.key))})});function at({width:l,height:s,data:n,resolvedSeries:a,x:c,y:C,grid:b,size:te,curve:w,forecastFrom:T,forecastLabel:B,markers:H,connectNulls:W,referenceLines:_,annotations:L,annotationsLabel:xe,overlay:ve,maxPoints:I,brush:ne,onBrush:re,brushLabel:ke,syncEnabled:Pe,margin:oe,tooltip:N,onPointClick:S,plotLabel:Le,formatValue:$,formatExact:ae,formatX:D,locale:se}){let[U,j]=(0,u.useState)(null),d=U!==null&&U<n.length?U:null,[Se,we]=(0,u.useState)(null),Re=(0,Xe.useChartSync)(),f=Pe?Re:null,e=(0,u.useMemo)(()=>{let t=a.filter(p=>!p.hidden),r=(0,m.buildCartesianGeometry)({locale:se,width:l,height:s,data:n,x:c,y:C,bounds:(0,m.widenBounds)((0,Oe.extent)((0,Z.collectAllValues)(n,t.map(p=>p.key))),(0,m.annotationValues)(n,c.key,_,L)),margin:oe,placement:"point",formatValue:$,formatX:D,extraTop:B?et:0}),h=r.categoryCenters,g=r.valueScale,V=T===void 0?-1:rt(r.xValues,T);T!==void 0&&V<0&&n.length>0&&!He&&(He=!0,console.warn(`[@synertech/ui] LineChart was given \`forecastFrom\` = ${String(T)}, which no row is on or after. Nothing is drawn as a forecast: pass the x value of the first projected row, in the form the rows carry it.`));let me=t.map(p=>{let Y=n.map((ge,Ue)=>{let Ee=(0,Z.readNumber)(ge,p.key);return{x:h[Ue],y:Ee===null?Number.NaN:g(Ee),defined:Ee!==null}}),We={connectNulls:W},fe=V>=0,Ae=ge=>I&&I>0?(0,Ce.decimatePath)(ge,I):ge,q=p.dashed?[]:Ae(fe?Y.slice(0,V+1):Y),J=p.dashed?Ae(Y):fe?Ae(Y.slice(V)):[];I||(0,Ce.warnPointBudget)("LineChart",Y.length);let $e=q[q.length-1],Ie=p.dashed?J:fe?[...q,...J[0]===$e?J.slice(1):J]:q;return{key:p.key,color:p.color,solid:p.dashed?"":(0,M.buildLinePath)(q,w,We),dashed:p.dashed||fe?(0,M.buildLinePath)(J,w,We):"",markers:Ie.filter(M.isDrawable),isolated:(0,M.isolatedPoints)(Ie,W)}}),A=n.length>1?r.innerWidth/(n.length-1):0;return{visible:t,locate:(0,m.createCategoryLocator)(r),span:(0,m.createSpanLocator)(r),plot:(0,m.createPlotContext)({geometry:r,width:l,height:s,data:n,series:t,formatValue:$,formatX:D}),xValues:r.xValues,xPositions:h,xTicks:r.categoryTicks,yTicks:r.valueTicks,yScale:g,innerWidth:r.innerWidth,innerHeight:r.innerHeight,margin:r.margin,lines:me,forecastIndex:V,showMarkers:H==="always"||H==="auto"&&A>=Ze&&n.length>1}},[se,n,a,c,C,l,s,oe,w,W,T,B,H,I,_,L,$,D]),z=(0,u.useCallback)(t=>e.visible.map(r=>{let h=(0,Z.readNumber)(n[t],r.key);return{seriesKey:r.key,seriesLabel:(0,P.getSeriesLabel)(r),color:r.color,value:h,formattedValue:h===null?"\u2014":ae(h),datum:n[t]}}),[n,e.visible,ae]),ie=f?f.brush:Se,x=(0,u.useCallback)(t=>{we(t),f?.setBrush(t),re?.(t)},[f,re]),y=(0,G.useChartBrush)({enabled:ne,active:ie!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:x}),le=(0,u.useCallback)(t=>{if(y.onPointerMove(t),N===!1||n.length===0)return;let r=t.currentTarget.getBoundingClientRect(),h=t.clientX-r.left-e.margin.left,g=(0,E.nearestIndex)(e.xPositions,h);j(g>=0?g:null),f?.setHovered(g>=0?e.xValues[g]:null)},[y,N,n.length,e.margin.left,e.xPositions,e.xValues,f]),ue=(0,u.useCallback)(()=>{j(null),f?.setHovered(null)},[f]),v=(0,u.useCallback)((t,r)=>{if(!S)return;let h=z(t),g=h.filter(A=>A.value!==null),V=A=>r===null?0:Math.abs(e.yScale(A.value)-r.y),me=g.length>0?g.reduce((A,p)=>V(p)<V(A)?p:A):h[0];me&&S({...me,index:t,x:e.xValues[t]})},[S,z,e]),Ve=(0,u.useCallback)(t=>{if(n.length===0)return;let r=S&&d!==null&&e.visible.length>0;if((0,be.pressChartMark)(t,r?()=>v(d,null):null))return;let h=y.onKeyDown(t,d),g=(0,be.chartCursorTarget)(t.key,d,n.length,"x");if(g===void 0){h&&t.preventDefault();return}t.preventDefault(),j(g),f?.setHovered(g===null?null:e.xValues[g])},[n.length,d,y,f,e.xValues,e.visible.length,S,v]),ce=(0,u.useCallback)(t=>{if(y.consumedClick()||!S||n.length===0)return;let r=(0,m.plotPointer)(t,e),h=d??(r===null?-1:(0,E.nearestIndex)(e.xPositions,r.x));h<0||v(h,r)},[y,S,n.length,e,d,v]),he=d!==null||f===null||f.hovered===null?null:(()=>{let t=(0,E.toKey)(f.hovered),r=e.xValues.findIndex(h=>(0,E.toKey)(h)===t);return r<0?null:r})(),R=d??he,F=R===null?null:z(R),K=(F??[]).filter(t=>t.value!==null),de=y.dragging??ie,i=de?(0,G.locateBrush)(de,e.xValues,e.xPositions,e.locate):null,X=(0,m.splitOverlay)(ve),k=d===null||F===null?null:{x:e.xValues[d],xLabel:D(e.xValues[d],d),index:d,points:F};return(0,o.jsxs)(o.Fragment,{children:[(0,o.jsxs)("svg",{width:l,height:s,role:"img","aria-label":Le??[e.visible.map(t=>(0,P.getSeriesLabel)(t)).join(", "),(0,Q.describeAnnotations)(L,xe)].filter(Boolean).join(". "),tabIndex:0,className:(0,Ne.cn)(_e.CHART_TOUCH,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",ne&&"select-none"),onPointerDown:y.onPointerDown,onPointerMove:le,onPointerUp:y.onPointerUp,onPointerCancel:y.onPointerUp,onPointerLeave:ue,onKeyDown:Ve,onBlur:ue,onClick:ce,children:[(0,o.jsxs)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[(0,o.jsx)(De.ChartGrid,{width:e.innerWidth,height:e.innerHeight,horizontal:b==="y"||b==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:b==="x"||b==="both"?e.xTicks.map(t=>t.offset):void 0}),L?(0,o.jsx)(Q.ChartAnnotationLayer,{layer:"under",annotations:L,xAt:e.locate,spanAt:e.span,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,i?(0,o.jsx)(G.ChartBrushLayer,{from:i.from,to:i.to,width:e.innerWidth,height:e.innerHeight,live:y.dragging!==null,label:ke,minSpan:Qe}):null,X.under?.(e.plot),_?.map(t=>{let r=e.yScale(t.value),h=r<tt?r+12:r-4;return(0,o.jsxs)("g",{children:[(0,o.jsx)("line",{x1:0,y1:r,x2:e.innerWidth,y2:r,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?(0,o.jsx)("text",{x:e.innerWidth,y:h,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),e.forecastIndex>=0?(0,o.jsxs)("g",{children:[(0,o.jsx)("line",{x1:e.xPositions[e.forecastIndex],y1:0,x2:e.xPositions[e.forecastIndex],y2:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,strokeDasharray:"3 3"}),B?(0,o.jsx)("text",{x:e.xPositions[e.forecastIndex]+4,y:-2,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:B}):null]}):null,(0,o.jsx)(ot,{lines:e.lines,showMarkers:e.showMarkers}),L?(0,o.jsx)(Q.ChartAnnotationLayer,{annotations:L,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,X.over?.(e.plot),R!==null?(0,o.jsxs)("g",{"aria-hidden":"true",children:[(0,o.jsx)("line",{x1:e.xPositions[R],y1:0,x2:e.xPositions[R],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:d===null?"3 3":void 0}),K.map(t=>(0,o.jsx)("circle",{cx:e.xPositions[R],cy:e.yScale(t.value),r:4,fill:t.color,strokeWidth:2,stroke:P.CHART_SURFACE_COLOR},t.seriesKey))]}):null]}),(0,o.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:c.hidden?null:(0,o.jsx)(Be.ChartAxis,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:c.label,size:te})}),(0,o.jsx)("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:C?.hidden?null:(0,o.jsx)(Be.ChartAxis,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:C?.label,size:te})})]}),k&&N!==!1?(0,o.jsx)(ye.ChartTooltip,{x:e.margin.left+e.xPositions[k.index],y:e.margin.top+(K.length>0?Math.min(...K.map(t=>e.yScale(t.value))):e.innerHeight/2),containerWidth:l,children:typeof N=="function"?N(k):(0,o.jsx)(ye.ChartTooltipContent,{title:k.xLabel,points:k.points})}):null]})}function st({data:l,series:s,x:n,y:a,height:c=240,width:C,size:b="md",grid:te="y",legend:w,tooltip:T=!0,tableView:B=!1,emphasis:H,title:W,description:_,loading:L=!1,emptyState:xe,error:ve=!1,errorState:I,onRetry:ne,actions:re,onPointClick:ke,curve:Pe="monotone",forecastFrom:oe,forecastLabel:N,markers:S="auto",connectNulls:Le=!1,referenceLines:$,annotations:ae,overlay:D,legendToggle:se=!0,maxPoints:U,brush:j=!1,onBrush:d,brushLabel:Se,sync:we=!0,margin:Re,locale:f,plotLabel:e,className:z,...ie}){let x=(0,pe.useUILocale)(f),y=(0,pe.useUILabels)(),[le,ue]=(0,u.useState)(()=>new Set),v=(0,u.useMemo)(()=>s.map((i,X)=>({...i,hidden:i.hidden||le.has(i.key),color:(0,P.resolveSeriesColor)(i,X,H)})),[s,le,H]),Ve=(0,u.useMemo)(()=>a?.format??(i=>(0,O.formatAuto)(i,x)),[a?.format,x]),ce=(0,u.useMemo)(()=>a?.format??(i=>(0,O.formatExact)(i,x)),[a?.format,x]),he=(0,u.useMemo)(()=>n.format??(i=>n.scale==="time"?(0,ee.formatTimeValue)(i,x):(0,O.formatXValue)(i,x)),[n.format,n.scale,x]),R=(0,u.useCallback)(i=>{ue(X=>{let k=new Set(X);return k.has(i)?k.delete(i):k.add(i),k})},[]),F=w===void 0?s.length>=2:w!==!1,K=typeof w=="string"?w:"bottom",de=v.filter(i=>!i.hidden).length;return(0,o.jsx)(Me.ChartContainer,{title:W,description:_,height:c,width:C,size:b,loading:L,empty:l.length===0||de===0,emptyState:xe,error:ve,errorState:I,onRetry:ne,actions:re,exportSource:{data:l,series:v,xKey:n.key,xLabel:n.label??n.key,formatX:n.format},tableView:B,legendPosition:K,legend:F?(0,o.jsx)(Ke.ChartLegend,{items:(0,P.toLegendItems)(v,H),position:K,marker:"line",size:b,onToggle:se?R:void 0}):void 0,table:B?(0,o.jsx)(Ge.ChartTableView,{data:l,series:v,xKey:n.key,xLabel:n.label??n.key,formatX:he,formatValue:ce,caption:typeof W=="string"?W:void 0}):void 0,className:z,...ie,children:({width:i})=>(0,o.jsx)(at,{locale:x,width:i,height:c,data:l,resolvedSeries:v,x:n,y:a,grid:te,size:b,curve:Pe,forecastFrom:oe,forecastLabel:N,markers:S,connectNulls:Le,referenceLines:$,annotations:ae,annotationsLabel:y.chartAnnotations,overlay:D,maxPoints:U,brush:j,onBrush:d,brushLabel:Se??y.chartBrush,syncEnabled:we,margin:Re,tooltip:T,onPointClick:ke,plotLabel:e,formatValue:Ve,formatExact:ce,formatX:he})})}0&&(module.exports={LineChart,resetLineChartWarnings});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{memo as Ie,useCallback as R,useMemo as z,useState as ve}from"react";import{cn as Ne}from"../../lib/cn.js";import{useUILabels as Me,useUILocale as De}from"../../lib/i18n.js";import{ChartAnnotationLayer as Se,describeAnnotations as Ke}from"../chart/ChartAnnotations.js";import{ChartAxis as we}from"../chart/ChartAxis.js";import{ChartBrushLayer as Xe,locateBrush as Ge,useChartBrush as Oe}from"../chart/ChartBrush.js";import{ChartContainer as _e}from"../chart/ChartContainer.js";import{ChartGrid as $e}from"../chart/ChartGrid.js";import{ChartLegend as Ue}from"../chart/ChartLegend.js";import{useChartSync as je}from"../chart/ChartSync.js";import{ChartTableView as ze}from"../chart/ChartTableView.js";import{ChartTooltip as Fe,ChartTooltipContent as Ye}from"../chart/ChartTooltip.js";import{CHART_SURFACE_COLOR as Be,getSeriesLabel as Re,resolveSeriesColor as qe,toLegendItems as Je}from"../chart/palette.js";import{annotationValues as Qe,buildCartesianGeometry as Ze,createCategoryLocator as et,createPlotContext as tt,createSpanLocator as nt,plotPointer as rt,splitOverlay as ot,widenBounds as at}from"../chart/utils/cartesian.js";import{collectAllValues as st,readNumber as Ve}from"../chart/utils/data.js";import{decimatePath as it,warnPointBudget as lt}from"../chart/utils/decimate.js";import{formatAuto as ut,formatExact as ct,formatXValue as ht}from"../chart/utils/format.js";import{chartCursorTarget as dt,pressChartMark as mt}from"../chart/utils/keyboard.js";import{buildLinePath as Ae,isDrawable as ft,isolatedPoints as gt}from"../chart/utils/path.js";import{nearestIndex as Ee,toKey as ue}from"../chart/utils/scales.js";import{extent as pt}from"../chart/utils/ticks.js";import{formatTimeValue as yt,toTimestamp as Te}from"../chart/utils/timestamp.js";import{CHART_TOUCH as bt}from"../chart/utils/touch.js";import{Fragment as wt,jsx as o,jsxs as W}from"react/jsx-runtime";var Ct=6,xt=24,vt=10,kt=10,ke=!1;function qt(){ke=!1}function Pt(d,g){let n=ue(g),s=d.findIndex(p=>ue(p)===n);if(s>=0)return s;let m=Te(g);return m===null?-1:d.findIndex(p=>{let y=Te(p);return y!==null&&y>=m})}var Lt=Ie(function({lines:g,showMarkers:n}){return o("g",{children:g.map(s=>W("g",{children:[s.solid?o("path",{d:s.solid,fill:"none",stroke:s.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}):null,s.dashed?o("path",{d:s.dashed,fill:"none",stroke:s.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"5 4"}):null,(n?s.markers:s.isolated).map((m,p)=>o("circle",{cx:m.x,cy:m.y,r:3,fill:s.color,strokeWidth:2,stroke:Be},p))]},s.key))})});function St({width:d,height:g,data:n,resolvedSeries:s,x:m,y:p,grid:y,size:F,curve:P,forecastFrom:V,forecastLabel:A,markers:E,connectNulls:T,referenceLines:D,annotations:v,annotationsLabel:ce,overlay:he,maxPoints:B,brush:Y,onBrush:q,brushLabel:de,syncEnabled:me,margin:J,tooltip:H,onPointClick:k,plotLabel:fe,formatValue:K,formatExact:Q,formatX:I,locale:Z}){let[X,G]=ve(null),l=X!==null&&X<n.length?X:null,[ge,pe]=ve(null),ye=je(),u=me?ye:null,e=z(()=>{let t=s.filter(h=>!h.hidden),r=Ze({locale:Z,width:d,height:g,data:n,x:m,y:p,bounds:at(pt(st(n,t.map(h=>h.key))),Qe(n,m.key,D,v)),margin:J,placement:"point",formatValue:K,formatX:I,extraTop:A?vt:0}),i=r.categoryCenters,c=r.valueScale,S=V===void 0?-1:Pt(r.xValues,V);V!==void 0&&S<0&&n.length>0&&!ke&&(ke=!0,console.warn(`[@synertech/ui] LineChart was given \`forecastFrom\` = ${String(V)}, which no row is on or after. Nothing is drawn as a forecast: pass the x value of the first projected row, in the form the rows carry it.`));let se=t.map(h=>{let $=n.map((le,We)=>{let xe=Ve(le,h.key);return{x:i[We],y:xe===null?Number.NaN:c(xe),defined:xe!==null}}),Pe={connectNulls:T},ie=S>=0,be=le=>B&&B>0?it(le,B):le,U=h.dashed?[]:be(ie?$.slice(0,S+1):$),j=h.dashed?be($):ie?be($.slice(S)):[];B||lt("LineChart",$.length);let He=U[U.length-1],Le=h.dashed?j:ie?[...U,...j[0]===He?j.slice(1):j]:U;return{key:h.key,color:h.color,solid:h.dashed?"":Ae(U,P,Pe),dashed:h.dashed||ie?Ae(j,P,Pe):"",markers:Le.filter(ft),isolated:gt(Le,T)}}),w=n.length>1?r.innerWidth/(n.length-1):0;return{visible:t,locate:et(r),span:nt(r),plot:tt({geometry:r,width:d,height:g,data:n,series:t,formatValue:K,formatX:I}),xValues:r.xValues,xPositions:i,xTicks:r.categoryTicks,yTicks:r.valueTicks,yScale:c,innerWidth:r.innerWidth,innerHeight:r.innerHeight,margin:r.margin,lines:se,forecastIndex:S,showMarkers:E==="always"||E==="auto"&&w>=xt&&n.length>1}},[Z,n,s,m,p,d,g,J,P,T,V,A,E,B,D,v,K,I]),O=R(t=>e.visible.map(r=>{let i=Ve(n[t],r.key);return{seriesKey:r.key,seriesLabel:Re(r),color:r.color,value:i,formattedValue:i===null?"\u2014":Q(i),datum:n[t]}}),[n,e.visible,Q]),ee=u?u.brush:ge,C=R(t=>{pe(t),u?.setBrush(t),q?.(t)},[u,q]),f=Oe({enabled:Y,active:ee!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:C}),te=R(t=>{if(f.onPointerMove(t),H===!1||n.length===0)return;let r=t.currentTarget.getBoundingClientRect(),i=t.clientX-r.left-e.margin.left,c=Ee(e.xPositions,i);G(c>=0?c:null),u?.setHovered(c>=0?e.xValues[c]:null)},[f,H,n.length,e.margin.left,e.xPositions,e.xValues,u]),ne=R(()=>{G(null),u?.setHovered(null)},[u]),b=R((t,r)=>{if(!k)return;let i=O(t),c=i.filter(w=>w.value!==null),S=w=>r===null?0:Math.abs(e.yScale(w.value)-r.y),se=c.length>0?c.reduce((w,h)=>S(h)<S(w)?h:w):i[0];se&&k({...se,index:t,x:e.xValues[t]})},[k,O,e.yScale,e.xValues]),Ce=R(t=>{if(n.length===0)return;let r=k&&l!==null&&e.visible.length>0;if(mt(t,r?()=>b(l,null):null))return;let i=f.onKeyDown(t,l),c=dt(t.key,l,n.length,"x");if(c===void 0){i&&t.preventDefault();return}t.preventDefault(),G(c),u?.setHovered(c===null?null:e.xValues[c])},[n.length,l,f,u,e.xValues,e.visible.length,k,b]),re=R(t=>{if(f.consumedClick()||!k||n.length===0)return;let r=rt(t,e),i=l??(r===null?-1:Ee(e.xPositions,r.x));i<0||b(i,r)},[f,k,n.length,e,l,b]),oe=l!==null||u===null||u.hovered===null?null:(()=>{let t=ue(u.hovered),r=e.xValues.findIndex(i=>ue(i)===t);return r<0?null:r})(),L=l??oe,_=L===null?null:O(L),N=(_??[]).filter(t=>t.value!==null),ae=f.dragging??ee,a=ae?Ge(ae,e.xValues,e.xPositions,e.locate):null,M=ot(he),x=l===null||_===null?null:{x:e.xValues[l],xLabel:I(e.xValues[l],l),index:l,points:_};return W(wt,{children:[W("svg",{width:d,height:g,role:"img","aria-label":fe??[e.visible.map(t=>Re(t)).join(", "),Ke(v,ce)].filter(Boolean).join(". "),tabIndex:0,className:Ne(bt,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",Y&&"select-none"),onPointerDown:f.onPointerDown,onPointerMove:te,onPointerUp:f.onPointerUp,onPointerCancel:f.onPointerUp,onPointerLeave:ne,onKeyDown:Ce,onBlur:ne,onClick:re,children:[W("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[o($e,{width:e.innerWidth,height:e.innerHeight,horizontal:y==="y"||y==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:y==="x"||y==="both"?e.xTicks.map(t=>t.offset):void 0}),v?o(Se,{layer:"under",annotations:v,xAt:e.locate,spanAt:e.span,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,a?o(Xe,{from:a.from,to:a.to,width:e.innerWidth,height:e.innerHeight,live:f.dragging!==null,label:de,minSpan:Ct}):null,M.under?.(e.plot),D?.map(t=>{let r=e.yScale(t.value),i=r<kt?r+12:r-4;return W("g",{children:[o("line",{x1:0,y1:r,x2:e.innerWidth,y2:r,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?o("text",{x:e.innerWidth,y:i,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),e.forecastIndex>=0?W("g",{children:[o("line",{x1:e.xPositions[e.forecastIndex],y1:0,x2:e.xPositions[e.forecastIndex],y2:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,strokeDasharray:"3 3"}),A?o("text",{x:e.xPositions[e.forecastIndex]+4,y:-2,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:A}):null]}):null,o(Lt,{lines:e.lines,showMarkers:e.showMarkers}),v?o(Se,{annotations:v,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,M.over?.(e.plot),L!==null?W("g",{"aria-hidden":"true",children:[o("line",{x1:e.xPositions[L],y1:0,x2:e.xPositions[L],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:l===null?"3 3":void 0}),N.map(t=>o("circle",{cx:e.xPositions[L],cy:e.yScale(t.value),r:4,fill:t.color,strokeWidth:2,stroke:Be},t.seriesKey))]}):null]}),o("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:m.hidden?null:o(we,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:m.label,size:F})}),o("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:p?.hidden?null:o(we,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:p?.label,size:F})})]}),x&&H!==!1?o(Fe,{x:e.margin.left+e.xPositions[x.index],y:e.margin.top+(N.length>0?Math.min(...N.map(t=>e.yScale(t.value))):e.innerHeight/2),containerWidth:d,children:typeof H=="function"?H(x):o(Ye,{title:x.xLabel,points:x.points})}):null]})}function Jt({data:d,series:g,x:n,y:s,height:m=240,width:p,size:y="md",grid:F="y",legend:P,tooltip:V=!0,tableView:A=!1,emphasis:E,title:T,description:D,loading:v=!1,emptyState:ce,error:he=!1,errorState:B,onRetry:Y,actions:q,onPointClick:de,curve:me="monotone",forecastFrom:J,forecastLabel:H,markers:k="auto",connectNulls:fe=!1,referenceLines:K,annotations:Q,overlay:I,legendToggle:Z=!0,maxPoints:X,brush:G=!1,onBrush:l,brushLabel:ge,sync:pe=!0,margin:ye,locale:u,plotLabel:e,className:O,...ee}){let C=De(u),f=Me(),[te,ne]=ve(()=>new Set),b=z(()=>g.map((a,M)=>({...a,hidden:a.hidden||te.has(a.key),color:qe(a,M,E)})),[g,te,E]),Ce=z(()=>s?.format??(a=>ut(a,C)),[s?.format,C]),re=z(()=>s?.format??(a=>ct(a,C)),[s?.format,C]),oe=z(()=>n.format??(a=>n.scale==="time"?yt(a,C):ht(a,C)),[n.format,n.scale,C]),L=R(a=>{ne(M=>{let x=new Set(M);return x.has(a)?x.delete(a):x.add(a),x})},[]),_=P===void 0?g.length>=2:P!==!1,N=typeof P=="string"?P:"bottom",ae=b.filter(a=>!a.hidden).length;return o(_e,{title:T,description:D,height:m,width:p,size:y,loading:v,empty:d.length===0||ae===0,emptyState:ce,error:he,errorState:B,onRetry:Y,actions:q,exportSource:{data:d,series:b,xKey:n.key,xLabel:n.label??n.key,formatX:n.format},tableView:A,legendPosition:N,legend:_?o(Ue,{items:Je(b,E),position:N,marker:"line",size:y,onToggle:Z?L:void 0}):void 0,table:A?o(ze,{data:d,series:b,xKey:n.key,xLabel:n.label??n.key,formatX:oe,formatValue:re,caption:typeof T=="string"?T:void 0}):void 0,className:O,...ee,children:({width:a})=>o(St,{locale:C,width:a,height:m,data:d,resolvedSeries:b,x:n,y:s,grid:F,size:y,curve:me,forecastFrom:J,forecastLabel:H,markers:k,connectNulls:fe,referenceLines:K,annotations:Q,annotationsLabel:f.chartAnnotations,overlay:I,maxPoints:X,brush:G,onBrush:l,brushLabel:ge??f.chartBrush,syncEnabled:pe,margin:ye,tooltip:V,onPointClick:de,plotLabel:e,formatValue:Ce,formatExact:re,formatX:oe})})}export{Jt as LineChart,qt as resetLineChartWarnings};
|
|
1
|
+
"use client";import{memo as Ie,useCallback as R,useMemo as z,useState as ve}from"react";import{cn as Ne}from"../../lib/cn.js";import{useUILabels as Me,useUILocale as De}from"../../lib/i18n.js";import{ChartAnnotationLayer as Se,describeAnnotations as Ke}from"../chart/ChartAnnotations.js";import{ChartAxis as we}from"../chart/ChartAxis.js";import{ChartBrushLayer as Xe,locateBrush as Ge,useChartBrush as Oe}from"../chart/ChartBrush.js";import{ChartContainer as _e}from"../chart/ChartContainer.js";import{ChartGrid as $e}from"../chart/ChartGrid.js";import{ChartLegend as Ue}from"../chart/ChartLegend.js";import{useChartSync as je}from"../chart/ChartSync.js";import{ChartTableView as ze}from"../chart/ChartTableView.js";import{ChartTooltip as Fe,ChartTooltipContent as Ye}from"../chart/ChartTooltip.js";import{CHART_SURFACE_COLOR as Be,getSeriesLabel as Re,resolveSeriesColor as qe,toLegendItems as Je}from"../chart/palette.js";import{annotationValues as Qe,buildCartesianGeometry as Ze,createCategoryLocator as et,createPlotContext as tt,createSpanLocator as nt,plotPointer as rt,splitOverlay as ot,widenBounds as at}from"../chart/utils/cartesian.js";import{collectAllValues as st,readNumber as Ve}from"../chart/utils/data.js";import{decimatePath as it,warnPointBudget as lt}from"../chart/utils/decimate.js";import{formatAuto as ut,formatExact as ct,formatXValue as ht}from"../chart/utils/format.js";import{chartCursorTarget as dt,pressChartMark as mt}from"../chart/utils/keyboard.js";import{buildLinePath as Ae,isDrawable as ft,isolatedPoints as gt}from"../chart/utils/path.js";import{nearestIndex as Ee,toKey as ue}from"../chart/utils/scales.js";import{extent as pt}from"../chart/utils/ticks.js";import{formatTimeValue as yt,toTimestamp as Te}from"../chart/utils/timestamp.js";import{CHART_TOUCH as bt}from"../chart/utils/touch.js";import{Fragment as wt,jsx as o,jsxs as W}from"react/jsx-runtime";var Ct=6,xt=24,vt=10,kt=10,ke=!1;function qt(){ke=!1}function Pt(d,g){let n=ue(g),s=d.findIndex(p=>ue(p)===n);if(s>=0)return s;let m=Te(g);return m===null?-1:d.findIndex(p=>{let y=Te(p);return y!==null&&y>=m})}var Lt=Ie(function({lines:g,showMarkers:n}){return o("g",{children:g.map(s=>W("g",{children:[s.solid?o("path",{d:s.solid,fill:"none",stroke:s.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"}):null,s.dashed?o("path",{d:s.dashed,fill:"none",stroke:s.color,strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round",strokeDasharray:"5 4"}):null,(n?s.markers:s.isolated).map((m,p)=>o("circle",{cx:m.x,cy:m.y,r:3,fill:s.color,strokeWidth:2,stroke:Be},p))]},s.key))})});function St({width:d,height:g,data:n,resolvedSeries:s,x:m,y:p,grid:y,size:F,curve:P,forecastFrom:V,forecastLabel:A,markers:E,connectNulls:T,referenceLines:D,annotations:v,annotationsLabel:ce,overlay:he,maxPoints:B,brush:Y,onBrush:q,brushLabel:de,syncEnabled:me,margin:J,tooltip:H,onPointClick:k,plotLabel:fe,formatValue:K,formatExact:Q,formatX:I,locale:Z}){let[X,G]=ve(null),l=X!==null&&X<n.length?X:null,[ge,pe]=ve(null),ye=je(),u=me?ye:null,e=z(()=>{let t=s.filter(h=>!h.hidden),r=Ze({locale:Z,width:d,height:g,data:n,x:m,y:p,bounds:at(pt(st(n,t.map(h=>h.key))),Qe(n,m.key,D,v)),margin:J,placement:"point",formatValue:K,formatX:I,extraTop:A?vt:0}),i=r.categoryCenters,c=r.valueScale,S=V===void 0?-1:Pt(r.xValues,V);V!==void 0&&S<0&&n.length>0&&!ke&&(ke=!0,console.warn(`[@synertech/ui] LineChart was given \`forecastFrom\` = ${String(V)}, which no row is on or after. Nothing is drawn as a forecast: pass the x value of the first projected row, in the form the rows carry it.`));let se=t.map(h=>{let $=n.map((le,We)=>{let xe=Ve(le,h.key);return{x:i[We],y:xe===null?Number.NaN:c(xe),defined:xe!==null}}),Pe={connectNulls:T},ie=S>=0,be=le=>B&&B>0?it(le,B):le,U=h.dashed?[]:be(ie?$.slice(0,S+1):$),j=h.dashed?be($):ie?be($.slice(S)):[];B||lt("LineChart",$.length);let He=U[U.length-1],Le=h.dashed?j:ie?[...U,...j[0]===He?j.slice(1):j]:U;return{key:h.key,color:h.color,solid:h.dashed?"":Ae(U,P,Pe),dashed:h.dashed||ie?Ae(j,P,Pe):"",markers:Le.filter(ft),isolated:gt(Le,T)}}),w=n.length>1?r.innerWidth/(n.length-1):0;return{visible:t,locate:et(r),span:nt(r),plot:tt({geometry:r,width:d,height:g,data:n,series:t,formatValue:K,formatX:I}),xValues:r.xValues,xPositions:i,xTicks:r.categoryTicks,yTicks:r.valueTicks,yScale:c,innerWidth:r.innerWidth,innerHeight:r.innerHeight,margin:r.margin,lines:se,forecastIndex:S,showMarkers:E==="always"||E==="auto"&&w>=xt&&n.length>1}},[Z,n,s,m,p,d,g,J,P,T,V,A,E,B,D,v,K,I]),O=R(t=>e.visible.map(r=>{let i=Ve(n[t],r.key);return{seriesKey:r.key,seriesLabel:Re(r),color:r.color,value:i,formattedValue:i===null?"\u2014":Q(i),datum:n[t]}}),[n,e.visible,Q]),ee=u?u.brush:ge,C=R(t=>{pe(t),u?.setBrush(t),q?.(t)},[u,q]),f=Oe({enabled:Y,active:ee!==null,centers:e.xPositions,xValues:e.xValues,offset:e.margin.left,orientation:"vertical",onCommit:C}),te=R(t=>{if(f.onPointerMove(t),H===!1||n.length===0)return;let r=t.currentTarget.getBoundingClientRect(),i=t.clientX-r.left-e.margin.left,c=Ee(e.xPositions,i);G(c>=0?c:null),u?.setHovered(c>=0?e.xValues[c]:null)},[f,H,n.length,e.margin.left,e.xPositions,e.xValues,u]),ne=R(()=>{G(null),u?.setHovered(null)},[u]),b=R((t,r)=>{if(!k)return;let i=O(t),c=i.filter(w=>w.value!==null),S=w=>r===null?0:Math.abs(e.yScale(w.value)-r.y),se=c.length>0?c.reduce((w,h)=>S(h)<S(w)?h:w):i[0];se&&k({...se,index:t,x:e.xValues[t]})},[k,O,e]),Ce=R(t=>{if(n.length===0)return;let r=k&&l!==null&&e.visible.length>0;if(mt(t,r?()=>b(l,null):null))return;let i=f.onKeyDown(t,l),c=dt(t.key,l,n.length,"x");if(c===void 0){i&&t.preventDefault();return}t.preventDefault(),G(c),u?.setHovered(c===null?null:e.xValues[c])},[n.length,l,f,u,e.xValues,e.visible.length,k,b]),re=R(t=>{if(f.consumedClick()||!k||n.length===0)return;let r=rt(t,e),i=l??(r===null?-1:Ee(e.xPositions,r.x));i<0||b(i,r)},[f,k,n.length,e,l,b]),oe=l!==null||u===null||u.hovered===null?null:(()=>{let t=ue(u.hovered),r=e.xValues.findIndex(i=>ue(i)===t);return r<0?null:r})(),L=l??oe,_=L===null?null:O(L),N=(_??[]).filter(t=>t.value!==null),ae=f.dragging??ee,a=ae?Ge(ae,e.xValues,e.xPositions,e.locate):null,M=ot(he),x=l===null||_===null?null:{x:e.xValues[l],xLabel:I(e.xValues[l],l),index:l,points:_};return W(wt,{children:[W("svg",{width:d,height:g,role:"img","aria-label":fe??[e.visible.map(t=>Re(t)).join(", "),Ke(v,ce)].filter(Boolean).join(". "),tabIndex:0,className:Ne(bt,"focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-synertech-primary-500",Y&&"select-none"),onPointerDown:f.onPointerDown,onPointerMove:te,onPointerUp:f.onPointerUp,onPointerCancel:f.onPointerUp,onPointerLeave:ne,onKeyDown:Ce,onBlur:ne,onClick:re,children:[W("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:[o($e,{width:e.innerWidth,height:e.innerHeight,horizontal:y==="y"||y==="both"?e.yTicks.map(t=>t.offset):void 0,vertical:y==="x"||y==="both"?e.xTicks.map(t=>t.offset):void 0}),v?o(Se,{layer:"under",annotations:v,xAt:e.locate,spanAt:e.span,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,a?o(Xe,{from:a.from,to:a.to,width:e.innerWidth,height:e.innerHeight,live:f.dragging!==null,label:de,minSpan:Ct}):null,M.under?.(e.plot),D?.map(t=>{let r=e.yScale(t.value),i=r<kt?r+12:r-4;return W("g",{children:[o("line",{x1:0,y1:r,x2:e.innerWidth,y2:r,stroke:t.color??"var(--color-chart-muted)",strokeWidth:1,strokeDasharray:t.dashed===!1?void 0:"4 4"}),t.label?o("text",{x:e.innerWidth,y:i,textAnchor:"end",className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:t.label}):null]},`${t.value}-${t.label??""}`)}),e.forecastIndex>=0?W("g",{children:[o("line",{x1:e.xPositions[e.forecastIndex],y1:0,x2:e.xPositions[e.forecastIndex],y2:e.innerHeight,className:"stroke-gray-300 dark:stroke-gray-600",strokeWidth:1,strokeDasharray:"3 3"}),A?o("text",{x:e.xPositions[e.forecastIndex]+4,y:-2,className:"fill-gray-500 text-[10px] dark:fill-gray-400",children:A}):null]}):null,o(Lt,{lines:e.lines,showMarkers:e.showMarkers}),v?o(Se,{annotations:v,xAt:e.locate,yAt:e.yScale,width:e.innerWidth,height:e.innerHeight}):null,M.over?.(e.plot),L!==null?W("g",{"aria-hidden":"true",children:[o("line",{x1:e.xPositions[L],y1:0,x2:e.xPositions[L],y2:e.innerHeight,className:"stroke-gray-400 dark:stroke-gray-500",strokeWidth:1,strokeDasharray:l===null?"3 3":void 0}),N.map(t=>o("circle",{cx:e.xPositions[L],cy:e.yScale(t.value),r:4,fill:t.color,strokeWidth:2,stroke:Be},t.seriesKey))]}):null]}),o("g",{transform:`translate(${e.margin.left}, ${e.margin.top+e.innerHeight})`,children:m.hidden?null:o(we,{orientation:"bottom",ticks:e.xTicks,length:e.innerWidth,label:m.label,size:F})}),o("g",{transform:`translate(${e.margin.left}, ${e.margin.top})`,children:p?.hidden?null:o(we,{orientation:"left",ticks:e.yTicks,length:e.innerHeight,showLine:!1,label:p?.label,size:F})})]}),x&&H!==!1?o(Fe,{x:e.margin.left+e.xPositions[x.index],y:e.margin.top+(N.length>0?Math.min(...N.map(t=>e.yScale(t.value))):e.innerHeight/2),containerWidth:d,children:typeof H=="function"?H(x):o(Ye,{title:x.xLabel,points:x.points})}):null]})}function Jt({data:d,series:g,x:n,y:s,height:m=240,width:p,size:y="md",grid:F="y",legend:P,tooltip:V=!0,tableView:A=!1,emphasis:E,title:T,description:D,loading:v=!1,emptyState:ce,error:he=!1,errorState:B,onRetry:Y,actions:q,onPointClick:de,curve:me="monotone",forecastFrom:J,forecastLabel:H,markers:k="auto",connectNulls:fe=!1,referenceLines:K,annotations:Q,overlay:I,legendToggle:Z=!0,maxPoints:X,brush:G=!1,onBrush:l,brushLabel:ge,sync:pe=!0,margin:ye,locale:u,plotLabel:e,className:O,...ee}){let C=De(u),f=Me(),[te,ne]=ve(()=>new Set),b=z(()=>g.map((a,M)=>({...a,hidden:a.hidden||te.has(a.key),color:qe(a,M,E)})),[g,te,E]),Ce=z(()=>s?.format??(a=>ut(a,C)),[s?.format,C]),re=z(()=>s?.format??(a=>ct(a,C)),[s?.format,C]),oe=z(()=>n.format??(a=>n.scale==="time"?yt(a,C):ht(a,C)),[n.format,n.scale,C]),L=R(a=>{ne(M=>{let x=new Set(M);return x.has(a)?x.delete(a):x.add(a),x})},[]),_=P===void 0?g.length>=2:P!==!1,N=typeof P=="string"?P:"bottom",ae=b.filter(a=>!a.hidden).length;return o(_e,{title:T,description:D,height:m,width:p,size:y,loading:v,empty:d.length===0||ae===0,emptyState:ce,error:he,errorState:B,onRetry:Y,actions:q,exportSource:{data:d,series:b,xKey:n.key,xLabel:n.label??n.key,formatX:n.format},tableView:A,legendPosition:N,legend:_?o(Ue,{items:Je(b,E),position:N,marker:"line",size:y,onToggle:Z?L:void 0}):void 0,table:A?o(ze,{data:d,series:b,xKey:n.key,xLabel:n.label??n.key,formatX:oe,formatValue:re,caption:typeof T=="string"?T:void 0}):void 0,className:O,...ee,children:({width:a})=>o(St,{locale:C,width:a,height:m,data:d,resolvedSeries:b,x:n,y:s,grid:F,size:y,curve:me,forecastFrom:J,forecastLabel:H,markers:k,connectNulls:fe,referenceLines:K,annotations:Q,annotationsLabel:f.chartAnnotations,overlay:I,maxPoints:X,brush:G,onBrush:l,brushLabel:ge??f.chartBrush,syncEnabled:pe,margin:ye,tooltip:V,onPointClick:de,plotLabel:e,formatValue:Ce,formatExact:re,formatX:oe})})}export{Jt as LineChart,qt as resetLineChartWarnings};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var R=(e,r)=>{for(var s in r)d(e,s,{get:r[s],enumerable:!0})},_=(e,r,s,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of N(r))!z.call(e,a)&&a!==s&&d(e,a,{get:()=>r[a],enumerable:!(o=B(r,a))||o.enumerable});return e};var V=e=>_(d({},"__esModule",{value:!0}),e);var $={};R($,{ProgressBar:()=>
|
|
1
|
+
"use strict";var d=Object.defineProperty;var B=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var z=Object.prototype.hasOwnProperty;var R=(e,r)=>{for(var s in r)d(e,s,{get:r[s],enumerable:!0})},_=(e,r,s,o)=>{if(r&&typeof r=="object"||typeof r=="function")for(let a of N(r))!z.call(e,a)&&a!==s&&d(e,a,{get:()=>r[a],enumerable:!(o=B(r,a))||o.enumerable});return e};var V=e=>_(d({},"__esModule",{value:!0}),e);var $={};R($,{ProgressBar:()=>p});module.exports=V($);var i=require("../../lib/cn.cjs"),t=require("react/jsx-runtime"),M={xs:"h-1",sm:"h-1.5",md:"h-2.5",lg:"h-4",xl:"h-6"},S={default:"bg-gray-500 dark:bg-gray-400",primary:"bg-synertech-primary-600 dark:bg-synertech-primary-500",success:"bg-green-600 dark:bg-green-500",warning:"bg-yellow-500 dark:bg-yellow-400",error:"bg-red-600 dark:bg-red-500",info:"bg-cyan-600 dark:bg-cyan-500"},O={default:"text-gray-700 dark:text-gray-300",primary:"text-synertech-primary-600 dark:text-synertech-primary-400",success:"text-green-700 dark:text-green-400",warning:"text-yellow-700 dark:text-yellow-400",error:"text-red-600 dark:text-red-400",info:"text-cyan-700 dark:text-cyan-400"},u="bg-[repeating-linear-gradient(45deg,transparent,transparent_10px,rgba(255,255,255,0.2)_10px,rgba(255,255,255,0.2)_20px)]",W={default:"bg-gradient-to-r from-gray-400 to-gray-600",primary:"bg-gradient-to-r from-synertech-primary-400 to-synertech-primary-700",success:"bg-gradient-to-r from-green-400 to-green-700",warning:"bg-gradient-to-r from-yellow-300 to-yellow-600",error:"bg-gradient-to-r from-red-400 to-red-700",info:"bg-gradient-to-r from-cyan-400 to-cyan-700"};function p({value:e=0,indeterminate:r=!1,size:s="md",color:o="primary",variant:a="default",progressColor:b,trackColor:f,showValue:g=!1,valueFormat:m,label:n,animated:x=!0,className:h,"aria-label":w,"aria-labelledby":y,"aria-describedby":v,"aria-valuetext":P,...C}){let l=Number.isFinite(e)?Math.min(100,Math.max(0,e)):0,c=b||(a==="gradient"?W[o]:S[o]),k=m?m(l):`${Math.round(l)}%`;return(0,t.jsxs)("div",{className:(0,i.cn)("w-full",h),...C,children:[(n||g)&&(0,t.jsxs)("div",{className:"flex items-center justify-between mb-1",children:[n&&(0,t.jsx)("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:n}),g&&!r&&(0,t.jsx)("span",{className:(0,i.cn)("text-sm font-semibold",O[o],!n&&"ml-auto"),children:k})]}),(0,t.jsx)("div",{role:"progressbar","aria-valuenow":r?void 0:l,"aria-valuemin":0,"aria-valuemax":100,"aria-valuetext":P,"aria-label":w??(y?void 0:n),"aria-labelledby":y,"aria-describedby":v,className:(0,i.cn)("relative w-full overflow-hidden rounded-full",f||"bg-gray-200 dark:bg-gray-700",M[s]),children:r?(0,t.jsx)("div",{className:(0,i.cn)("absolute h-full w-1/3 rounded-full",c,a==="striped"&&u,"animate-[progress-indeterminate_1.5s_ease-in-out_infinite]","motion-reduce:w-full motion-reduce:animate-pulse")}):(0,t.jsx)("div",{className:(0,i.cn)("h-full rounded-full",c,a==="striped"&&u,x&&"transition-[width] duration-300 ease-out"),style:{width:`${l}%`}})})]})}p.displayName="ProgressBar";0&&(module.exports={ProgressBar});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cn as e}from"../../lib/cn.js";import{jsx as a,jsxs as c}from"react/jsx-runtime";var k={xs:"h-1",sm:"h-1.5",md:"h-2.5",lg:"h-4",xl:"h-6"},B={default:"bg-gray-500 dark:bg-gray-400",primary:"bg-synertech-primary-600 dark:bg-synertech-primary-500",success:"bg-green-600 dark:bg-green-500",warning:"bg-yellow-500 dark:bg-yellow-400",error:"bg-red-600 dark:bg-red-500",info:"bg-cyan-600 dark:bg-cyan-500"},N={default:"text-gray-700 dark:text-gray-300",primary:"text-synertech-primary-600 dark:text-synertech-primary-400",success:"text-green-700 dark:text-green-400",warning:"text-yellow-700 dark:text-yellow-400",error:"text-red-600 dark:text-red-400",info:"text-cyan-700 dark:text-cyan-400"},y="bg-[repeating-linear-gradient(45deg,transparent,transparent_10px,rgba(255,255,255,0.2)_10px,rgba(255,255,255,0.2)_20px)]",z={default:"bg-gradient-to-r from-gray-400 to-gray-600",primary:"bg-gradient-to-r from-synertech-primary-400 to-synertech-primary-700",success:"bg-gradient-to-r from-green-400 to-green-700",warning:"bg-gradient-to-r from-yellow-300 to-yellow-600",error:"bg-gradient-to-r from-red-400 to-red-700",info:"bg-gradient-to-r from-cyan-400 to-cyan-700"};function R({value:n=0,indeterminate:s=!1,size:
|
|
1
|
+
import{cn as e}from"../../lib/cn.js";import{jsx as a,jsxs as c}from"react/jsx-runtime";var k={xs:"h-1",sm:"h-1.5",md:"h-2.5",lg:"h-4",xl:"h-6"},B={default:"bg-gray-500 dark:bg-gray-400",primary:"bg-synertech-primary-600 dark:bg-synertech-primary-500",success:"bg-green-600 dark:bg-green-500",warning:"bg-yellow-500 dark:bg-yellow-400",error:"bg-red-600 dark:bg-red-500",info:"bg-cyan-600 dark:bg-cyan-500"},N={default:"text-gray-700 dark:text-gray-300",primary:"text-synertech-primary-600 dark:text-synertech-primary-400",success:"text-green-700 dark:text-green-400",warning:"text-yellow-700 dark:text-yellow-400",error:"text-red-600 dark:text-red-400",info:"text-cyan-700 dark:text-cyan-400"},y="bg-[repeating-linear-gradient(45deg,transparent,transparent_10px,rgba(255,255,255,0.2)_10px,rgba(255,255,255,0.2)_20px)]",z={default:"bg-gradient-to-r from-gray-400 to-gray-600",primary:"bg-gradient-to-r from-synertech-primary-400 to-synertech-primary-700",success:"bg-gradient-to-r from-green-400 to-green-700",warning:"bg-gradient-to-r from-yellow-300 to-yellow-600",error:"bg-gradient-to-r from-red-400 to-red-700",info:"bg-gradient-to-r from-cyan-400 to-cyan-700"};function R({value:n=0,indeterminate:s=!1,size:u="md",color:o="primary",variant:i="default",progressColor:p,trackColor:b,showValue:l=!1,valueFormat:d,label:r,animated:f=!0,className:x,"aria-label":h,"aria-labelledby":g,"aria-describedby":w,"aria-valuetext":v,...P}){let t=Number.isFinite(n)?Math.min(100,Math.max(0,n)):0,m=p||(i==="gradient"?z[o]:B[o]),C=d?d(t):`${Math.round(t)}%`;return c("div",{className:e("w-full",x),...P,children:[(r||l)&&c("div",{className:"flex items-center justify-between mb-1",children:[r&&a("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:r}),l&&!s&&a("span",{className:e("text-sm font-semibold",N[o],!r&&"ml-auto"),children:C})]}),a("div",{role:"progressbar","aria-valuenow":s?void 0:t,"aria-valuemin":0,"aria-valuemax":100,"aria-valuetext":v,"aria-label":h??(g?void 0:r),"aria-labelledby":g,"aria-describedby":w,className:e("relative w-full overflow-hidden rounded-full",b||"bg-gray-200 dark:bg-gray-700",k[u]),children:s?a("div",{className:e("absolute h-full w-1/3 rounded-full",m,i==="striped"&&y,"animate-[progress-indeterminate_1.5s_ease-in-out_infinite]","motion-reduce:w-full motion-reduce:animate-pulse")}):a("div",{className:e("h-full rounded-full",m,i==="striped"&&y,f&&"transition-[width] duration-300 ease-out"),style:{width:`${t}%`}})})]})}R.displayName="ProgressBar";export{R as ProgressBar};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var Ve=Object.defineProperty;var jt=Object.getOwnPropertyDescriptor;var Zt=Object.getOwnPropertyNames;var en=Object.prototype.hasOwnProperty;var tn=(h,p)=>{for(var Y in p)Ve(h,Y,{get:p[Y],enumerable:!0})},nn=(h,p,Y,q)=>{if(p&&typeof p=="object"||typeof p=="function")for(let z of Zt(p))!en.call(h,z)&&z!==Y&&Ve(h,z,{get:()=>p[z],enumerable:!(q=jt(p,z))||q.enumerable});return h};var rn=h=>nn(Ve({},"__esModule",{value:!0}),h);var dn={};tn(dn,{SchemaEditor:()=>Rt});module.exports=rn(dn);var n=require("react"),D=require("../../lib/canvas-events.cjs"),ut=require("../../lib/cn.cjs"),dt=require("../../lib/editable-target.cjs"),me=require("../../lib/i18n.cjs"),ft=require("../../lib/owner-document.cjs"),mt=require("./canvas/GridLayer.cjs"),ht=require("./tables/SchemaTableRenderer.cjs"),bt=require("./relations/SchemaRelationRenderer.cjs"),gt=require("./toolbar/SchemaToolbar.cjs"),pt=require("./legend/SchemaLegend.cjs"),yt=require("./minimap/SchemaMinimap.cjs"),u=require("./utils/geometry.cjs"),X=require("./utils/schema-helpers.cjs"),He=require("./utils/sql-export.cjs"),vt=require("./utils/import.cjs"),It=require("./utils/auto-layout.cjs"),E=require("./utils/foreign-keys.cjs"),R=require("react/jsx-runtime"),Ne={x:0,y:0,zoom:1},Ae=.1,on=.1,an=3,sn=20,ln=50;function cn(h,p){return h.tables===p.tables&&h.relations===p.relations?!0:JSON.stringify([h.tables,h.relations])===JSON.stringify([p.tables,p.relations])}function un({value:h,defaultValue:p,onValueChange:Y,fieldTypes:q=X.DEFAULT_FIELD_TYPES,onTableClick:z,onTableDoubleClick:he,onTableContextMenu:be,onFieldClick:ge,onFieldDoubleClick:pe,readOnly:L=!1,disabled:b=!1,draggableTables:Pe=!0,panOnDrag:Oe=!0,zoomOnWheel:St=!0,editable:ke=!0,minZoom:x=on,maxZoom:M=an,snapToGrid:_e=!1,gridSize:ye=sn,showGrid:Et=!0,toolbar:Tt=!0,legend:Ue=!0,autoFit:Be=!1,labels:wt,className:zt},Ft){let H=(0,me.useUILabels)(wt),j=h!==void 0,[Ct,Dt]=(0,n.useState)(()=>p??{tables:[],relations:[],viewport:{...Ne}}),v=j?h:Ct,y=v.tables,B=v.relations,a=v.viewport??Ne,S=(0,n.useRef)(null),P=(0,n.useRef)(null),[Z,J]=(0,n.useState)(null),[ee,K]=(0,n.useState)(null),[F,ve]=(0,n.useState)(null),[Je,Ke]=(0,n.useState)(null),[Ie,We]=(0,n.useState)({width:0,height:0}),w=ke&&!L&&!b,Ge=(0,n.useRef)(v),V=(0,n.useRef)(v),[te]=(0,n.useState)(()=>new WeakSet),O=(0,n.useRef)([v]),C=(0,n.useRef)(0),[,Qe]=(0,n.useReducer)(e=>e+1,0),W=(0,n.useRef)(!1);j&&(!te.has(h)&&!cn(h,V.current)&&(O.current=[h],C.current=0),V.current=h),te.add(v),Ge.current=v;let ne=(0,n.useRef)(a);ne.current=a;let $e=(0,n.useRef)(y);$e.current=y;let qe=(0,n.useRef)(B);qe.current=B;let je=(0,n.useRef)(_e);je.current=_e;let Re=(0,n.useRef)(ye);Re.current=ye;let Se=(0,n.useRef)(w);Se.current=w;let re=(0,n.useCallback)(e=>{let t=O.current[C.current];if(t&&t.tables===e.tables&&t.relations===e.relations)return;let r=O.current.slice(0,C.current+1);r.push(e),r.length>ln&&r.shift(),O.current=r,C.current=r.length-1,Qe()},[]),Ze=(0,n.useRef)(Y);Ze.current=Y;let Ee=(0,n.useRef)(!1),oe=(0,n.useCallback)(e=>{V.current=e,te.add(e),j?Ee.current||(Ee.current=!0,queueMicrotask(()=>{Ee.current=!1,V.current=Ge.current})):Dt(e),Ze.current?.(e)},[j,te]),l=(0,n.useCallback)((e,t=!0)=>{let r=V.current,o=e(r);return o===r?!1:(oe(o),t&&re(o),!0)},[oe,re]),ie=(0,n.useRef)(l);ie.current=l;let T=(0,n.useCallback)(e=>{l(t=>({...t,viewport:e}),!1)},[l]),et=(0,n.useRef)(T);et.current=T;let G=(0,n.useRef)(null),Q=(0,n.useRef)(null),k=(0,n.useCallback)(()=>{Q.current?.(),Q.current=null;let e=P.current;P.current=null,G.current=null,e?.type==="relation"&&(ve(null),Ke(null)),(e?.type==="table"||e?.type==="resize")&&W.current&&re(V.current),W.current=!1},[re]),tt=(0,n.useCallback)((e,t,r,o)=>{let s=ne.current,i=(0,u.screenToCanvas)(e,t,s,r),g=1/0,d=null,f=null;for(let c of o){if(c.collapsed||c.fields.length===0)continue;let m=c.width??u.DEFAULT_TABLE_WIDTH,N=(0,u.getTableHeight)(c,Se.current),A=(0,u.hasNotesRow)(c,Se.current),de=40;if(!(i.x<c.x-de||i.x>c.x+m+de||i.y<c.y-de||i.y>c.y+N+de))for(let fe=0;fe<c.fields.length;fe++){let qt=c.y+(0,u.getFieldConnectionY)(fe,A),ct=Math.abs(i.y-qt);ct<g&&(g=ct,d=c.id,f=c.fields[fe].id)}}return d&&f?{tableId:d,fieldId:f}:null},[]),Te=(0,n.useCallback)(e=>{let t=P.current;if(!t||e.pointerId!==G.current)return;if(e.buttons===0){k();return}let r=S.current?.getBoundingClientRect();if(!r)return;let o=ne.current;if(t.type==="pan"){let s=e.clientX-t.startX,i=e.clientY-t.startY;et.current({...o,x:t.startVpX+s,y:t.startVpY+i})}if(t.type==="table"){let s=(0,u.screenToCanvas)(e.clientX,e.clientY,o,r),i=s.x-t.offsetX,g=s.y-t.offsetY;je.current&&(i=(0,u.snapValue)(i,Re.current),g=(0,u.snapValue)(g,Re.current)),ie.current(f=>{let c=f.tables.find(I=>I.id===t.tableId);return!c||c.x===i&&c.y===g?f:{...f,tables:f.tables.map(I=>I.id===t.tableId?{...I,x:i,y:g}:I)}},!1)&&(W.current=!0)}if(t.type==="relation"){let s=(0,u.screenToCanvas)(e.clientX,e.clientY,o,r);P.current={...t,currentX:s.x,currentY:s.y},ve({fromX:t.fromX,fromY:t.fromY,currentX:s.x,currentY:s.y})}if(t.type==="resize"){let s=(e.clientX-t.startX)/o.zoom,i=(e.clientY-t.startY)/o.zoom,g=180,d=80,f=Math.max(g,t.startWidth+s),c=Math.max(d,t.startHeight+i);ie.current(m=>{let N=m.tables.find(A=>A.id===t.tableId);return!N||N.width===f&&N.height===c?m:{...m,tables:m.tables.map(A=>A.id===t.tableId?{...A,width:f,height:c}:A)}},!1)&&(W.current=!0)}},[k]),we=(0,n.useCallback)(e=>{let t=P.current;if(!(!t||e.pointerId!==G.current)){if(t.type==="relation"){let r=S.current?.getBoundingClientRect();if(r){let o=qe.current,s=$e.current,i=tt(e.clientX,e.clientY,r,s);if(i&&i.tableId!==t.fromTableId&&!o.some(d=>d.from.tableId===t.fromTableId&&d.from.fieldId===t.fromFieldId&&d.to.tableId===i.tableId&&d.to.fieldId===i.fieldId)){let d=t.fromTableId,f=t.fromFieldId,c=i.tableId,I=i.fieldId;ie.current(m=>(0,E.addRelationToSchema)(m,{id:(0,X.generateRelationId)(),from:{tableId:d,fieldId:f},to:{tableId:c,fieldId:I},cardinality:"1:n"}))}}}k()}},[k,tt]),ze=(0,n.useCallback)(e=>{e.pointerId===G.current&&k()},[k]),_=(0,n.useCallback)((e,t)=>{Q.current?.(),P.current=e,G.current=t,W.current=!1;let r=(0,ft.ownerDocumentOf)(S.current);r.addEventListener("pointermove",Te),r.addEventListener("pointerup",we),r.addEventListener("pointercancel",ze),Q.current=()=>{r.removeEventListener("pointermove",Te),r.removeEventListener("pointerup",we),r.removeEventListener("pointercancel",ze)}},[Te,we,ze]);(0,n.useEffect)(()=>()=>Q.current?.(),[]),(0,D.useCanvasWheel)(S,e=>{if(!St||b)return;let t=(0,D.wheelZoomDirection)(e);if(t===null)return;e.preventDefault();let r=S.current?.getBoundingClientRect();if(!r)return;let o=e.clientX-r.left,s=e.clientY-r.top,i=(0,u.clampZoom)(a.zoom+t*Ae,x,M),g=i/a.zoom;T({x:o-(o-a.x)*g,y:s-(s-a.y)*g,zoom:i})});let Lt=(0,n.useCallback)(e=>{if(b||!(0,D.isInCanvas)(S.current,e.target))return;let t=(0,D.isPrimaryPress)(e),r=e.target,o=r.tagName,s=o==="INPUT"||o==="SELECT"||o==="TEXTAREA"||o==="BUTTON";if(r.closest("[data-resize-handle]"))return;let i=r.closest("[data-connection-side]");if(i&&!s){if(L||!t)return;e.preventDefault();let d=i.getAttribute("data-table-id"),f=i.getAttribute("data-field-id");if(!d||!f)return;let c=y.find(N=>N.id===d);if(!c)return;let I=i.getAttribute("data-connection-side"),m=(0,u.getFieldConnectionPosition)(c,f,I,w);if(!m)return;_({type:"relation",fromTableId:d,fromFieldId:f,fromX:m.x,fromY:m.y,currentX:m.x,currentY:m.y},e.pointerId),ve({fromX:m.x,fromY:m.y,currentX:m.x,currentY:m.y}),Ke(d);return}let g=r.closest("[data-table-id]");if(g){if(L)return;let d=g.getAttribute("data-table-id");if(K(null),J(d),s||!t||r.closest('[draggable="true"]'))return;if(Pe){let f=S.current?.getBoundingClientRect();if(!f)return;let c=y.find(m=>m.id===d);if(!c||c.locked)return;let I=(0,u.screenToCanvas)(e.clientX,e.clientY,a,f);_({type:"table",tableId:d,offsetX:I.x-c.x,offsetY:I.y-c.y},e.pointerId)}return}J(null),K(null),Oe&&t&&_({type:"pan",startX:e.clientX,startY:e.clientY,startVpX:a.x,startVpY:a.y},e.pointerId)},[b,L,w,Pe,Oe,a,y,_]),U=(0,n.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 o=r.getAttribute("data-table-id");return y.find(s=>s.id===o)??null},[y]),ae=(0,n.useCallback)(e=>{let t=e.target;if(t.closest("[data-connection-side]"))return null;let r=t.closest("[data-field-id]");if(!r)return null;let o=y.find(i=>i.id===r.getAttribute("data-table-id")),s=o?.fields.find(i=>i.id===r.getAttribute("data-field-id"));return o&&s?{table:o,field:s}:null},[y]),Xt=(0,n.useCallback)(e=>{if(b)return;let t=ge?ae(e):null;t&&ge?.({...t,nativeEvent:e.nativeEvent});let r=U(e);r&&z&&z({table:r,nativeEvent:e.nativeEvent})},[z,ge,b,U,ae]),Yt=(0,n.useCallback)(e=>{if(b)return;let t=pe?ae(e):null;t&&pe?.({...t,nativeEvent:e.nativeEvent});let r=U(e);r&&he&&he({table:r,nativeEvent:e.nativeEvent})},[he,pe,b,U,ae]),xt=(0,n.useCallback)(e=>{if(b)return;let t=U(e);t&&be&&(e.preventDefault(),be({table:t,nativeEvent:e.nativeEvent}))},[be,b,U]),Mt=(0,n.useCallback)((e,t)=>{b||(t.stopPropagation(),J(null),K(e))},[b]),Vt=(0,n.useCallback)((e,t)=>{l(r=>({...r,relations:r.relations.map(o=>o.id===e?{...o,cardinality:t}:o)}))},[l]),Nt=C.current>0,At=C.current<O.current.length-1,se=(0,n.useCallback)(e=>{let t=O.current[e];if(!t)return;C.current=e;let r=V.current;oe({...r,tables:t.tables,relations:t.relations}),Qe()},[oe]),Fe=(0,n.useCallback)(()=>se(C.current-1),[se]),Ce=(0,n.useCallback)(()=>se(C.current+1),[se]),Ht=(0,n.useCallback)(()=>(0,He.generateSQL)(v),[v]),Pt=(0,n.useCallback)(()=>{l(e=>({...e,tables:(0,It.autoLayoutTables)((0,E.resolveForeignKeys)(e).tables,w)}))},[l,w]),Ot=(0,n.useCallback)((e,t,r)=>{t!==r&&l(o=>({...o,tables:o.tables.map(s=>{if(s.id!==e)return s;let i=[...s.fields],[g]=i.splice(t,1);return i.splice(r,0,g),{...s,fields:i}})}))},[l]);(0,n.useEffect)(()=>{let e=S.current;if(!e)return;if(typeof ResizeObserver>"u"){We({width:e.clientWidth,height:e.clientHeight});return}let t=new ResizeObserver(r=>{for(let o of r)We({width:o.contentRect.width,height:o.contentRect.height})});return t.observe(e),()=>t.disconnect()},[]);let le=(0,n.useCallback)(e=>{l(t=>(0,E.removeTableFromSchema)(t,e))},[l]),ce=(0,n.useCallback)(e=>{l(t=>(0,E.removeRelationFromSchema)(t,e))},[l]),kt=(0,n.useCallback)(e=>{if(!(L||b)&&(0,D.isInCanvas)(S.current,e.target)){if((e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey){e.preventDefault(),Fe();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"){if((0,dt.isEditableTarget)(e.target))return;Z&&(le(Z),J(null)),ee&&(ce(ee),K(null))}e.key==="Escape"&&(J(null),K(null))}},[L,b,Z,ee,le,ce,Fe,Ce]),_t=(0,n.useCallback)((e,t)=>{l(r=>({...r,tables:r.tables.map(o=>o.id===e?{...o,name:t}:o)}))},[l]),Ut=(0,n.useCallback)((e,t)=>{l(r=>({...r,tables:r.tables.map(o=>o.id===e?{...o,notes:t}:o)}))},[l]),Bt=(0,n.useCallback)(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e?{...r,collapsed:!r.collapsed}:r)}))},[l]),Jt=(0,n.useCallback)((e,t,r)=>{l(o=>({...o,tables:o.tables.map(s=>s.id===e?{...s,fields:s.fields.map(i=>i.id===t?{...i,...r}:i)}:s)}))},[l]),Kt=(0,n.useCallback)(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e?{...r,fields:[...r.fields,(0,X.createDefaultField)()]}:r)}))},[l]),De=(0,n.useCallback)((e,t)=>{l(r=>(0,E.removeFieldFromSchema)(r,e,t))},[l]),Wt=(0,n.useCallback)((e,t,r,o,s,i)=>{_({type:"resize",tableId:e,startX:t,startY:r,startWidth:o,startHeight:s},i)},[_]),Le=(0,n.useCallback)(()=>{let e=(0,u.clampZoom)(a.zoom+Ae,x,M);T({...a,zoom:e})},[a,x,M,T]),Xe=(0,n.useCallback)(()=>{let e=(0,u.clampZoom)(a.zoom-Ae,x,M);T({...a,zoom:e})},[a,x,M,T]),Ye=(0,n.useCallback)(()=>{T({...Ne})},[T]),$=(0,n.useCallback)(()=>{let e=S.current?.getBoundingClientRect();if(!e)return;let t=(0,u.fitViewport)(y,e.width,e.height,w),r=(0,u.clampZoom)(t.zoom,x,M);T({...t,zoom:r})},[y,w,x,M,T]),ue=(0,n.useCallback)(e=>{l(t=>({...t,tables:[...t.tables,e]}))},[l]),nt=(0,n.useCallback)((e,t)=>{l(r=>({...r,tables:r.tables.map(o=>o.id===e?{...o,fields:[...o.fields,t]}:o)}))},[l]),rt=(0,n.useCallback)((e,t)=>{De(e,t)},[De]),ot=(0,n.useCallback)(e=>{l(t=>(0,E.addRelationToSchema)(t,e))},[l]),xe=(0,n.useCallback)(()=>JSON.stringify(v,null,2),[v]),Me=(0,n.useCallback)(e=>{let t=(0,vt.readSchemaJSON)(e);return t.ok?(l(()=>(0,E.resolveForeignKeys)(t.value)),null):t.reason==="json"?H.editorImportInvalidJson:(0,me.formatUILabel)(H.editorImportInvalidContent,{path:t.path})},[l,H]),it=(0,n.useCallback)(e=>Me(e)===null,[Me]),Gt=(0,n.useCallback)(()=>{let e=S.current?.getBoundingClientRect(),t=ne.current,r=100,o=100;e&&(r=(e.width/2-t.x)/t.zoom-u.DEFAULT_TABLE_WIDTH/2,o=(e.height/2-t.y)/t.zoom-60),ue((0,X.createDefaultTable)(r,o))},[ue]),at=(0,n.useCallback)(()=>(0,He.generateSQL)(v),[v]);(0,n.useImperativeHandle)(Ft,()=>({zoomIn:Le,zoomOut:Xe,resetView:Ye,fitToContent:$,addTable:ue,removeTable:le,addField:nt,removeField:rt,addRelation:ot,removeRelation:ce,toJSON:xe,loadJSON:it,toSQL:at}),[Le,Xe,Ye,$,ue,le,nt,rt,ot,ce,xe,it,at]);let st=(0,n.useRef)(!1),lt=y.length>0;(0,n.useEffect)(()=>{Be&<&&!st.current&&S.current&&(st.current=!0,$())},[Be,lt,$]);let Qt=(0,n.useMemo)(()=>(0,E.resolveForeignKeys)({tables:y,relations:B}).tables,[y,B]),$t=(0,n.useMemo)(()=>({transform:`translate(${a.x}px, ${a.y}px) scale(${a.zoom})`,transformOrigin:"0 0"}),[a.x,a.y,a.zoom]);return(0,R.jsxs)("div",{ref:S,"data-testid":"schema-editor",className:(0,ut.cn)("relative w-full overflow-hidden bg-gray-50 dark:bg-gray-900 select-none touch-none",b&&"opacity-60 pointer-events-none",zt),tabIndex:0,onPointerDown:Lt,onClick:Xt,onDoubleClick:Yt,onContextMenu:xt,onKeyDown:kt,children:[Et&&(0,R.jsx)(mt.GridLayer,{gridSize:ye,zoom:a.zoom}),Tt&&!L&&(0,R.jsx)(gt.SchemaToolbar,{zoom:a.zoom,onZoomIn:Le,onZoomOut:Xe,onResetView:Ye,onFitToContent:$,onAddTable:Gt,onExportJSON:xe,onImportJSON:Me,onExportSQL:Ht,onUndo:Fe,onRedo:Ce,canUndo:Nt,canRedo:At,onAutoLayout:Pt,disabled:b,labels:H}),Ue&&(0,R.jsx)(pt.SchemaLegend,{labels:H}),(0,R.jsx)(bt.SchemaRelationRenderer,{relations:B,tables:y,viewport:a,selectedRelationId:ee,disabled:b,editable:w,onRelationClick:Mt,onCardinalityChange:Vt}),(0,R.jsx)("div",{style:$t,children:Qt.map(e=>(0,R.jsx)(ht.SchemaTableRenderer,{table:e,selected:Z===e.id,disabled:b,readOnly:L,editable:ke,dropTarget:Je!==null&&Je!==e.id&&!e.collapsed,fieldTypes:q,onTableNameChange:_t,onTableNotesChange:Ut,onToggleCollapse:Bt,onFieldChange:Jt,onFieldAdd:Kt,onFieldRemove:De,onFieldReorder:Ot,onResizeStart:Wt,labels:H},e.id))}),F&&(0,R.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,R.jsx)("path",{d:(0,u.computeBezierPath)(F.fromX*a.zoom+a.x,F.fromY*a.zoom+a.y,F.currentX*a.zoom+a.x,F.currentY*a.zoom+a.y),fill:"none",stroke:"#3b82f6",strokeWidth:2.5,strokeDasharray:"8 4"}),(0,R.jsx)("circle",{cx:F.fromX*a.zoom+a.x,cy:F.fromY*a.zoom+a.y,r:5,fill:"#3b82f6"}),(0,R.jsx)("circle",{cx:F.currentX*a.zoom+a.x,cy:F.currentY*a.zoom+a.y,r:4,fill:"#3b82f6",opacity:.6})]}),Ue&&Ie.width>0&&(0,R.jsx)(yt.SchemaMinimap,{tables:y,viewport:a,containerWidth:Ie.width,containerHeight:Ie.height,editable:w,onViewportChange:T})]})}var Rt=(0,n.forwardRef)(un);Rt.displayName="SchemaEditor";0&&(module.exports={SchemaEditor});
|
|
1
|
+
"use strict";"use client";var Ve=Object.defineProperty;var qt=Object.getOwnPropertyDescriptor;var Zt=Object.getOwnPropertyNames;var en=Object.prototype.hasOwnProperty;var tn=(h,p)=>{for(var X in p)Ve(h,X,{get:p[X],enumerable:!0})},nn=(h,p,X,j)=>{if(p&&typeof p=="object"||typeof p=="function")for(let z of Zt(p))!en.call(h,z)&&z!==X&&Ve(h,z,{get:()=>p[z],enumerable:!(j=qt(p,z))||j.enumerable});return h};var rn=h=>nn(Ve({},"__esModule",{value:!0}),h);var dn={};tn(dn,{SchemaEditor:()=>Rt});module.exports=rn(dn);var n=require("react"),D=require("../../lib/canvas-events.cjs"),ut=require("../../lib/cn.cjs"),dt=require("../../lib/editable-target.cjs"),me=require("../../lib/i18n.cjs"),ft=require("../../lib/owner-document.cjs"),mt=require("./canvas/GridLayer.cjs"),ht=require("./tables/SchemaTableRenderer.cjs"),bt=require("./relations/SchemaRelationRenderer.cjs"),gt=require("./toolbar/SchemaToolbar.cjs"),pt=require("./legend/SchemaLegend.cjs"),yt=require("./minimap/SchemaMinimap.cjs"),u=require("./utils/geometry.cjs"),x=require("./utils/schema-helpers.cjs"),He=require("./utils/sql-export.cjs"),vt=require("./utils/import.cjs"),It=require("./utils/auto-layout.cjs"),E=require("./utils/foreign-keys.cjs"),R=require("react/jsx-runtime"),Ne={x:0,y:0,zoom:1},Ae=.1,on=.1,an=3,sn=20,ln=50;function cn(h,p){return h.tables===p.tables&&h.relations===p.relations?!0:JSON.stringify([h.tables,h.relations])===JSON.stringify([p.tables,p.relations])}function un({value:h,defaultValue:p,onValueChange:X,fieldTypes:j=x.DEFAULT_FIELD_TYPES,onTableClick:z,onTableDoubleClick:he,onTableContextMenu:be,onFieldClick:ge,onFieldDoubleClick:pe,readOnly:L=!1,disabled:b=!1,draggableTables:Pe=!0,panOnDrag:Oe=!0,zoomOnWheel:St=!0,editable:ke=!0,minZoom:Y=on,maxZoom:M=an,snapToGrid:_e=!1,gridSize:ye=sn,showGrid:Et=!0,toolbar:Tt=!0,legend:Ue=!0,autoFit:Be=!1,labels:wt,className:zt},Ft){let H=(0,me.useUILabels)(wt),q=h!==void 0,[Ct,Dt]=(0,n.useState)(()=>p??{tables:[],relations:[],viewport:{...Ne}}),v=q?h:Ct,y=v.tables,B=v.relations,a=v.viewport??Ne,S=(0,n.useRef)(null),P=(0,n.useRef)(null),[Z,J]=(0,n.useState)(null),[ee,K]=(0,n.useState)(null),[F,ve]=(0,n.useState)(null),[Je,Ke]=(0,n.useState)(null),[Ie,We]=(0,n.useState)({width:0,height:0}),w=ke&&!L&&!b,Ge=(0,n.useRef)(v),V=(0,n.useRef)(v),[te]=(0,n.useState)(()=>new WeakSet),O=(0,n.useRef)([v]),C=(0,n.useRef)(0),[,Qe]=(0,n.useReducer)(e=>e+1,0),W=(0,n.useRef)(!1);q&&(!te.has(h)&&!cn(h,V.current)&&(O.current=[h],C.current=0),V.current=h),te.add(v),Ge.current=v;let ne=(0,n.useRef)(a);ne.current=a;let $e=(0,n.useRef)(y);$e.current=y;let je=(0,n.useRef)(B);je.current=B;let qe=(0,n.useRef)(_e);qe.current=_e;let Re=(0,n.useRef)(ye);Re.current=ye;let Se=(0,n.useRef)(w);Se.current=w;let re=(0,n.useCallback)(e=>{let t=O.current[C.current];if(t&&t.tables===e.tables&&t.relations===e.relations)return;let r=O.current.slice(0,C.current+1);r.push(e),r.length>ln&&r.shift(),O.current=r,C.current=r.length-1,Qe()},[]),Ze=(0,n.useRef)(X);Ze.current=X;let Ee=(0,n.useRef)(!1),oe=(0,n.useCallback)(e=>{V.current=e,te.add(e),q?Ee.current||(Ee.current=!0,queueMicrotask(()=>{Ee.current=!1,V.current=Ge.current})):Dt(e),Ze.current?.(e)},[q,te]),l=(0,n.useCallback)((e,t=!0)=>{let r=V.current,o=e(r);return o===r?!1:(oe(o),t&&re(o),!0)},[oe,re]),ie=(0,n.useRef)(l);ie.current=l;let T=(0,n.useCallback)(e=>{l(t=>({...t,viewport:e}),!1)},[l]),et=(0,n.useRef)(T);et.current=T;let G=(0,n.useRef)(null),Q=(0,n.useRef)(null),k=(0,n.useCallback)(()=>{Q.current?.(),Q.current=null;let e=P.current;P.current=null,G.current=null,e?.type==="relation"&&(ve(null),Ke(null)),(e?.type==="table"||e?.type==="resize")&&W.current&&re(V.current),W.current=!1},[re]),tt=(0,n.useCallback)((e,t,r,o)=>{let s=ne.current,i=(0,u.screenToCanvas)(e,t,s,r),g=1/0,d=null,f=null;for(let c of o){if(c.collapsed||c.fields.length===0)continue;let m=c.width??u.DEFAULT_TABLE_WIDTH,N=(0,u.getTableHeight)(c,Se.current),A=(0,u.hasNotesRow)(c,Se.current),de=40;if(!(i.x<c.x-de||i.x>c.x+m+de||i.y<c.y-de||i.y>c.y+N+de))for(let fe=0;fe<c.fields.length;fe++){let jt=c.y+(0,u.getFieldConnectionY)(fe,A),ct=Math.abs(i.y-jt);ct<g&&(g=ct,d=c.id,f=c.fields[fe].id)}}return d&&f?{tableId:d,fieldId:f}:null},[]),Te=(0,n.useCallback)(e=>{let t=P.current;if(!t||e.pointerId!==G.current)return;if(e.buttons===0){k();return}let r=S.current?.getBoundingClientRect();if(!r)return;let o=ne.current;if(t.type==="pan"){let s=e.clientX-t.startX,i=e.clientY-t.startY;et.current({...o,x:t.startVpX+s,y:t.startVpY+i})}if(t.type==="table"){let s=(0,u.screenToCanvas)(e.clientX,e.clientY,o,r),i=s.x-t.offsetX,g=s.y-t.offsetY;qe.current&&(i=(0,u.snapValue)(i,Re.current),g=(0,u.snapValue)(g,Re.current)),ie.current(f=>{let c=f.tables.find(I=>I.id===t.tableId);return!c||c.x===i&&c.y===g?f:{...f,tables:f.tables.map(I=>I.id===t.tableId?{...I,x:i,y:g}:I)}},!1)&&(W.current=!0)}if(t.type==="relation"){let s=(0,u.screenToCanvas)(e.clientX,e.clientY,o,r);P.current={...t,currentX:s.x,currentY:s.y},ve({fromX:t.fromX,fromY:t.fromY,currentX:s.x,currentY:s.y})}if(t.type==="resize"){let s=(e.clientX-t.startX)/o.zoom,i=(e.clientY-t.startY)/o.zoom,g=180,d=80,f=Math.max(g,t.startWidth+s),c=Math.max(d,t.startHeight+i);ie.current(m=>{let N=m.tables.find(A=>A.id===t.tableId);return!N||N.width===f&&N.height===c?m:{...m,tables:m.tables.map(A=>A.id===t.tableId?{...A,width:f,height:c}:A)}},!1)&&(W.current=!0)}},[k]),we=(0,n.useCallback)(e=>{let t=P.current;if(!(!t||e.pointerId!==G.current)){if(t.type==="relation"){let r=S.current?.getBoundingClientRect();if(r){let o=je.current,s=$e.current,i=tt(e.clientX,e.clientY,r,s);if(i&&i.tableId!==t.fromTableId&&!o.some(d=>d.from.tableId===t.fromTableId&&d.from.fieldId===t.fromFieldId&&d.to.tableId===i.tableId&&d.to.fieldId===i.fieldId)){let d=t.fromTableId,f=t.fromFieldId,c=i.tableId,I=i.fieldId;ie.current(m=>(0,E.addRelationToSchema)(m,{id:(0,x.generateRelationId)(),from:{tableId:d,fieldId:f},to:{tableId:c,fieldId:I},cardinality:"1:n"}))}}}k()}},[k,tt]),ze=(0,n.useCallback)(e=>{e.pointerId===G.current&&k()},[k]),_=(0,n.useCallback)((e,t)=>{Q.current?.(),P.current=e,G.current=t,W.current=!1;let r=(0,ft.ownerDocumentOf)(S.current);r.addEventListener("pointermove",Te),r.addEventListener("pointerup",we),r.addEventListener("pointercancel",ze),Q.current=()=>{r.removeEventListener("pointermove",Te),r.removeEventListener("pointerup",we),r.removeEventListener("pointercancel",ze)}},[Te,we,ze]);(0,n.useEffect)(()=>()=>Q.current?.(),[]),(0,D.useCanvasWheel)(S,e=>{if(!St||b)return;let t=(0,D.wheelZoomDirection)(e);if(t===null)return;e.preventDefault();let r=S.current?.getBoundingClientRect();if(!r)return;let o=e.clientX-r.left,s=e.clientY-r.top,i=(0,u.clampZoom)(a.zoom+t*Ae,Y,M),g=i/a.zoom;T({x:o-(o-a.x)*g,y:s-(s-a.y)*g,zoom:i})});let Lt=(0,n.useCallback)(e=>{if(b||!(0,D.isInCanvas)(S.current,e.target))return;let t=(0,D.isPrimaryPress)(e),r=e.target,o=r.tagName,s=o==="INPUT"||o==="SELECT"||o==="TEXTAREA"||o==="BUTTON";if(r.closest("[data-resize-handle]"))return;let i=r.closest("[data-connection-side]");if(i&&!s){if(L||!t)return;e.preventDefault();let d=i.getAttribute("data-table-id"),f=i.getAttribute("data-field-id");if(!d||!f)return;let c=y.find(N=>N.id===d);if(!c)return;let I=i.getAttribute("data-connection-side"),m=(0,u.getFieldConnectionPosition)(c,f,I,w);if(!m)return;_({type:"relation",fromTableId:d,fromFieldId:f,fromX:m.x,fromY:m.y,currentX:m.x,currentY:m.y},e.pointerId),ve({fromX:m.x,fromY:m.y,currentX:m.x,currentY:m.y}),Ke(d);return}let g=r.closest("[data-table-id]");if(g){if(L)return;let d=g.getAttribute("data-table-id");if(K(null),J(d),s||!t||r.closest('[draggable="true"]'))return;if(Pe){let f=S.current?.getBoundingClientRect();if(!f)return;let c=y.find(m=>m.id===d);if(!c||c.locked)return;let I=(0,u.screenToCanvas)(e.clientX,e.clientY,a,f);_({type:"table",tableId:d,offsetX:I.x-c.x,offsetY:I.y-c.y},e.pointerId)}return}J(null),K(null),Oe&&t&&_({type:"pan",startX:e.clientX,startY:e.clientY,startVpX:a.x,startVpY:a.y},e.pointerId)},[b,L,w,Pe,Oe,a,y,_]),U=(0,n.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 o=r.getAttribute("data-table-id");return y.find(s=>s.id===o)??null},[y]),ae=(0,n.useCallback)(e=>{let t=e.target;if(t.closest("[data-connection-side]"))return null;let r=t.closest("[data-field-id]");if(!r)return null;let o=y.find(i=>i.id===r.getAttribute("data-table-id")),s=o?.fields.find(i=>i.id===r.getAttribute("data-field-id"));return o&&s?{table:o,field:s}:null},[y]),xt=(0,n.useCallback)(e=>{if(b)return;let t=ge?ae(e):null;t&&ge?.({...t,nativeEvent:e.nativeEvent});let r=U(e);r&&z&&z({table:r,nativeEvent:e.nativeEvent})},[z,ge,b,U,ae]),Xt=(0,n.useCallback)(e=>{if(b)return;let t=pe?ae(e):null;t&&pe?.({...t,nativeEvent:e.nativeEvent});let r=U(e);r&&he&&he({table:r,nativeEvent:e.nativeEvent})},[he,pe,b,U,ae]),Yt=(0,n.useCallback)(e=>{if(b)return;let t=U(e);t&&be&&(e.preventDefault(),be({table:t,nativeEvent:e.nativeEvent}))},[be,b,U]),Mt=(0,n.useCallback)((e,t)=>{b||(t.stopPropagation(),J(null),K(e))},[b]),Vt=(0,n.useCallback)((e,t)=>{l(r=>({...r,relations:r.relations.map(o=>o.id===e?{...o,cardinality:t}:o)}))},[l]),Nt=C.current>0,At=C.current<O.current.length-1,se=(0,n.useCallback)(e=>{let t=O.current[e];if(!t)return;C.current=e;let r=V.current;oe({...r,tables:t.tables,relations:t.relations}),Qe()},[oe]),Fe=(0,n.useCallback)(()=>se(C.current-1),[se]),Ce=(0,n.useCallback)(()=>se(C.current+1),[se]),Ht=(0,n.useCallback)(()=>(0,He.generateSQL)(v),[v]),Pt=(0,n.useCallback)(()=>{l(e=>({...e,tables:(0,It.autoLayoutTables)((0,E.resolveForeignKeys)(e).tables,w)}))},[l,w]),Ot=(0,n.useCallback)((e,t,r)=>{t!==r&&l(o=>({...o,tables:o.tables.map(s=>{if(s.id!==e)return s;let i=[...s.fields],[g]=i.splice(t,1);return i.splice(r,0,g),{...s,fields:i}})}))},[l]);(0,n.useEffect)(()=>{let e=S.current;if(!e)return;if(typeof ResizeObserver>"u"){We({width:e.clientWidth,height:e.clientHeight});return}let t=new ResizeObserver(r=>{for(let o of r)We({width:o.contentRect.width,height:o.contentRect.height})});return t.observe(e),()=>t.disconnect()},[]);let le=(0,n.useCallback)(e=>{l(t=>(0,E.removeTableFromSchema)(t,e))},[l]),ce=(0,n.useCallback)(e=>{l(t=>(0,E.removeRelationFromSchema)(t,e))},[l]),kt=(0,n.useCallback)(e=>{if(!(L||b)&&(0,D.isInCanvas)(S.current,e.target)){if((e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey){e.preventDefault(),Fe();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"){if((0,dt.isEditableTarget)(e.target))return;Z&&(le(Z),J(null)),ee&&(ce(ee),K(null))}e.key==="Escape"&&(J(null),K(null))}},[L,b,Z,ee,le,ce,Fe,Ce]),_t=(0,n.useCallback)((e,t)=>{l(r=>({...r,tables:r.tables.map(o=>o.id===e?{...o,name:t}:o)}))},[l]),Ut=(0,n.useCallback)((e,t)=>{l(r=>({...r,tables:r.tables.map(o=>o.id===e?{...o,notes:t}:o)}))},[l]),Bt=(0,n.useCallback)(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e?{...r,collapsed:!r.collapsed}:r)}))},[l]),Jt=(0,n.useCallback)((e,t,r)=>{l(o=>({...o,tables:o.tables.map(s=>s.id===e?{...s,fields:s.fields.map(i=>i.id===t?{...i,...r}:i)}:s)}))},[l]),Kt=(0,n.useCallback)(e=>{l(t=>({...t,tables:t.tables.map(r=>r.id===e?{...r,fields:[...r.fields,(0,x.createDefaultField)()]}:r)}))},[l]),De=(0,n.useCallback)((e,t)=>{l(r=>(0,E.removeFieldFromSchema)(r,e,t))},[l]),Wt=(0,n.useCallback)((e,t,r,o,s,i)=>{_({type:"resize",tableId:e,startX:t,startY:r,startWidth:o,startHeight:s},i)},[_]),Le=(0,n.useCallback)(()=>{let e=(0,u.clampZoom)(a.zoom+Ae,Y,M);T({...a,zoom:e})},[a,Y,M,T]),xe=(0,n.useCallback)(()=>{let e=(0,u.clampZoom)(a.zoom-Ae,Y,M);T({...a,zoom:e})},[a,Y,M,T]),Xe=(0,n.useCallback)(()=>{T({...Ne})},[T]),$=(0,n.useCallback)(()=>{let e=S.current?.getBoundingClientRect();if(!e)return;let t=(0,u.fitViewport)(y,e.width,e.height,w),r=(0,u.clampZoom)(t.zoom,Y,M);T({...t,zoom:r})},[y,w,Y,M,T]),ue=(0,n.useCallback)(e=>{l(t=>({...t,tables:[...t.tables,e]}))},[l]),nt=(0,n.useCallback)((e,t)=>{l(r=>({...r,tables:r.tables.map(o=>o.id===e?{...o,fields:[...o.fields,t]}:o)}))},[l]),rt=(0,n.useCallback)((e,t)=>{De(e,t)},[De]),ot=(0,n.useCallback)(e=>{l(t=>(0,E.addRelationToSchema)(t,e))},[l]),Ye=(0,n.useCallback)(()=>JSON.stringify(v,null,2),[v]),Me=(0,n.useCallback)(e=>{let t=(0,vt.readSchemaJSON)(e);return t.ok?(l(()=>(0,E.resolveForeignKeys)(t.value)),null):t.reason==="json"?H.editorImportInvalidJson:(0,me.formatUILabel)(H.editorImportInvalidContent,{path:t.path})},[l,H]),it=(0,n.useCallback)(e=>Me(e)===null,[Me]),Gt=(0,n.useCallback)(()=>{let e=S.current?.getBoundingClientRect(),t=ne.current,r=100,o=100;e&&(r=(e.width/2-t.x)/t.zoom-u.DEFAULT_TABLE_WIDTH/2,o=(e.height/2-t.y)/t.zoom-60),ue((0,x.createDefaultTable)(r,o))},[ue]),at=(0,n.useCallback)(()=>(0,He.generateSQL)(v),[v]);(0,n.useImperativeHandle)(Ft,()=>({zoomIn:Le,zoomOut:xe,resetView:Xe,fitToContent:$,addTable:ue,removeTable:le,addField:nt,removeField:rt,addRelation:ot,removeRelation:ce,toJSON:Ye,loadJSON:it,toSQL:at}),[Le,xe,Xe,$,ue,le,nt,rt,ot,ce,Ye,it,at]);let st=(0,n.useRef)(!1),lt=y.length>0;(0,n.useEffect)(()=>{Be&<&&!st.current&&S.current&&(st.current=!0,$())},[Be,lt,$]);let Qt=(0,n.useMemo)(()=>(0,E.resolveForeignKeys)({tables:y,relations:B}).tables,[y,B]),$t=(0,n.useMemo)(()=>({transform:`translate(${a.x}px, ${a.y}px) scale(${a.zoom})`,transformOrigin:"0 0"}),[a.x,a.y,a.zoom]);return(0,R.jsxs)("div",{ref:S,"data-testid":"schema-editor",className:(0,ut.cn)("relative w-full overflow-hidden bg-gray-50 dark:bg-gray-900 select-none touch-none",b&&"opacity-60 pointer-events-none",zt),tabIndex:0,onPointerDown:Lt,onClick:xt,onDoubleClick:Xt,onContextMenu:Yt,onKeyDown:kt,children:[Et&&(0,R.jsx)(mt.GridLayer,{gridSize:ye,zoom:a.zoom}),Tt&&!L&&(0,R.jsx)(gt.SchemaToolbar,{zoom:a.zoom,onZoomIn:Le,onZoomOut:xe,onResetView:Xe,onFitToContent:$,onAddTable:Gt,onExportJSON:Ye,onImportJSON:Me,onExportSQL:Ht,onUndo:Fe,onRedo:Ce,canUndo:Nt,canRedo:At,onAutoLayout:Pt,disabled:b,labels:H}),Ue&&(0,R.jsx)(pt.SchemaLegend,{labels:H}),(0,R.jsx)(bt.SchemaRelationRenderer,{relations:B,tables:y,viewport:a,selectedRelationId:ee,disabled:b,editable:w,onRelationClick:Mt,onCardinalityChange:Vt}),(0,R.jsx)("div",{style:$t,children:Qt.map(e=>(0,R.jsx)(ht.SchemaTableRenderer,{table:e,selected:Z===e.id,disabled:b,readOnly:L,editable:ke,dropTarget:Je!==null&&Je!==e.id&&!e.collapsed,fieldTypes:j,onTableNameChange:_t,onTableNotesChange:Ut,onToggleCollapse:Bt,onFieldChange:Jt,onFieldAdd:Kt,onFieldRemove:De,onFieldReorder:Ot,onResizeStart:Wt,labels:H},e.id))}),F&&(0,R.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,R.jsx)("path",{d:(0,u.computeBezierPath)(F.fromX*a.zoom+a.x,F.fromY*a.zoom+a.y,F.currentX*a.zoom+a.x,F.currentY*a.zoom+a.y),fill:"none",stroke:"#3b82f6",strokeWidth:2.5,strokeDasharray:"8 4"}),(0,R.jsx)("circle",{cx:F.fromX*a.zoom+a.x,cy:F.fromY*a.zoom+a.y,r:5,fill:"#3b82f6"}),(0,R.jsx)("circle",{cx:F.currentX*a.zoom+a.x,cy:F.currentY*a.zoom+a.y,r:4,fill:"#3b82f6",opacity:.6})]}),Ue&&Ie.width>0&&(0,R.jsx)(yt.SchemaMinimap,{tables:y,viewport:a,containerWidth:Ie.width,containerHeight:Ie.height,editable:w,onViewportChange:T})]})}var Rt=(0,n.forwardRef)(un);Rt.displayName="SchemaEditor";0&&(module.exports={SchemaEditor});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{forwardRef as Kt,useCallback as o,useEffect as Ye,useImperativeHandle as Wt,useMemo as lt,useReducer as Gt,useRef as m,useState as Y}from"react";import{isInCanvas as ct,isPrimaryPress as Qt,useCanvasWheel as $t,wheelZoomDirection as qt}from"../../lib/canvas-events.js";import{cn as jt}from"../../lib/cn.js";import{isEditableTarget as Zt}from"../../lib/editable-target.js";import{formatUILabel as en,useUILabels as tn}from"../../lib/i18n.js";import{ownerDocumentOf as nn}from"../../lib/owner-document.js";import{GridLayer as rn}from"./canvas/GridLayer.js";import{SchemaTableRenderer as on}from"./tables/SchemaTableRenderer.js";import{SchemaRelationRenderer as an}from"./relations/SchemaRelationRenderer.js";import{SchemaToolbar as sn}from"./toolbar/SchemaToolbar.js";import{SchemaLegend as ln}from"./legend/SchemaLegend.js";import{SchemaMinimap as cn}from"./minimap/SchemaMinimap.js";import{clampZoom as le,computeBezierPath as un,DEFAULT_TABLE_WIDTH as ut,fitViewport as dn,getFieldConnectionPosition as fn,getFieldConnectionY as mn,getTableHeight as hn,hasNotesRow as bn,screenToCanvas as ce,snapValue as dt}from"./utils/geometry.js";import{createDefaultField as gn,createDefaultTable as pn,DEFAULT_FIELD_TYPES as yn,generateRelationId as vn}from"./utils/schema-helpers.js";import{generateSQL as ft}from"./utils/sql-export.js";import{readSchemaJSON as In}from"./utils/import.js";import{autoLayoutTables as Rn}from"./utils/auto-layout.js";import{addRelationToSchema as mt,removeFieldFromSchema as Sn,removeRelationFromSchema as En,removeTableFromSchema as Tn,resolveForeignKeys as xe}from"./utils/foreign-keys.js";import{jsx as E,jsxs as ht}from"react/jsx-runtime";var Me={x:0,y:0,zoom:1},Ve=.1,wn=.1,zn=3,Fn=20,Cn=50;function Dn(R,x){return R.tables===x.tables&&R.relations===x.relations?!0:JSON.stringify([R.tables,R.relations])===JSON.stringify([x.tables,x.relations])}function Ln({value:R,defaultValue:x,onValueChange:Ne,fieldTypes:bt=yn,onTableClick:ue,onTableDoubleClick:de,onTableContextMenu:fe,onFieldClick:me,onFieldDoubleClick:he,readOnly:z=!1,disabled:h=!1,draggableTables:Ae=!0,panOnDrag:He=!0,zoomOnWheel:gt=!0,editable:Pe=!0,minZoom:F=wn,maxZoom:C=zn,snapToGrid:Oe=!1,gridSize:be=Fn,showGrid:pt=!0,toolbar:yt=!0,legend:ke=!0,autoFit:_e=!1,labels:vt,className:It},Rt){let M=tn(vt),W=R!==void 0,[St,Et]=Y(()=>x??{tables:[],relations:[],viewport:{...Me}}),p=W?R:St,g=p.tables,O=p.relations,a=p.viewport??Me,v=m(null),V=m(null),[G,k]=Y(null),[Q,_]=Y(null),[T,ge]=Y(null),[Ue,Be]=Y(null),[pe,Je]=Y({width:0,height:0}),S=Pe&&!z&&!h,Ke=m(p),D=m(p),[$]=Y(()=>new WeakSet),N=m([p]),w=m(0),[,We]=Gt(e=>e+1,0),U=m(!1);W&&(!$.has(R)&&!Dn(R,D.current)&&(N.current=[R],w.current=0),D.current=R),$.add(p),Ke.current=p;let q=m(a);q.current=a;let Ge=m(g);Ge.current=g;let Qe=m(O);Qe.current=O;let $e=m(Oe);$e.current=Oe;let ye=m(be);ye.current=be;let ve=m(S);ve.current=S;let j=o(e=>{let t=N.current[w.current];if(t&&t.tables===e.tables&&t.relations===e.relations)return;let n=N.current.slice(0,w.current+1);n.push(e),n.length>Cn&&n.shift(),N.current=n,w.current=n.length-1,We()},[]),qe=m(Ne);qe.current=Ne;let Ie=m(!1),Z=o(e=>{D.current=e,$.add(e),W?Ie.current||(Ie.current=!0,queueMicrotask(()=>{Ie.current=!1,D.current=Ke.current})):Et(e),qe.current?.(e)},[W,$]),l=o((e,t=!0)=>{let n=D.current,r=e(n);return r===n?!1:(Z(r),t&&j(r),!0)},[Z,j]),ee=m(l);ee.current=l;let I=o(e=>{l(t=>({...t,viewport:e}),!1)},[l]),je=m(I);je.current=I;let B=m(null),J=m(null),A=o(()=>{J.current?.(),J.current=null;let e=V.current;V.current=null,B.current=null,e?.type==="relation"&&(ge(null),Be(null)),(e?.type==="table"||e?.type==="resize")&&U.current&&j(D.current),U.current=!1},[j]),Ze=o((e,t,n,r)=>{let s=q.current,i=ce(e,t,s,n),b=1/0,u=null,d=null;for(let c of r){if(c.collapsed||c.fields.length===0)continue;let f=c.width??ut,L=hn(c,ve.current),X=bn(c,ve.current),ae=40;if(!(i.x<c.x-ae||i.x>c.x+f+ae||i.y<c.y-ae||i.y>c.y+L+ae))for(let se=0;se<c.fields.length;se++){let Jt=c.y+mn(se,X),st=Math.abs(i.y-Jt);st<b&&(b=st,u=c.id,d=c.fields[se].id)}}return u&&d?{tableId:u,fieldId:d}:null},[]),Re=o(e=>{let t=V.current;if(!t||e.pointerId!==B.current)return;if(e.buttons===0){A();return}let n=v.current?.getBoundingClientRect();if(!n)return;let r=q.current;if(t.type==="pan"){let s=e.clientX-t.startX,i=e.clientY-t.startY;je.current({...r,x:t.startVpX+s,y:t.startVpY+i})}if(t.type==="table"){let s=ce(e.clientX,e.clientY,r,n),i=s.x-t.offsetX,b=s.y-t.offsetY;$e.current&&(i=dt(i,ye.current),b=dt(b,ye.current)),ee.current(d=>{let c=d.tables.find(y=>y.id===t.tableId);return!c||c.x===i&&c.y===b?d:{...d,tables:d.tables.map(y=>y.id===t.tableId?{...y,x:i,y:b}:y)}},!1)&&(U.current=!0)}if(t.type==="relation"){let s=ce(e.clientX,e.clientY,r,n);V.current={...t,currentX:s.x,currentY:s.y},ge({fromX:t.fromX,fromY:t.fromY,currentX:s.x,currentY:s.y})}if(t.type==="resize"){let s=(e.clientX-t.startX)/r.zoom,i=(e.clientY-t.startY)/r.zoom,b=180,u=80,d=Math.max(b,t.startWidth+s),c=Math.max(u,t.startHeight+i);ee.current(f=>{let L=f.tables.find(X=>X.id===t.tableId);return!L||L.width===d&&L.height===c?f:{...f,tables:f.tables.map(X=>X.id===t.tableId?{...X,width:d,height:c}:X)}},!1)&&(U.current=!0)}},[A]),Se=o(e=>{let t=V.current;if(!(!t||e.pointerId!==B.current)){if(t.type==="relation"){let n=v.current?.getBoundingClientRect();if(n){let r=Qe.current,s=Ge.current,i=Ze(e.clientX,e.clientY,n,s);if(i&&i.tableId!==t.fromTableId&&!r.some(u=>u.from.tableId===t.fromTableId&&u.from.fieldId===t.fromFieldId&&u.to.tableId===i.tableId&&u.to.fieldId===i.fieldId)){let u=t.fromTableId,d=t.fromFieldId,c=i.tableId,y=i.fieldId;ee.current(f=>mt(f,{id:vn(),from:{tableId:u,fieldId:d},to:{tableId:c,fieldId:y},cardinality:"1:n"}))}}}A()}},[A,Ze]),Ee=o(e=>{e.pointerId===B.current&&A()},[A]),H=o((e,t)=>{J.current?.(),V.current=e,B.current=t,U.current=!1;let n=nn(v.current);n.addEventListener("pointermove",Re),n.addEventListener("pointerup",Se),n.addEventListener("pointercancel",Ee),J.current=()=>{n.removeEventListener("pointermove",Re),n.removeEventListener("pointerup",Se),n.removeEventListener("pointercancel",Ee)}},[Re,Se,Ee]);Ye(()=>()=>J.current?.(),[]),$t(v,e=>{if(!gt||h)return;let t=qt(e);if(t===null)return;e.preventDefault();let n=v.current?.getBoundingClientRect();if(!n)return;let r=e.clientX-n.left,s=e.clientY-n.top,i=le(a.zoom+t*Ve,F,C),b=i/a.zoom;I({x:r-(r-a.x)*b,y:s-(s-a.y)*b,zoom:i})});let Tt=o(e=>{if(h||!ct(v.current,e.target))return;let t=Qt(e),n=e.target,r=n.tagName,s=r==="INPUT"||r==="SELECT"||r==="TEXTAREA"||r==="BUTTON";if(n.closest("[data-resize-handle]"))return;let i=n.closest("[data-connection-side]");if(i&&!s){if(z||!t)return;e.preventDefault();let u=i.getAttribute("data-table-id"),d=i.getAttribute("data-field-id");if(!u||!d)return;let c=g.find(L=>L.id===u);if(!c)return;let y=i.getAttribute("data-connection-side"),f=fn(c,d,y,S);if(!f)return;H({type:"relation",fromTableId:u,fromFieldId:d,fromX:f.x,fromY:f.y,currentX:f.x,currentY:f.y},e.pointerId),ge({fromX:f.x,fromY:f.y,currentX:f.x,currentY:f.y}),Be(u);return}let b=n.closest("[data-table-id]");if(b){if(z)return;let u=b.getAttribute("data-table-id");if(_(null),k(u),s||!t||n.closest('[draggable="true"]'))return;if(Ae){let d=v.current?.getBoundingClientRect();if(!d)return;let c=g.find(f=>f.id===u);if(!c||c.locked)return;let y=ce(e.clientX,e.clientY,a,d);H({type:"table",tableId:u,offsetX:y.x-c.x,offsetY:y.y-c.y},e.pointerId)}return}k(null),_(null),He&&t&&H({type:"pan",startX:e.clientX,startY:e.clientY,startVpX:a.x,startVpY:a.y},e.pointerId)},[h,z,S,Ae,He,a,g,H]),P=o(e=>{let t=e.target;if(t.closest("[data-connection-side]"))return null;let n=t.closest("[data-table-id]");if(!n)return null;let r=n.getAttribute("data-table-id");return g.find(s=>s.id===r)??null},[g]),te=o(e=>{let t=e.target;if(t.closest("[data-connection-side]"))return null;let n=t.closest("[data-field-id]");if(!n)return null;let r=g.find(i=>i.id===n.getAttribute("data-table-id")),s=r?.fields.find(i=>i.id===n.getAttribute("data-field-id"));return r&&s?{table:r,field:s}:null},[g]),wt=o(e=>{if(h)return;let t=me?te(e):null;t&&me?.({...t,nativeEvent:e.nativeEvent});let n=P(e);n&&ue&&ue({table:n,nativeEvent:e.nativeEvent})},[ue,me,h,P,te]),zt=o(e=>{if(h)return;let t=he?te(e):null;t&&he?.({...t,nativeEvent:e.nativeEvent});let n=P(e);n&&de&&de({table:n,nativeEvent:e.nativeEvent})},[de,he,h,P,te]),Ft=o(e=>{if(h)return;let t=P(e);t&&fe&&(e.preventDefault(),fe({table:t,nativeEvent:e.nativeEvent}))},[fe,h,P]),Ct=o((e,t)=>{h||(t.stopPropagation(),k(null),_(e))},[h]),Dt=o((e,t)=>{l(n=>({...n,relations:n.relations.map(r=>r.id===e?{...r,cardinality:t}:r)}))},[l]),Lt=w.current>0,Xt=w.current<N.current.length-1,ne=o(e=>{let t=N.current[e];if(!t)return;w.current=e;let n=D.current;Z({...n,tables:t.tables,relations:t.relations}),We()},[Z]),Te=o(()=>ne(w.current-1),[ne]),we=o(()=>ne(w.current+1),[ne]),Yt=o(()=>ft(p),[p]),xt=o(()=>{l(e=>({...e,tables:Rn(xe(e).tables,S)}))},[l,S]),Mt=o((e,t,n)=>{t!==n&&l(r=>({...r,tables:r.tables.map(s=>{if(s.id!==e)return s;let i=[...s.fields],[b]=i.splice(t,1);return i.splice(n,0,b),{...s,fields:i}})}))},[l]);Ye(()=>{let e=v.current;if(!e)return;if(typeof ResizeObserver>"u"){Je({width:e.clientWidth,height:e.clientHeight});return}let t=new ResizeObserver(n=>{for(let r of n)Je({width:r.contentRect.width,height:r.contentRect.height})});return t.observe(e),()=>t.disconnect()},[]);let re=o(e=>{l(t=>Tn(t,e))},[l]),oe=o(e=>{l(t=>En(t,e))},[l]),Vt=o(e=>{if(!(z||h)&&ct(v.current,e.target)){if((e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey){e.preventDefault(),Te();return}if((e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey)){e.preventDefault(),we();return}if(e.key==="Delete"||e.key==="Backspace"){if(Zt(e.target))return;G&&(re(G),k(null)),Q&&(oe(Q),_(null))}e.key==="Escape"&&(k(null),_(null))}},[z,h,G,Q,re,oe,Te,we]),Nt=o((e,t)=>{l(n=>({...n,tables:n.tables.map(r=>r.id===e?{...r,name:t}:r)}))},[l]),At=o((e,t)=>{l(n=>({...n,tables:n.tables.map(r=>r.id===e?{...r,notes:t}:r)}))},[l]),Ht=o(e=>{l(t=>({...t,tables:t.tables.map(n=>n.id===e?{...n,collapsed:!n.collapsed}:n)}))},[l]),Pt=o((e,t,n)=>{l(r=>({...r,tables:r.tables.map(s=>s.id===e?{...s,fields:s.fields.map(i=>i.id===t?{...i,...n}:i)}:s)}))},[l]),Ot=o(e=>{l(t=>({...t,tables:t.tables.map(n=>n.id===e?{...n,fields:[...n.fields,gn()]}:n)}))},[l]),ze=o((e,t)=>{l(n=>Sn(n,e,t))},[l]),kt=o((e,t,n,r,s,i)=>{H({type:"resize",tableId:e,startX:t,startY:n,startWidth:r,startHeight:s},i)},[H]),Fe=o(()=>{let e=le(a.zoom+Ve,F,C);I({...a,zoom:e})},[a,F,C,I]),Ce=o(()=>{let e=le(a.zoom-Ve,F,C);I({...a,zoom:e})},[a,F,C,I]),De=o(()=>{I({...Me})},[I]),K=o(()=>{let e=v.current?.getBoundingClientRect();if(!e)return;let t=dn(g,e.width,e.height,S),n=le(t.zoom,F,C);I({...t,zoom:n})},[g,S,F,C,I]),ie=o(e=>{l(t=>({...t,tables:[...t.tables,e]}))},[l]),et=o((e,t)=>{l(n=>({...n,tables:n.tables.map(r=>r.id===e?{...r,fields:[...r.fields,t]}:r)}))},[l]),tt=o((e,t)=>{ze(e,t)},[ze]),nt=o(e=>{l(t=>mt(t,e))},[l]),Le=o(()=>JSON.stringify(p,null,2),[p]),Xe=o(e=>{let t=In(e);return t.ok?(l(()=>xe(t.value)),null):t.reason==="json"?M.editorImportInvalidJson:en(M.editorImportInvalidContent,{path:t.path})},[l,M]),rt=o(e=>Xe(e)===null,[Xe]),_t=o(()=>{let e=v.current?.getBoundingClientRect(),t=q.current,n=100,r=100;e&&(n=(e.width/2-t.x)/t.zoom-ut/2,r=(e.height/2-t.y)/t.zoom-60),ie(pn(n,r))},[ie]),ot=o(()=>ft(p),[p]);Wt(Rt,()=>({zoomIn:Fe,zoomOut:Ce,resetView:De,fitToContent:K,addTable:ie,removeTable:re,addField:et,removeField:tt,addRelation:nt,removeRelation:oe,toJSON:Le,loadJSON:rt,toSQL:ot}),[Fe,Ce,De,K,ie,re,et,tt,nt,oe,Le,rt,ot]);let it=m(!1),at=g.length>0;Ye(()=>{_e&&at&&!it.current&&v.current&&(it.current=!0,K())},[_e,at,K]);let Ut=lt(()=>xe({tables:g,relations:O}).tables,[g,O]),Bt=lt(()=>({transform:`translate(${a.x}px, ${a.y}px) scale(${a.zoom})`,transformOrigin:"0 0"}),[a.x,a.y,a.zoom]);return ht("div",{ref:v,"data-testid":"schema-editor",className:jt("relative w-full overflow-hidden bg-gray-50 dark:bg-gray-900 select-none touch-none",h&&"opacity-60 pointer-events-none",It),tabIndex:0,onPointerDown:Tt,onClick:wt,onDoubleClick:zt,onContextMenu:Ft,onKeyDown:Vt,children:[pt&&E(rn,{gridSize:be,zoom:a.zoom}),yt&&!z&&E(sn,{zoom:a.zoom,onZoomIn:Fe,onZoomOut:Ce,onResetView:De,onFitToContent:K,onAddTable:_t,onExportJSON:Le,onImportJSON:Xe,onExportSQL:Yt,onUndo:Te,onRedo:we,canUndo:Lt,canRedo:Xt,onAutoLayout:xt,disabled:h,labels:M}),ke&&E(ln,{labels:M}),E(an,{relations:O,tables:g,viewport:a,selectedRelationId:Q,disabled:h,editable:S,onRelationClick:Ct,onCardinalityChange:Dt}),E("div",{style:Bt,children:Ut.map(e=>E(on,{table:e,selected:G===e.id,disabled:h,readOnly:z,editable:Pe,dropTarget:Ue!==null&&Ue!==e.id&&!e.collapsed,fieldTypes:bt,onTableNameChange:Nt,onTableNotesChange:At,onToggleCollapse:Ht,onFieldChange:Pt,onFieldAdd:Ot,onFieldRemove:ze,onFieldReorder:Mt,onResizeStart:kt,labels:M},e.id))}),T&&ht("svg",{"data-testid":"drag-relation-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:1e3,overflow:"visible"},children:[E("path",{d:un(T.fromX*a.zoom+a.x,T.fromY*a.zoom+a.y,T.currentX*a.zoom+a.x,T.currentY*a.zoom+a.y),fill:"none",stroke:"#3b82f6",strokeWidth:2.5,strokeDasharray:"8 4"}),E("circle",{cx:T.fromX*a.zoom+a.x,cy:T.fromY*a.zoom+a.y,r:5,fill:"#3b82f6"}),E("circle",{cx:T.currentX*a.zoom+a.x,cy:T.currentY*a.zoom+a.y,r:4,fill:"#3b82f6",opacity:.6})]}),ke&&pe.width>0&&E(cn,{tables:g,viewport:a,containerWidth:pe.width,containerHeight:pe.height,editable:S,onViewportChange:I})]})}var Xn=Kt(Ln);Xn.displayName="SchemaEditor";export{Xn as SchemaEditor};
|
|
1
|
+
"use client";import{forwardRef as Kt,useCallback as o,useEffect as Xe,useImperativeHandle as Wt,useMemo as lt,useReducer as Gt,useRef as m,useState as X}from"react";import{isInCanvas as ct,isPrimaryPress as Qt,useCanvasWheel as $t,wheelZoomDirection as jt}from"../../lib/canvas-events.js";import{cn as qt}from"../../lib/cn.js";import{isEditableTarget as Zt}from"../../lib/editable-target.js";import{formatUILabel as en,useUILabels as tn}from"../../lib/i18n.js";import{ownerDocumentOf as nn}from"../../lib/owner-document.js";import{GridLayer as rn}from"./canvas/GridLayer.js";import{SchemaTableRenderer as on}from"./tables/SchemaTableRenderer.js";import{SchemaRelationRenderer as an}from"./relations/SchemaRelationRenderer.js";import{SchemaToolbar as sn}from"./toolbar/SchemaToolbar.js";import{SchemaLegend as ln}from"./legend/SchemaLegend.js";import{SchemaMinimap as cn}from"./minimap/SchemaMinimap.js";import{clampZoom as le,computeBezierPath as un,DEFAULT_TABLE_WIDTH as ut,fitViewport as dn,getFieldConnectionPosition as fn,getFieldConnectionY as mn,getTableHeight as hn,hasNotesRow as bn,screenToCanvas as ce,snapValue as dt}from"./utils/geometry.js";import{createDefaultField as gn,createDefaultTable as pn,DEFAULT_FIELD_TYPES as yn,generateRelationId as vn}from"./utils/schema-helpers.js";import{generateSQL as ft}from"./utils/sql-export.js";import{readSchemaJSON as In}from"./utils/import.js";import{autoLayoutTables as Rn}from"./utils/auto-layout.js";import{addRelationToSchema as mt,removeFieldFromSchema as Sn,removeRelationFromSchema as En,removeTableFromSchema as Tn,resolveForeignKeys as Ye}from"./utils/foreign-keys.js";import{jsx as E,jsxs as ht}from"react/jsx-runtime";var Me={x:0,y:0,zoom:1},Ve=.1,wn=.1,zn=3,Fn=20,Cn=50;function Dn(R,Y){return R.tables===Y.tables&&R.relations===Y.relations?!0:JSON.stringify([R.tables,R.relations])===JSON.stringify([Y.tables,Y.relations])}function Ln({value:R,defaultValue:Y,onValueChange:Ne,fieldTypes:bt=yn,onTableClick:ue,onTableDoubleClick:de,onTableContextMenu:fe,onFieldClick:me,onFieldDoubleClick:he,readOnly:z=!1,disabled:h=!1,draggableTables:Ae=!0,panOnDrag:He=!0,zoomOnWheel:gt=!0,editable:Pe=!0,minZoom:F=wn,maxZoom:C=zn,snapToGrid:Oe=!1,gridSize:be=Fn,showGrid:pt=!0,toolbar:yt=!0,legend:ke=!0,autoFit:_e=!1,labels:vt,className:It},Rt){let M=tn(vt),W=R!==void 0,[St,Et]=X(()=>Y??{tables:[],relations:[],viewport:{...Me}}),p=W?R:St,g=p.tables,O=p.relations,a=p.viewport??Me,v=m(null),V=m(null),[G,k]=X(null),[Q,_]=X(null),[T,ge]=X(null),[Ue,Be]=X(null),[pe,Je]=X({width:0,height:0}),S=Pe&&!z&&!h,Ke=m(p),D=m(p),[$]=X(()=>new WeakSet),N=m([p]),w=m(0),[,We]=Gt(e=>e+1,0),U=m(!1);W&&(!$.has(R)&&!Dn(R,D.current)&&(N.current=[R],w.current=0),D.current=R),$.add(p),Ke.current=p;let j=m(a);j.current=a;let Ge=m(g);Ge.current=g;let Qe=m(O);Qe.current=O;let $e=m(Oe);$e.current=Oe;let ye=m(be);ye.current=be;let ve=m(S);ve.current=S;let q=o(e=>{let t=N.current[w.current];if(t&&t.tables===e.tables&&t.relations===e.relations)return;let n=N.current.slice(0,w.current+1);n.push(e),n.length>Cn&&n.shift(),N.current=n,w.current=n.length-1,We()},[]),je=m(Ne);je.current=Ne;let Ie=m(!1),Z=o(e=>{D.current=e,$.add(e),W?Ie.current||(Ie.current=!0,queueMicrotask(()=>{Ie.current=!1,D.current=Ke.current})):Et(e),je.current?.(e)},[W,$]),l=o((e,t=!0)=>{let n=D.current,r=e(n);return r===n?!1:(Z(r),t&&q(r),!0)},[Z,q]),ee=m(l);ee.current=l;let I=o(e=>{l(t=>({...t,viewport:e}),!1)},[l]),qe=m(I);qe.current=I;let B=m(null),J=m(null),A=o(()=>{J.current?.(),J.current=null;let e=V.current;V.current=null,B.current=null,e?.type==="relation"&&(ge(null),Be(null)),(e?.type==="table"||e?.type==="resize")&&U.current&&q(D.current),U.current=!1},[q]),Ze=o((e,t,n,r)=>{let s=j.current,i=ce(e,t,s,n),b=1/0,u=null,d=null;for(let c of r){if(c.collapsed||c.fields.length===0)continue;let f=c.width??ut,L=hn(c,ve.current),x=bn(c,ve.current),ae=40;if(!(i.x<c.x-ae||i.x>c.x+f+ae||i.y<c.y-ae||i.y>c.y+L+ae))for(let se=0;se<c.fields.length;se++){let Jt=c.y+mn(se,x),st=Math.abs(i.y-Jt);st<b&&(b=st,u=c.id,d=c.fields[se].id)}}return u&&d?{tableId:u,fieldId:d}:null},[]),Re=o(e=>{let t=V.current;if(!t||e.pointerId!==B.current)return;if(e.buttons===0){A();return}let n=v.current?.getBoundingClientRect();if(!n)return;let r=j.current;if(t.type==="pan"){let s=e.clientX-t.startX,i=e.clientY-t.startY;qe.current({...r,x:t.startVpX+s,y:t.startVpY+i})}if(t.type==="table"){let s=ce(e.clientX,e.clientY,r,n),i=s.x-t.offsetX,b=s.y-t.offsetY;$e.current&&(i=dt(i,ye.current),b=dt(b,ye.current)),ee.current(d=>{let c=d.tables.find(y=>y.id===t.tableId);return!c||c.x===i&&c.y===b?d:{...d,tables:d.tables.map(y=>y.id===t.tableId?{...y,x:i,y:b}:y)}},!1)&&(U.current=!0)}if(t.type==="relation"){let s=ce(e.clientX,e.clientY,r,n);V.current={...t,currentX:s.x,currentY:s.y},ge({fromX:t.fromX,fromY:t.fromY,currentX:s.x,currentY:s.y})}if(t.type==="resize"){let s=(e.clientX-t.startX)/r.zoom,i=(e.clientY-t.startY)/r.zoom,b=180,u=80,d=Math.max(b,t.startWidth+s),c=Math.max(u,t.startHeight+i);ee.current(f=>{let L=f.tables.find(x=>x.id===t.tableId);return!L||L.width===d&&L.height===c?f:{...f,tables:f.tables.map(x=>x.id===t.tableId?{...x,width:d,height:c}:x)}},!1)&&(U.current=!0)}},[A]),Se=o(e=>{let t=V.current;if(!(!t||e.pointerId!==B.current)){if(t.type==="relation"){let n=v.current?.getBoundingClientRect();if(n){let r=Qe.current,s=Ge.current,i=Ze(e.clientX,e.clientY,n,s);if(i&&i.tableId!==t.fromTableId&&!r.some(u=>u.from.tableId===t.fromTableId&&u.from.fieldId===t.fromFieldId&&u.to.tableId===i.tableId&&u.to.fieldId===i.fieldId)){let u=t.fromTableId,d=t.fromFieldId,c=i.tableId,y=i.fieldId;ee.current(f=>mt(f,{id:vn(),from:{tableId:u,fieldId:d},to:{tableId:c,fieldId:y},cardinality:"1:n"}))}}}A()}},[A,Ze]),Ee=o(e=>{e.pointerId===B.current&&A()},[A]),H=o((e,t)=>{J.current?.(),V.current=e,B.current=t,U.current=!1;let n=nn(v.current);n.addEventListener("pointermove",Re),n.addEventListener("pointerup",Se),n.addEventListener("pointercancel",Ee),J.current=()=>{n.removeEventListener("pointermove",Re),n.removeEventListener("pointerup",Se),n.removeEventListener("pointercancel",Ee)}},[Re,Se,Ee]);Xe(()=>()=>J.current?.(),[]),$t(v,e=>{if(!gt||h)return;let t=jt(e);if(t===null)return;e.preventDefault();let n=v.current?.getBoundingClientRect();if(!n)return;let r=e.clientX-n.left,s=e.clientY-n.top,i=le(a.zoom+t*Ve,F,C),b=i/a.zoom;I({x:r-(r-a.x)*b,y:s-(s-a.y)*b,zoom:i})});let Tt=o(e=>{if(h||!ct(v.current,e.target))return;let t=Qt(e),n=e.target,r=n.tagName,s=r==="INPUT"||r==="SELECT"||r==="TEXTAREA"||r==="BUTTON";if(n.closest("[data-resize-handle]"))return;let i=n.closest("[data-connection-side]");if(i&&!s){if(z||!t)return;e.preventDefault();let u=i.getAttribute("data-table-id"),d=i.getAttribute("data-field-id");if(!u||!d)return;let c=g.find(L=>L.id===u);if(!c)return;let y=i.getAttribute("data-connection-side"),f=fn(c,d,y,S);if(!f)return;H({type:"relation",fromTableId:u,fromFieldId:d,fromX:f.x,fromY:f.y,currentX:f.x,currentY:f.y},e.pointerId),ge({fromX:f.x,fromY:f.y,currentX:f.x,currentY:f.y}),Be(u);return}let b=n.closest("[data-table-id]");if(b){if(z)return;let u=b.getAttribute("data-table-id");if(_(null),k(u),s||!t||n.closest('[draggable="true"]'))return;if(Ae){let d=v.current?.getBoundingClientRect();if(!d)return;let c=g.find(f=>f.id===u);if(!c||c.locked)return;let y=ce(e.clientX,e.clientY,a,d);H({type:"table",tableId:u,offsetX:y.x-c.x,offsetY:y.y-c.y},e.pointerId)}return}k(null),_(null),He&&t&&H({type:"pan",startX:e.clientX,startY:e.clientY,startVpX:a.x,startVpY:a.y},e.pointerId)},[h,z,S,Ae,He,a,g,H]),P=o(e=>{let t=e.target;if(t.closest("[data-connection-side]"))return null;let n=t.closest("[data-table-id]");if(!n)return null;let r=n.getAttribute("data-table-id");return g.find(s=>s.id===r)??null},[g]),te=o(e=>{let t=e.target;if(t.closest("[data-connection-side]"))return null;let n=t.closest("[data-field-id]");if(!n)return null;let r=g.find(i=>i.id===n.getAttribute("data-table-id")),s=r?.fields.find(i=>i.id===n.getAttribute("data-field-id"));return r&&s?{table:r,field:s}:null},[g]),wt=o(e=>{if(h)return;let t=me?te(e):null;t&&me?.({...t,nativeEvent:e.nativeEvent});let n=P(e);n&&ue&&ue({table:n,nativeEvent:e.nativeEvent})},[ue,me,h,P,te]),zt=o(e=>{if(h)return;let t=he?te(e):null;t&&he?.({...t,nativeEvent:e.nativeEvent});let n=P(e);n&&de&&de({table:n,nativeEvent:e.nativeEvent})},[de,he,h,P,te]),Ft=o(e=>{if(h)return;let t=P(e);t&&fe&&(e.preventDefault(),fe({table:t,nativeEvent:e.nativeEvent}))},[fe,h,P]),Ct=o((e,t)=>{h||(t.stopPropagation(),k(null),_(e))},[h]),Dt=o((e,t)=>{l(n=>({...n,relations:n.relations.map(r=>r.id===e?{...r,cardinality:t}:r)}))},[l]),Lt=w.current>0,xt=w.current<N.current.length-1,ne=o(e=>{let t=N.current[e];if(!t)return;w.current=e;let n=D.current;Z({...n,tables:t.tables,relations:t.relations}),We()},[Z]),Te=o(()=>ne(w.current-1),[ne]),we=o(()=>ne(w.current+1),[ne]),Xt=o(()=>ft(p),[p]),Yt=o(()=>{l(e=>({...e,tables:Rn(Ye(e).tables,S)}))},[l,S]),Mt=o((e,t,n)=>{t!==n&&l(r=>({...r,tables:r.tables.map(s=>{if(s.id!==e)return s;let i=[...s.fields],[b]=i.splice(t,1);return i.splice(n,0,b),{...s,fields:i}})}))},[l]);Xe(()=>{let e=v.current;if(!e)return;if(typeof ResizeObserver>"u"){Je({width:e.clientWidth,height:e.clientHeight});return}let t=new ResizeObserver(n=>{for(let r of n)Je({width:r.contentRect.width,height:r.contentRect.height})});return t.observe(e),()=>t.disconnect()},[]);let re=o(e=>{l(t=>Tn(t,e))},[l]),oe=o(e=>{l(t=>En(t,e))},[l]),Vt=o(e=>{if(!(z||h)&&ct(v.current,e.target)){if((e.ctrlKey||e.metaKey)&&e.key==="z"&&!e.shiftKey){e.preventDefault(),Te();return}if((e.ctrlKey||e.metaKey)&&(e.key==="y"||e.key==="z"&&e.shiftKey)){e.preventDefault(),we();return}if(e.key==="Delete"||e.key==="Backspace"){if(Zt(e.target))return;G&&(re(G),k(null)),Q&&(oe(Q),_(null))}e.key==="Escape"&&(k(null),_(null))}},[z,h,G,Q,re,oe,Te,we]),Nt=o((e,t)=>{l(n=>({...n,tables:n.tables.map(r=>r.id===e?{...r,name:t}:r)}))},[l]),At=o((e,t)=>{l(n=>({...n,tables:n.tables.map(r=>r.id===e?{...r,notes:t}:r)}))},[l]),Ht=o(e=>{l(t=>({...t,tables:t.tables.map(n=>n.id===e?{...n,collapsed:!n.collapsed}:n)}))},[l]),Pt=o((e,t,n)=>{l(r=>({...r,tables:r.tables.map(s=>s.id===e?{...s,fields:s.fields.map(i=>i.id===t?{...i,...n}:i)}:s)}))},[l]),Ot=o(e=>{l(t=>({...t,tables:t.tables.map(n=>n.id===e?{...n,fields:[...n.fields,gn()]}:n)}))},[l]),ze=o((e,t)=>{l(n=>Sn(n,e,t))},[l]),kt=o((e,t,n,r,s,i)=>{H({type:"resize",tableId:e,startX:t,startY:n,startWidth:r,startHeight:s},i)},[H]),Fe=o(()=>{let e=le(a.zoom+Ve,F,C);I({...a,zoom:e})},[a,F,C,I]),Ce=o(()=>{let e=le(a.zoom-Ve,F,C);I({...a,zoom:e})},[a,F,C,I]),De=o(()=>{I({...Me})},[I]),K=o(()=>{let e=v.current?.getBoundingClientRect();if(!e)return;let t=dn(g,e.width,e.height,S),n=le(t.zoom,F,C);I({...t,zoom:n})},[g,S,F,C,I]),ie=o(e=>{l(t=>({...t,tables:[...t.tables,e]}))},[l]),et=o((e,t)=>{l(n=>({...n,tables:n.tables.map(r=>r.id===e?{...r,fields:[...r.fields,t]}:r)}))},[l]),tt=o((e,t)=>{ze(e,t)},[ze]),nt=o(e=>{l(t=>mt(t,e))},[l]),Le=o(()=>JSON.stringify(p,null,2),[p]),xe=o(e=>{let t=In(e);return t.ok?(l(()=>Ye(t.value)),null):t.reason==="json"?M.editorImportInvalidJson:en(M.editorImportInvalidContent,{path:t.path})},[l,M]),rt=o(e=>xe(e)===null,[xe]),_t=o(()=>{let e=v.current?.getBoundingClientRect(),t=j.current,n=100,r=100;e&&(n=(e.width/2-t.x)/t.zoom-ut/2,r=(e.height/2-t.y)/t.zoom-60),ie(pn(n,r))},[ie]),ot=o(()=>ft(p),[p]);Wt(Rt,()=>({zoomIn:Fe,zoomOut:Ce,resetView:De,fitToContent:K,addTable:ie,removeTable:re,addField:et,removeField:tt,addRelation:nt,removeRelation:oe,toJSON:Le,loadJSON:rt,toSQL:ot}),[Fe,Ce,De,K,ie,re,et,tt,nt,oe,Le,rt,ot]);let it=m(!1),at=g.length>0;Xe(()=>{_e&&at&&!it.current&&v.current&&(it.current=!0,K())},[_e,at,K]);let Ut=lt(()=>Ye({tables:g,relations:O}).tables,[g,O]),Bt=lt(()=>({transform:`translate(${a.x}px, ${a.y}px) scale(${a.zoom})`,transformOrigin:"0 0"}),[a.x,a.y,a.zoom]);return ht("div",{ref:v,"data-testid":"schema-editor",className:qt("relative w-full overflow-hidden bg-gray-50 dark:bg-gray-900 select-none touch-none",h&&"opacity-60 pointer-events-none",It),tabIndex:0,onPointerDown:Tt,onClick:wt,onDoubleClick:zt,onContextMenu:Ft,onKeyDown:Vt,children:[pt&&E(rn,{gridSize:be,zoom:a.zoom}),yt&&!z&&E(sn,{zoom:a.zoom,onZoomIn:Fe,onZoomOut:Ce,onResetView:De,onFitToContent:K,onAddTable:_t,onExportJSON:Le,onImportJSON:xe,onExportSQL:Xt,onUndo:Te,onRedo:we,canUndo:Lt,canRedo:xt,onAutoLayout:Yt,disabled:h,labels:M}),ke&&E(ln,{labels:M}),E(an,{relations:O,tables:g,viewport:a,selectedRelationId:Q,disabled:h,editable:S,onRelationClick:Ct,onCardinalityChange:Dt}),E("div",{style:Bt,children:Ut.map(e=>E(on,{table:e,selected:G===e.id,disabled:h,readOnly:z,editable:Pe,dropTarget:Ue!==null&&Ue!==e.id&&!e.collapsed,fieldTypes:bt,onTableNameChange:Nt,onTableNotesChange:At,onToggleCollapse:Ht,onFieldChange:Pt,onFieldAdd:Ot,onFieldRemove:ze,onFieldReorder:Mt,onResizeStart:kt,labels:M},e.id))}),T&&ht("svg",{"data-testid":"drag-relation-overlay",style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none",zIndex:1e3,overflow:"visible"},children:[E("path",{d:un(T.fromX*a.zoom+a.x,T.fromY*a.zoom+a.y,T.currentX*a.zoom+a.x,T.currentY*a.zoom+a.y),fill:"none",stroke:"#3b82f6",strokeWidth:2.5,strokeDasharray:"8 4"}),E("circle",{cx:T.fromX*a.zoom+a.x,cy:T.fromY*a.zoom+a.y,r:5,fill:"#3b82f6"}),E("circle",{cx:T.currentX*a.zoom+a.x,cy:T.currentY*a.zoom+a.y,r:4,fill:"#3b82f6",opacity:.6})]}),ke&&pe.width>0&&E(cn,{tables:g,viewport:a,containerWidth:pe.width,containerHeight:pe.height,editable:S,onViewportChange:I})]})}var xn=Kt(Ln);xn.displayName="SchemaEditor";export{xn as SchemaEditor};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var Ie=Object.defineProperty;var kt=Object.getOwnPropertyDescriptor;var wt=Object.getOwnPropertyNames;var Ct=Object.prototype.hasOwnProperty;var Lt=(o,s)=>{for(var a in s)Ie(o,a,{get:s[a],enumerable:!0})},Nt=(o,s,a,c)=>{if(s&&typeof s=="object"||typeof s=="function")for(let g of wt(s))!Ct.call(o,g)&&g!==a&&Ie(o,g,{get:()=>s[g],enumerable:!(c=kt(s,g))||c.enumerable});return o};var It=o=>Nt(Ie({},"__esModule",{value:!0}),o);var zt={};Lt(zt,{Select:()=>Ht});module.exports=It(zt);var r=require("react"),Xe=require("react-dom"),Ze=require("../../lib/aria-hide.cjs"),X=require("../../lib/owner-document.cjs"),j=require("../../lib/i18n.cjs"),Ge=require("../form/shared/field-error.cjs"),t=require("react/jsx-runtime"),St=[],Me=[],Q=o=>o.preventDefault(),Mt=(0,t.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,t.jsx)("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Ye=(0,t.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,t.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"})}),Et=(0,t.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,t.jsx)("path",{d:"M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),Dt=(0,t.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0 animate-spin",children:[(0,t.jsx)("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",strokeOpacity:"0.25"}),(0,t.jsx)("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),Ot=(0,t.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,t.jsx)("path",{d:"M11.5 3.5L5.5 10.5L2.5 7.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Vt=(0,t.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:(0,t.jsx)("path",{d:"M11.5 3.5L5.5 10.5L2.5 7.5",stroke:"currentColor",strokeWidth:"2.25",strokeLinecap:"round",strokeLinejoin:"round"})}),Pt=(0,t.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:(0,t.jsx)("path",{d:"M7 2.5V11.5M2.5 7H11.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})}),S={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",frame:"min-h-8 pl-1 pr-2.5 py-1 text-xs gap-1.5",tag:"h-5 pl-1.5 pr-0.5 gap-0.5 text-xs",combobox:"h-5 px-1"},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",frame:"min-h-10 pl-1.5 pr-3 py-1.5 text-sm gap-2",tag:"h-6 pl-2 pr-1 gap-1 text-xs",combobox:"h-6 px-1.5"},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",frame:"min-h-12 pl-2 pr-4 py-2 text-base gap-2.5",tag:"h-7 pl-2.5 pr-1 gap-1 text-sm",combobox:"h-7 px-2"}},Se={default:{trigger:"border border-gray-300 bg-white dark:border-gray-600 dark:bg-gray-800",focus:"focus:ring-2 focus:ring-synertech-primary-500 focus:border-synertech-primary-500"},outlined:{trigger:"border-2 border-gray-300 bg-transparent dark:border-gray-600",focus:"focus:ring-2 focus:ring-synertech-primary-500 focus:border-synertech-primary-500"},filled:{trigger:"border border-transparent bg-gray-100 dark:bg-gray-700",focus:"focus:ring-2 focus:ring-synertech-primary-500 focus:border-synertech-primary-500"}},Tt="focus-within:ring-2 focus-within:ring-synertech-primary-500 focus-within:border-synertech-primary-500",Bt="border-red-500 dark:border-red-400 focus-within:ring-2 focus-within:ring-red-500 focus-within:border-red-500";function m(...o){let s="";for(let a=0;a<o.length;a++){let c=o[a];c&&(s&&(s+=" "),s+=c)}return s}function Rt(o,s){if(!s)return o;let a=s.toLowerCase();return o.filter(c=>{if(c.label.toLowerCase().includes(a)||c.value.toLowerCase().includes(a))return!0;if(c.keywords){for(let g of c.keywords)if(g.toLowerCase().includes(a))return!0}return!1})}function Qe(o,s){if(o!==void 0)return Array.isArray(o)?s?new Set(o).size===o.length?o:Array.from(new Set(o)):o.slice(0,1):o===""?Me:[o]}function Je(o,s,a,c,g){return m(S[o].option,"flex items-center gap-2 cursor-pointer select-none transition-colors",s&&!c&&"bg-synertech-primary-50 dark:bg-synertech-primary-900/30",a&&!s&&!g&&"bg-gray-50 dark:bg-gray-700/50",c&&"opacity-50 cursor-not-allowed")}var At=(0,r.memo)((0,r.forwardRef)(function({option:s,isSelected:a,isHighlighted:c,isDisabled:g,multiple:R,sizeKey:U,optionId:ae,onClick:se,onMouseEnter:oe,index:b},v){let f=()=>{g||se(s.value)},x=()=>{g||oe(b)};return(0,t.jsxs)("div",{ref:v,id:ae,role:"option","aria-selected":a,"aria-disabled":g||void 0,"data-highlighted":c||void 0,className:Je(U,c,a,g,R),onMouseDown:Q,onClick:f,onMouseEnter:x,children:[R?(0,t.jsx)("span",{"aria-hidden":"true",className:m("flex size-4 shrink-0 items-center justify-center rounded border-2 transition-colors",a?"border-synertech-primary-600 bg-synertech-primary-600 text-synertech-on-primary":"border-gray-500 dark:border-gray-400"),children:a?Vt:null}):null,s.icon?(0,t.jsx)("span",{className:"flex shrink-0 items-center",children:s.icon}):null,(0,t.jsxs)("span",{className:"flex flex-col min-w-0 flex-1",children:[(0,t.jsx)("span",{className:"truncate",children:s.label}),s.description?(0,t.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:s.description}):null]}),a&&!R?(0,t.jsx)("span",{className:"ml-auto text-synertech-primary-600 dark:text-synertech-primary-400",children:Ot}):null]})}));function Ht(o){let{options:s=St,multiple:a=!1,value:c,defaultValue:g,onValueChange:R,maxTagCount:U,creatable:ae=!1,searchable:se=!1,clearable:oe=!1,disabled:b=!1,readOnly:v=!1,loading:f=!1,size:x="md",variant:le="default",placeholder:et,label:Z,description:Ee,helperText:De,error:tt,required:Oe=!1,noOptionsText:rt,clearLabel:Ve,searchLabel:nt,searchPlaceholder:at,labels:st,onSearchChange:Pe,name:ie,className:ot,triggerClassName:Te,contentClassName:lt,maxHeight:ce=256}=o,w=a&&ae,O=se||w,N=(0,j.useUILabels)(st),Be=et??N.selectPlaceholder,it=rt??N.selectNoOptions,A=(0,r.useId)(),de=`${A}-label`,ue=`${A}-trigger`,pe=`${A}-listbox`,h=(0,Ge.describeField)(ue,{description:Ee,helperText:De,error:tt}),y=(0,r.useRef)(null),ge=(0,r.useRef)(null),fe=(0,r.useRef)(null),he=(0,r.useRef)(null),me=(0,r.useRef)([]),Re=c!==void 0,[be,ct]=(0,r.useState)(()=>Qe(g,a)??Me),Ae=(0,r.useMemo)(()=>Qe(c,a),[c,a]),i=(0,r.useMemo)(()=>Ae??(a?be:be.slice(0,1)),[Ae,be,a]),[u,ye]=(0,r.useState)(!1),[H,z]=(0,r.useState)(""),[p,k]=(0,r.useState)(-1),[V,He]=(0,r.useState)(null),F=(0,r.useMemo)(()=>{let e=new Map;for(let n of s)e.has(n.value)||e.set(n.value,n);return e},[s]),W=(0,r.useMemo)(()=>{if(!w)return s;let e=[];for(let n of i)F.has(n)||e.push({value:n,label:n});return e.length>0?[...s,...e]:s},[w,s,i,F]),I=(0,r.useMemo)(()=>O?Rt(W,H):W,[W,H,O]),M=H.trim(),$=(0,r.useMemo)(()=>{if(!w||M==="")return null;let e=M.toLowerCase();return W.find(n=>n.label.toLowerCase()===e)??null},[w,M,W]),xe=w&&M!==""&&$===null,P=xe?I.length:-1,T=I.length+(xe?1:0),_=(0,r.useMemo)(()=>new Set(i),[i]),G=(0,r.useMemo)(()=>a?null:F.get(i[0]??"")??null,[a,F,i]),ve=(0,r.useMemo)(()=>{let e=new Set;for(let n of s)n.disabled&&e.add(n.value);return e},[s]),J=(0,r.useCallback)(e=>e<I.length&&ve.has(I[e].value),[I,ve]),ze=(0,r.useCallback)(e=>F.get(e)?.label??e,[F]),K=(0,r.useCallback)(e=>{Re||ct(e),R?.(a?e:e[0]??"")},[Re,R,a]),dt=(0,r.useCallback)(e=>{f||(K([e]),ye(!1),z(""),k(-1),y.current?.focus())},[K,f]),E=(0,r.useCallback)(e=>{f||K(e)},[K,f]),ut=(0,r.useCallback)(e=>{E(_.has(e)?i.filter(n=>n!==e):[...i,e])},[E,_,i]),pt=(0,r.useCallback)(e=>{E(i.filter(n=>n!==e))},[E,i]),ee=(0,r.useCallback)(()=>{i.length!==0&&E(i.slice(0,-1))},[E,i]),q=(0,r.useCallback)(()=>{if(!w||M===""||f||$?.disabled)return;let e=$?$.value:M;_.has(e)||E([...i,e]),z(""),k(-1)},[w,M,$,f,_,E,i]),ke=a?ut:dt,we=(0,r.useCallback)(e=>{if(e===P){q();return}e<0||e>=I.length||J(e)||ke(I[e].value)},[P,q,I,J,ke]),Ce=(0,r.useCallback)(()=>{((u&&O?he.current:null)??y.current)?.focus()},[u,O]),Fe=(0,r.useCallback)(e=>{e.stopPropagation(),K(Me),z(""),Ce()},[K,Ce]),B=(0,r.useCallback)(()=>{b||v||(ye(!0),z(""),k(-1))},[b,v]),C=(0,r.useCallback)(()=>{ye(!1),z(""),k(-1),y.current?.focus()},[]),gt=(0,r.useCallback)(()=>{u?C():B()},[u,C,B]),Y=(0,r.useCallback)((e,n)=>{let l=T;if(l===0)return-1;let d=e;for(let D=0;D<l;D++)if(d=((d+n)%l+l)%l,!J(d))return d;return-1},[T,J]),te=(0,r.useCallback)((e,n)=>{switch(e.key){case"ArrowDown":{e.preventDefault();let l=Y(p,1);l!==-1&&k(l);break}case"ArrowUp":{e.preventDefault();let l=Y(p,-1);l!==-1&&k(l);break}case"Home":{e.preventDefault();let l=Y(-1,1);l!==-1&&k(l);break}case"End":{e.preventDefault();let l=Y(T,-1);l!==-1&&k(l);break}case"Enter":{e.preventDefault(),p>=0&&p<T?we(p):w&&q();break}case" ":if(n)break;e.preventDefault(),p>=0&&p<T?we(p):C();break;case"Backspace":a&&(!n||H==="")&&(n||e.preventDefault(),ee());break;case"Escape":e.preventDefault(),C();break;case"Tab":C();break}},[Y,p,T,we,w,q,C,a,H,ee]),ft=(0,r.useCallback)(e=>{if(!(b||v)){if(u){te(e,!1);return}switch(e.key){case"ArrowDown":case"ArrowUp":e.preventDefault(),B();break;case"Enter":case" ":e.preventDefault(),B();break;case"Backspace":a&&i.length>0&&(e.preventDefault(),ee());break}}},[b,v,u,te,B,a,i.length,ee]),ht=(0,r.useCallback)(e=>te(e,!0),[te]),mt=(0,r.useCallback)(e=>{let n=e.target.value;z(n),k(-1),Pe?.(n)},[Pe]),L=!b&&!v,bt=(0,r.useCallback)(e=>{L&&(y.current?.contains(e.target)||e.preventDefault())},[L]),yt=(0,r.useCallback)(()=>{L&&(u?C():(y.current?.focus(),B()))},[L,u,C,B]);(0,r.useEffect)(()=>{if(!u)return;let e=l=>{let d=l.target;y.current?.contains(d)||ge.current?.contains(d)||fe.current?.contains(d)||C()},n=(0,X.ownerDocumentOf)(y.current);return n.addEventListener("mousedown",e),n.addEventListener("touchstart",e,{passive:!0}),()=>{n.removeEventListener("mousedown",e),n.removeEventListener("touchstart",e)}},[u,C]);let xt=a?i.length:0;(0,r.useEffect)(()=>{if(!u||!y.current){He(null);return}let e=(0,X.ownerWindowOf)(y.current),n=()=>{let l=a?ge.current:y.current;if(!l)return;let d=l.getBoundingClientRect(),D=e.innerHeight-d.bottom,Ne=d.top,vt=ce+8,qe=D<vt&&Ne>D?"top":"bottom";He({top:qe==="bottom"?d.bottom+e.scrollY+4:d.top+e.scrollY-4,left:d.left+e.scrollX,width:d.width,placement:qe})};return n(),e.addEventListener("scroll",n,!0),e.addEventListener("resize",n),()=>{e.removeEventListener("scroll",n,!0),e.removeEventListener("resize",n)}},[u,ce,a,xt]);let re=u&&V!==null;(0,r.useEffect)(()=>{re&&O&&he.current?.focus()},[re,O]),(0,r.useEffect)(()=>{let e=fe.current;if(!(!re||!e))return(0,Ze.registerFloatingLayer)(e,()=>y.current)},[re]),(0,r.useEffect)(()=>{if(p>=0){let e=me.current[p];e&&typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest"})}},[p]);let ne=i.length>0,Ke=oe&&ne&&!b&&!v&&!f,je=L&&!f,Ue=u&&p>=0?`${A}-option-${p}`:void 0,We={ref:y,id:ue,type:"button",role:"combobox","aria-expanded":u,"aria-haspopup":"listbox","aria-controls":u?pe:void 0,"aria-labelledby":Z?de:void 0,"aria-required":Oe||void 0,"aria-invalid":h.invalid||void 0,"aria-describedby":h.describedBy,"aria-activedescendant":Ue,disabled:b,onKeyDown:ft},$e=f?(0,t.jsx)("span",{className:"text-gray-500 dark:text-gray-400",children:Dt}):null,_e=(0,t.jsx)("span",{className:m("text-gray-500 dark:text-gray-400 transition-transform duration-200",u&&"rotate-180"),children:Mt}),Le;if(a){let e=U===void 0||!Number.isFinite(U)?i.length:Math.max(0,Math.floor(U)),n=i.slice(0,e),l=i.length-n.length;Le=(0,t.jsxs)("div",{ref:ge,className:m("w-full flex items-center rounded-md transition-colors","text-gray-900 dark:text-gray-100",S[x].frame,Se[le].trigger,!h.invalid&&L&&Tt,h.invalid&&Bt,b&&"opacity-50 cursor-not-allowed bg-gray-50 dark:bg-gray-900",v&&"cursor-default",L&&"cursor-pointer",Te),onMouseDown:bt,onClick:yt,children:[(0,t.jsxs)("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1",children:[n.map(d=>{let D=ze(d);return(0,t.jsxs)("span",{className:m("inline-flex max-w-full items-center rounded","bg-synertech-primary-100 text-synertech-primary-700 dark:bg-synertech-primary-900/50 dark:text-synertech-primary-300",S[x].tag,!je&&"pr-2"),children:[(0,t.jsx)("span",{className:"min-w-0 truncate","aria-hidden":"true",children:D}),je?(0,t.jsx)("button",{type:"button",tabIndex:-1,"aria-label":(0,j.formatUILabel)(N.selectRemoveValue,{label:D}),className:"flex shrink-0 items-center justify-center rounded-sm p-0.5 hover:bg-synertech-primary-200 dark:hover:bg-synertech-primary-800",onMouseDown:Q,onClick:Ne=>{Ne.stopPropagation(),pt(d),Ce()},children:Et}):null]},d)}),l>0?(0,t.jsx)("span",{"aria-hidden":"true",className:m("inline-flex items-center rounded bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-200",S[x].tag,"pr-2"),children:(0,j.formatUILabel)(N.selectMoreValues,{count:l})}):null,(0,t.jsx)("button",{...We,className:m("min-w-8 flex-1 text-left outline-hidden","flex items-center bg-transparent",S[x].combobox,L?"cursor-pointer":b?"cursor-not-allowed":"cursor-default"),children:ne?(0,t.jsx)("span",{className:"sr-only",children:i.map(ze).join(", ")}):(0,t.jsx)("span",{className:"truncate text-gray-600 dark:text-gray-300",children:Be})})]}),(0,t.jsxs)("span",{className:"flex items-center gap-1 shrink-0",children:[$e,Ke?(0,t.jsx)("button",{type:"button",tabIndex:-1,"aria-label":Ve??N.selectClear,className:"text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 p-0.5 rounded transition-colors",onMouseDown:Q,onClick:Fe,children:Ye}):null,_e]})]})}else{let e=m("w-full flex items-center justify-between rounded-md transition-colors","text-gray-900 dark:text-gray-100",S[x].trigger,Se[le].trigger,!h.invalid&&L&&Se[le].focus,h.invalid&&"border-red-500 dark:border-red-400 focus:ring-2 focus:ring-red-500 focus:border-red-500",b&&"opacity-50 cursor-not-allowed bg-gray-50 dark:bg-gray-900",v&&"cursor-default",!b&&!v&&"cursor-pointer",Te);Le=(0,t.jsxs)("button",{...We,className:e,onClick:L?gt:void 0,children:[(0,t.jsxs)("span",{className:m("flex items-center gap-2 min-w-0 flex-1 truncate",!ne&&"text-gray-600 dark:text-gray-300"),children:[G?.icon?(0,t.jsx)("span",{className:"flex shrink-0 items-center",children:G.icon}):null,(0,t.jsx)("span",{className:"truncate",children:ne&&G?G.label:Be})]}),(0,t.jsxs)("span",{className:"flex items-center gap-1 shrink-0",children:[$e,Ke?(0,t.jsx)("span",{role:"button",tabIndex:-1,"aria-label":Ve??N.selectClear,className:"text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 p-0.5 rounded transition-colors",onClick:Fe,onMouseDown:Q,children:Ye}):null,_e]})]})}return(0,t.jsxs)("div",{className:m("flex flex-col gap-1",ot),children:[Z?(0,t.jsxs)("label",{id:de,htmlFor:ue,className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:[Z,Oe?(0,t.jsx)("span",{className:"text-red-600 dark:text-red-400 ml-0.5","aria-hidden":"true",children:"*"}):null]}):null,h.hasDescription?(0,t.jsx)("p",{id:h.ids.description,className:"text-xs text-gray-500 dark:text-gray-400",children:Ee}):null,Le,h.message!==void 0?(0,t.jsx)("p",{id:h.ids.error,className:"text-xs text-red-600 dark:text-red-400",children:h.message}):h.showHelper?(0,t.jsx)("p",{id:h.ids.helper,className:m("text-xs",h.invalid?"text-red-600 dark:text-red-400":"text-gray-500 dark:text-gray-400"),children:De}):null,ie?a?i.map(e=>(0,t.jsx)("input",{type:"hidden",name:ie,value:e},e)):(0,t.jsx)("input",{type:"hidden",name:ie,value:i[0]??""}):null,u&&V?(0,Xe.createPortal)((0,t.jsxs)("div",{ref:fe,className:m("fixed z-50 bg-white text-gray-900 dark:bg-gray-800 dark:text-gray-100 border border-gray-200 dark:border-gray-700","rounded-md shadow-lg overflow-hidden","animate-in fade-in-0 zoom-in-95",S[x].content,lt),"data-placement":V.placement,style:{top:V.top,left:V.left,width:V.width,position:"absolute",translate:V.placement==="top"?"0 -100%":void 0},onKeyDown:ht,children:[O?(0,t.jsx)("div",{className:"border-b-2 border-gray-200 focus-within:border-synertech-primary-500 dark:border-gray-700 dark:focus-within:border-synertech-primary-400",children:(0,t.jsx)("input",{ref:he,type:"text",role:"searchbox","aria-label":nt??N.selectSearch,"aria-controls":pe,"aria-activedescendant":Ue,className:m(S[x].searchInput,"w-full outline-hidden bg-transparent text-gray-900 dark:text-gray-100","placeholder:text-gray-500 dark:placeholder:text-gray-400"),placeholder:at??N.selectSearchPlaceholder,value:H,onChange:mt})}):null,(0,t.jsxs)("div",{role:"listbox",id:pe,"aria-labelledby":Z?de:void 0,"aria-multiselectable":a||void 0,className:"overflow-y-auto",style:{maxHeight:ce},children:[I.map((e,n)=>(0,t.jsx)(At,{option:e,isSelected:_.has(e.value),isHighlighted:n===p,isDisabled:f||ve.has(e.value),multiple:a,sizeKey:x,optionId:`${A}-option-${n}`,onClick:ke,onMouseEnter:k,index:n,ref:l=>{me.current[n]=l}},e.value)),xe?(0,t.jsxs)("div",{ref:e=>{me.current[P]=e},id:`${A}-option-${P}`,role:"option","aria-selected":!1,"aria-disabled":f||void 0,"data-highlighted":P===p||void 0,className:Je(x,P===p,!1,f,a),onMouseDown:Q,onClick:f?void 0:q,onMouseEnter:f?void 0:()=>k(P),children:[(0,t.jsx)("span",{className:"flex size-4 shrink-0 items-center justify-center text-gray-500 dark:text-gray-400",children:Pt}),(0,t.jsx)("span",{className:"truncate",children:(0,j.formatUILabel)(N.selectCreateOption,{label:M})})]}):null]}),T===0?(0,t.jsx)("div",{className:m(S[x].option,"text-gray-500 dark:text-gray-400 text-center py-4"),children:it}):null]}),(0,X.ownerDocumentOf)(y.current).body):null]})}0&&(module.exports={Select});
|
|
1
|
+
"use strict";"use client";var Se=Object.defineProperty;var kt=Object.getOwnPropertyDescriptor;var wt=Object.getOwnPropertyNames;var Ct=Object.prototype.hasOwnProperty;var Lt=(o,s)=>{for(var a in s)Se(o,a,{get:s[a],enumerable:!0})},Nt=(o,s,a,c)=>{if(s&&typeof s=="object"||typeof s=="function")for(let f of wt(s))!Ct.call(o,f)&&f!==a&&Se(o,f,{get:()=>s[f],enumerable:!(c=kt(s,f))||c.enumerable});return o};var It=o=>Nt(Se({},"__esModule",{value:!0}),o);var zt={};Lt(zt,{Select:()=>Ht});module.exports=It(zt);var r=require("react"),Xe=require("react-dom"),Ze=require("../../lib/aria-hide.cjs"),Z=require("../../lib/owner-document.cjs"),j=require("../../lib/i18n.cjs"),Ge=require("../form/shared/field-error.cjs"),t=require("react/jsx-runtime"),St=[],se=[],X=o=>o.preventDefault(),Mt=(0,t.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,t.jsx)("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Ye=(0,t.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,t.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"})}),Et=(0,t.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,t.jsx)("path",{d:"M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),Dt=(0,t.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0 animate-spin",children:[(0,t.jsx)("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",strokeOpacity:"0.25"}),(0,t.jsx)("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),Ot=(0,t.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,t.jsx)("path",{d:"M11.5 3.5L5.5 10.5L2.5 7.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Vt=(0,t.jsx)("svg",{width:"10",height:"10",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:(0,t.jsx)("path",{d:"M11.5 3.5L5.5 10.5L2.5 7.5",stroke:"currentColor",strokeWidth:"2.25",strokeLinecap:"round",strokeLinejoin:"round"})}),Pt=(0,t.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:(0,t.jsx)("path",{d:"M7 2.5V11.5M2.5 7H11.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})}),S={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",frame:"min-h-8 pl-1 pr-2.5 py-1 text-xs gap-1.5",tag:"h-5 pl-1.5 pr-0.5 gap-0.5 text-xs",combobox:"h-5 px-1"},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",frame:"min-h-10 pl-1.5 pr-3 py-1.5 text-sm gap-2",tag:"h-6 pl-2 pr-1 gap-1 text-xs",combobox:"h-6 px-1.5"},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",frame:"min-h-12 pl-2 pr-4 py-2 text-base gap-2.5",tag:"h-7 pl-2.5 pr-1 gap-1 text-sm",combobox:"h-7 px-2"}},Me={default:{trigger:"border border-gray-300 bg-white dark:border-gray-600 dark:bg-gray-800",focus:"focus:ring-2 focus:ring-synertech-primary-500 focus:border-synertech-primary-500"},outlined:{trigger:"border-2 border-gray-300 bg-transparent dark:border-gray-600",focus:"focus:ring-2 focus:ring-synertech-primary-500 focus:border-synertech-primary-500"},filled:{trigger:"border border-transparent bg-gray-100 dark:bg-gray-700",focus:"focus:ring-2 focus:ring-synertech-primary-500 focus:border-synertech-primary-500"}},Tt="focus-within:ring-2 focus-within:ring-synertech-primary-500 focus-within:border-synertech-primary-500",Bt="border-red-500 dark:border-red-400 focus-within:ring-2 focus-within:ring-red-500 focus-within:border-red-500";function m(...o){let s="";for(let a=0;a<o.length;a++){let c=o[a];c&&(s&&(s+=" "),s+=c)}return s}function Rt(o,s){if(!s)return o;let a=s.toLowerCase();return o.filter(c=>{if(c.label.toLowerCase().includes(a)||c.value.toLowerCase().includes(a))return!0;if(c.keywords){for(let f of c.keywords)if(f.toLowerCase().includes(a))return!0}return!1})}function Qe(o,s){if(o!==void 0)return Array.isArray(o)?s?new Set(o).size===o.length?o:Array.from(new Set(o)):o.slice(0,1):o===""?se:[o]}function Je(o,s,a,c,f){return m(S[o].option,"flex items-center gap-2 cursor-pointer select-none transition-colors",s&&!c&&"bg-synertech-primary-50 dark:bg-synertech-primary-900/30",a&&!s&&!f&&"bg-gray-50 dark:bg-gray-700/50",c&&"opacity-50 cursor-not-allowed")}var At=(0,r.memo)((0,r.forwardRef)(function({option:s,isSelected:a,isHighlighted:c,isDisabled:f,multiple:A,sizeKey:U,optionId:oe,onClick:le,onMouseEnter:W,index:b},v){let u=()=>{f||le(s.value)},x=()=>{f||W(b)};return(0,t.jsxs)("div",{ref:v,id:oe,role:"option","aria-selected":a,"aria-disabled":f||void 0,"data-highlighted":c||void 0,className:Je(U,c,a,f,A),onMouseDown:X,onClick:u,onMouseEnter:x,children:[A?(0,t.jsx)("span",{"aria-hidden":"true",className:m("flex size-4 shrink-0 items-center justify-center rounded border-2 transition-colors",a?"border-synertech-primary-600 bg-synertech-primary-600 text-synertech-on-primary":"border-gray-500 dark:border-gray-400"),children:a?Vt:null}):null,s.icon?(0,t.jsx)("span",{className:"flex shrink-0 items-center",children:s.icon}):null,(0,t.jsxs)("span",{className:"flex flex-col min-w-0 flex-1",children:[(0,t.jsx)("span",{className:"truncate",children:s.label}),s.description?(0,t.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:s.description}):null]}),a&&!A?(0,t.jsx)("span",{className:"ml-auto text-synertech-primary-600 dark:text-synertech-primary-400",children:Ot}):null]})}));function Ht(o){let{options:s=St,multiple:a=!1,value:c,defaultValue:f,onValueChange:A,maxTagCount:U,creatable:oe=!1,searchable:le=!1,clearable:W=!1,disabled:b=!1,readOnly:v=!1,loading:u=!1,size:x="md",variant:ie="default",placeholder:et,label:G,description:Ee,helperText:De,error:tt,required:Oe=!1,noOptionsText:rt,clearLabel:Ve,searchLabel:nt,searchPlaceholder:at,labels:st,onSearchChange:Pe,name:ce,className:ot,triggerClassName:Te,contentClassName:lt,maxHeight:de=256}=o,w=a&&oe,V=le||w,N=(0,j.useUILabels)(st),Be=et??N.selectPlaceholder,it=rt??N.selectNoOptions,H=(0,r.useId)(),ue=`${H}-label`,pe=`${H}-trigger`,ge=`${H}-listbox`,h=(0,Ge.describeField)(pe,{description:Ee,helperText:De,error:tt}),y=(0,r.useRef)(null),fe=(0,r.useRef)(null),he=(0,r.useRef)(null),me=(0,r.useRef)(null),be=(0,r.useRef)([]),Re=c!==void 0,[ye,ct]=(0,r.useState)(()=>Qe(f,a)??se),Ae=(0,r.useMemo)(()=>Qe(c,a),[c,a]),l=(0,r.useMemo)(()=>Ae??(a?ye:ye.slice(0,1)),[Ae,ye,a]),[p,xe]=(0,r.useState)(!1),[z,F]=(0,r.useState)(""),[g,k]=(0,r.useState)(-1),[P,He]=(0,r.useState)(null),K=(0,r.useMemo)(()=>{let e=new Map;for(let n of s)e.has(n.value)||e.set(n.value,n);return e},[s]),$=(0,r.useMemo)(()=>{if(!w)return s;let e=[];for(let n of l)K.has(n)||e.push({value:n,label:n});return e.length>0?[...s,...e]:s},[w,s,l,K]),I=(0,r.useMemo)(()=>V?Rt($,z):$,[$,z,V]),M=z.trim(),_=(0,r.useMemo)(()=>{if(!w||M==="")return null;let e=M.toLowerCase();return $.find(n=>n.label.toLowerCase()===e)??null},[w,M,$]),ve=w&&M!==""&&_===null,T=ve?I.length:-1,B=I.length+(ve?1:0),q=(0,r.useMemo)(()=>new Set(l),[l]),J=(0,r.useMemo)(()=>a?null:K.get(l[0]??"")??null,[a,K,l]),ke=(0,r.useMemo)(()=>{let e=new Set;for(let n of s)n.disabled&&e.add(n.value);return e},[s]),ee=(0,r.useCallback)(e=>e<I.length&&ke.has(I[e].value),[I,ke]),ze=(0,r.useCallback)(e=>K.get(e)?.label??e,[K]),E=(0,r.useCallback)(e=>{Re||ct(e),A?.(a?e:e[0]??"")},[Re,A,a]),dt=(0,r.useCallback)(e=>{u||(E([e]),xe(!1),F(""),k(-1),y.current?.focus())},[E,u]),D=(0,r.useCallback)(e=>{u||E(e)},[E,u]),ut=(0,r.useCallback)(e=>{D(q.has(e)?l.filter(n=>n!==e):[...l,e])},[D,q,l]),pt=(0,r.useCallback)(e=>{D(l.filter(n=>n!==e))},[D,l]),te=(0,r.useCallback)(()=>{l.length!==0&&D(l.slice(0,-1))},[D,l]),Y=(0,r.useCallback)(()=>{if(!w||M===""||u||_?.disabled)return;let e=_?_.value:M;q.has(e)||D([...l,e]),F(""),k(-1)},[w,M,_,u,q,D,l]),we=a?ut:dt,Ce=(0,r.useCallback)(e=>{if(e===T){Y();return}e<0||e>=I.length||ee(e)||we(I[e].value)},[T,Y,I,ee,we]),Le=(0,r.useCallback)(()=>{((p&&V?me.current:null)??y.current)?.focus()},[p,V]),Fe=(0,r.useCallback)(e=>{e.stopPropagation(),E(se),F(""),Le()},[E,Le]),R=(0,r.useCallback)(()=>{b||v||(xe(!0),F(""),k(-1))},[b,v]),C=(0,r.useCallback)(()=>{xe(!1),F(""),k(-1),y.current?.focus()},[]),gt=(0,r.useCallback)(()=>{p?C():R()},[p,C,R]),Q=(0,r.useCallback)((e,n)=>{let i=B;if(i===0)return-1;let d=e;for(let O=0;O<i;O++)if(d=((d+n)%i+i)%i,!ee(d))return d;return-1},[B,ee]),re=(0,r.useCallback)((e,n)=>{switch(e.key){case"ArrowDown":{e.preventDefault();let i=Q(g,1);i!==-1&&k(i);break}case"ArrowUp":{e.preventDefault();let i=Q(g,-1);i!==-1&&k(i);break}case"Home":{e.preventDefault();let i=Q(-1,1);i!==-1&&k(i);break}case"End":{e.preventDefault();let i=Q(B,-1);i!==-1&&k(i);break}case"Enter":{e.preventDefault(),g>=0&&g<B?Ce(g):w&&Y();break}case" ":if(n)break;e.preventDefault(),g>=0&&g<B?Ce(g):C();break;case"Backspace":a&&(!n||z==="")&&(n||e.preventDefault(),te());break;case"Escape":e.preventDefault(),C();break;case"Tab":C();break}},[Q,g,B,Ce,w,Y,C,a,z,te]),ft=(0,r.useCallback)(e=>{if(!(b||v)){if(p){re(e,!1);return}switch(e.key){case"ArrowDown":case"ArrowUp":e.preventDefault(),R();break;case"Enter":case" ":e.preventDefault(),R();break;case"Backspace":case"Delete":a?e.key==="Backspace"&&l.length>0&&(e.preventDefault(),te()):W&&!u&&l.length>0&&(e.preventDefault(),E(se));break}}},[b,v,p,re,R,a,l.length,te,W,u,E]),ht=(0,r.useCallback)(e=>re(e,!0),[re]),mt=(0,r.useCallback)(e=>{let n=e.target.value;F(n),k(-1),Pe?.(n)},[Pe]),L=!b&&!v,bt=(0,r.useCallback)(e=>{L&&(y.current?.contains(e.target)||e.preventDefault())},[L]),yt=(0,r.useCallback)(()=>{L&&(p?C():(y.current?.focus(),R()))},[L,p,C,R]);(0,r.useEffect)(()=>{if(!p)return;let e=i=>{let d=i.target;y.current?.contains(d)||fe.current?.contains(d)||he.current?.contains(d)||C()},n=(0,Z.ownerDocumentOf)(y.current);return n.addEventListener("mousedown",e),n.addEventListener("touchstart",e,{passive:!0}),()=>{n.removeEventListener("mousedown",e),n.removeEventListener("touchstart",e)}},[p,C]);let xt=a?l.length:0;(0,r.useEffect)(()=>{if(!p||!y.current){He(null);return}let e=(0,Z.ownerWindowOf)(y.current),n=()=>{let i=a?fe.current:y.current;if(!i)return;let d=i.getBoundingClientRect(),O=e.innerHeight-d.bottom,Ie=d.top,vt=de+8,qe=O<vt&&Ie>O?"top":"bottom";He({top:qe==="bottom"?d.bottom+e.scrollY+4:d.top+e.scrollY-4,left:d.left+e.scrollX,width:d.width,placement:qe})};return n(),e.addEventListener("scroll",n,!0),e.addEventListener("resize",n),()=>{e.removeEventListener("scroll",n,!0),e.removeEventListener("resize",n)}},[p,de,a,xt]);let ne=p&&P!==null;(0,r.useEffect)(()=>{ne&&V&&me.current?.focus()},[ne,V]),(0,r.useEffect)(()=>{let e=he.current;if(!(!ne||!e))return(0,Ze.registerFloatingLayer)(e,()=>y.current)},[ne]),(0,r.useEffect)(()=>{if(g>=0){let e=be.current[g];e&&typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest"})}},[g]);let ae=l.length>0,Ke=W&&ae&&!b&&!v&&!u,je=L&&!u,Ue=p&&g>=0?`${H}-option-${g}`:void 0,We={ref:y,id:pe,type:"button",role:"combobox","aria-expanded":p,"aria-haspopup":"listbox","aria-controls":p?ge:void 0,"aria-labelledby":G?ue:void 0,"aria-required":Oe||void 0,"aria-invalid":h.invalid||void 0,"aria-describedby":h.describedBy,"aria-activedescendant":Ue,disabled:b,onKeyDown:ft},$e=u?(0,t.jsx)("span",{className:"text-gray-500 dark:text-gray-400",children:Dt}):null,_e=(0,t.jsx)("span",{className:m("text-gray-500 dark:text-gray-400 transition-transform duration-200",p&&"rotate-180"),children:Mt}),Ne;if(a){let e=U===void 0||!Number.isFinite(U)?l.length:Math.max(0,Math.floor(U)),n=l.slice(0,e),i=l.length-n.length;Ne=(0,t.jsxs)("div",{ref:fe,className:m("w-full flex items-center rounded-md transition-colors","text-gray-900 dark:text-gray-100",S[x].frame,Me[ie].trigger,!h.invalid&&L&&Tt,h.invalid&&Bt,b&&"opacity-50 cursor-not-allowed bg-gray-50 dark:bg-gray-900",v&&"cursor-default",L&&"cursor-pointer",Te),onMouseDown:bt,onClick:yt,children:[(0,t.jsxs)("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1",children:[n.map(d=>{let O=ze(d);return(0,t.jsxs)("span",{className:m("inline-flex max-w-full items-center rounded","bg-synertech-primary-100 text-synertech-primary-700 dark:bg-synertech-primary-900/50 dark:text-synertech-primary-300",S[x].tag,!je&&"pr-2"),children:[(0,t.jsx)("span",{className:"min-w-0 truncate","aria-hidden":"true",children:O}),je?(0,t.jsx)("button",{type:"button",tabIndex:-1,"aria-label":(0,j.formatUILabel)(N.selectRemoveValue,{label:O}),className:"flex shrink-0 items-center justify-center rounded-sm p-0.5 hover:bg-synertech-primary-200 dark:hover:bg-synertech-primary-800",onMouseDown:X,onClick:Ie=>{Ie.stopPropagation(),pt(d),Le()},children:Et}):null]},d)}),i>0?(0,t.jsx)("span",{"aria-hidden":"true",className:m("inline-flex items-center rounded bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-200",S[x].tag,"pr-2"),children:(0,j.formatUILabel)(N.selectMoreValues,{count:i})}):null,(0,t.jsx)("button",{...We,className:m("min-w-8 flex-1 text-left outline-hidden","flex items-center bg-transparent",S[x].combobox,L?"cursor-pointer":b?"cursor-not-allowed":"cursor-default"),children:ae?(0,t.jsx)("span",{className:"sr-only",children:l.map(ze).join(", ")}):(0,t.jsx)("span",{className:"truncate text-gray-600 dark:text-gray-300",children:Be})})]}),(0,t.jsxs)("span",{className:"flex items-center gap-1 shrink-0",children:[$e,Ke?(0,t.jsx)("button",{type:"button",tabIndex:-1,"aria-label":Ve??N.selectClear,className:"text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 p-0.5 rounded transition-colors",onMouseDown:X,onClick:Fe,children:Ye}):null,_e]})]})}else{let e=m("w-full flex items-center justify-between rounded-md transition-colors","text-gray-900 dark:text-gray-100",S[x].trigger,Me[ie].trigger,!h.invalid&&L&&Me[ie].focus,h.invalid&&"border-red-500 dark:border-red-400 focus:ring-2 focus:ring-red-500 focus:border-red-500",b&&"opacity-50 cursor-not-allowed bg-gray-50 dark:bg-gray-900",v&&"cursor-default",!b&&!v&&"cursor-pointer",Te);Ne=(0,t.jsxs)("button",{...We,className:e,onClick:L?gt:void 0,children:[(0,t.jsxs)("span",{className:m("flex items-center gap-2 min-w-0 flex-1 truncate",!ae&&"text-gray-600 dark:text-gray-300"),children:[J?.icon?(0,t.jsx)("span",{className:"flex shrink-0 items-center",children:J.icon}):null,(0,t.jsx)("span",{className:"truncate",children:ae&&J?J.label:Be})]}),(0,t.jsxs)("span",{className:"flex items-center gap-1 shrink-0",children:[$e,Ke?(0,t.jsx)("span",{role:"button",tabIndex:-1,"aria-label":Ve??N.selectClear,className:"text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 p-0.5 rounded transition-colors",onClick:Fe,onMouseDown:X,children:Ye}):null,_e]})]})}return(0,t.jsxs)("div",{className:m("flex flex-col gap-1",ot),children:[G?(0,t.jsxs)("label",{id:ue,htmlFor:pe,className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:[G,Oe?(0,t.jsx)("span",{className:"text-red-600 dark:text-red-400 ml-0.5","aria-hidden":"true",children:"*"}):null]}):null,h.hasDescription?(0,t.jsx)("p",{id:h.ids.description,className:"text-xs text-gray-500 dark:text-gray-400",children:Ee}):null,Ne,h.message!==void 0?(0,t.jsx)("p",{id:h.ids.error,className:"text-xs text-red-600 dark:text-red-400",children:h.message}):h.showHelper?(0,t.jsx)("p",{id:h.ids.helper,className:m("text-xs",h.invalid?"text-red-600 dark:text-red-400":"text-gray-500 dark:text-gray-400"),children:De}):null,ce?a?l.map(e=>(0,t.jsx)("input",{type:"hidden",name:ce,value:e},e)):(0,t.jsx)("input",{type:"hidden",name:ce,value:l[0]??""}):null,p&&P?(0,Xe.createPortal)((0,t.jsxs)("div",{ref:he,className:m("fixed z-50 bg-white text-gray-900 dark:bg-gray-800 dark:text-gray-100 border border-gray-200 dark:border-gray-700","rounded-md shadow-lg overflow-hidden","animate-in fade-in-0 zoom-in-95",S[x].content,lt),"data-placement":P.placement,style:{top:P.top,left:P.left,width:P.width,position:"absolute",translate:P.placement==="top"?"0 -100%":void 0},onKeyDown:ht,children:[V?(0,t.jsx)("div",{className:"border-b-2 border-gray-200 focus-within:border-synertech-primary-500 dark:border-gray-700 dark:focus-within:border-synertech-primary-400",children:(0,t.jsx)("input",{ref:me,type:"text",role:"searchbox","aria-label":nt??N.selectSearch,"aria-controls":ge,"aria-activedescendant":Ue,className:m(S[x].searchInput,"w-full outline-hidden bg-transparent text-gray-900 dark:text-gray-100","placeholder:text-gray-500 dark:placeholder:text-gray-400"),placeholder:at??N.selectSearchPlaceholder,value:z,onChange:mt})}):null,(0,t.jsxs)("div",{role:"listbox",id:ge,"aria-labelledby":G?ue:void 0,"aria-multiselectable":a||void 0,className:"overflow-y-auto",style:{maxHeight:de},children:[I.map((e,n)=>(0,t.jsx)(At,{option:e,isSelected:q.has(e.value),isHighlighted:n===g,isDisabled:u||ke.has(e.value),multiple:a,sizeKey:x,optionId:`${H}-option-${n}`,onClick:we,onMouseEnter:k,index:n,ref:i=>{be.current[n]=i}},e.value)),ve?(0,t.jsxs)("div",{ref:e=>{be.current[T]=e},id:`${H}-option-${T}`,role:"option","aria-selected":!1,"aria-disabled":u||void 0,"data-highlighted":T===g||void 0,className:Je(x,T===g,!1,u,a),onMouseDown:X,onClick:u?void 0:Y,onMouseEnter:u?void 0:()=>k(T),children:[(0,t.jsx)("span",{className:"flex size-4 shrink-0 items-center justify-center text-gray-500 dark:text-gray-400",children:Pt}),(0,t.jsx)("span",{className:"truncate",children:(0,j.formatUILabel)(N.selectCreateOption,{label:M})})]}):null]}),B===0?(0,t.jsx)("div",{className:m(S[x].option,"text-gray-500 dark:text-gray-400 text-center py-4"),children:it}):null]}),(0,Z.ownerDocumentOf)(y.current).body):null]})}0&&(module.exports={Select});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useState as X,useRef as Z,useEffect as G,useCallback as i,useMemo as M,useId as wt,memo as Ct,forwardRef as Lt}from"react";import{createPortal as Nt}from"react-dom";import{registerFloatingLayer as It}from"../../lib/aria-hide.js";import{ownerDocumentOf as Ze,ownerWindowOf as St}from"../../lib/owner-document.js";import{formatUILabel as Ee,useUILabels as Mt}from"../../lib/i18n.js";import{describeField as Et}from"../form/shared/field-error.js";import{jsx as r,jsxs as f}from"react/jsx-runtime";var Dt=[],Oe=[],J=l=>l.preventDefault(),Ot=r("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0",children:r("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Ge=r("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:r("path",{d:"M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Vt=r("svg",{width:"10",height:"10",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:r("path",{d:"M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),Pt=f("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0 animate-spin",children:[r("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",strokeOpacity:"0.25"}),r("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),Tt=r("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:r("path",{d:"M11.5 3.5L5.5 10.5L2.5 7.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Bt=r("svg",{width:"10",height:"10",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:r("path",{d:"M11.5 3.5L5.5 10.5L2.5 7.5",stroke:"currentColor",strokeWidth:"2.25",strokeLinecap:"round",strokeLinejoin:"round"})}),Rt=r("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:r("path",{d:"M7 2.5V11.5M2.5 7H11.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})}),E={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",frame:"min-h-8 pl-1 pr-2.5 py-1 text-xs gap-1.5",tag:"h-5 pl-1.5 pr-0.5 gap-0.5 text-xs",combobox:"h-5 px-1"},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",frame:"min-h-10 pl-1.5 pr-3 py-1.5 text-sm gap-2",tag:"h-6 pl-2 pr-1 gap-1 text-xs",combobox:"h-6 px-1.5"},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",frame:"min-h-12 pl-2 pr-4 py-2 text-base gap-2.5",tag:"h-7 pl-2.5 pr-1 gap-1 text-sm",combobox:"h-7 px-2"}},De={default:{trigger:"border border-gray-300 bg-white dark:border-gray-600 dark:bg-gray-800",focus:"focus:ring-2 focus:ring-synertech-primary-500 focus:border-synertech-primary-500"},outlined:{trigger:"border-2 border-gray-300 bg-transparent dark:border-gray-600",focus:"focus:ring-2 focus:ring-synertech-primary-500 focus:border-synertech-primary-500"},filled:{trigger:"border border-transparent bg-gray-100 dark:bg-gray-700",focus:"focus:ring-2 focus:ring-synertech-primary-500 focus:border-synertech-primary-500"}},At="focus-within:ring-2 focus-within:ring-synertech-primary-500 focus-within:border-synertech-primary-500",Ht="border-red-500 dark:border-red-400 focus-within:ring-2 focus-within:ring-red-500 focus-within:border-red-500";function m(...l){let a="";for(let n=0;n<l.length;n++){let u=l[n];u&&(a&&(a+=" "),a+=u)}return a}function zt(l,a){if(!a)return l;let n=a.toLowerCase();return l.filter(u=>{if(u.label.toLowerCase().includes(n)||u.value.toLowerCase().includes(n))return!0;if(u.keywords){for(let w of u.keywords)if(w.toLowerCase().includes(n))return!0}return!1})}function Je(l,a){if(l!==void 0)return Array.isArray(l)?a?new Set(l).size===l.length?l:Array.from(new Set(l)):l.slice(0,1):l===""?Oe:[l]}function et(l,a,n,u,w){return m(E[l].option,"flex items-center gap-2 cursor-pointer select-none transition-colors",a&&!u&&"bg-synertech-primary-50 dark:bg-synertech-primary-900/30",n&&!a&&!w&&"bg-gray-50 dark:bg-gray-700/50",u&&"opacity-50 cursor-not-allowed")}var Ft=Ct(Lt(function({option:a,isSelected:n,isHighlighted:u,isDisabled:w,multiple:H,sizeKey:W,optionId:le,onClick:ie,onMouseEnter:ce,index:b},v){let g=()=>{w||ie(a.value)},x=()=>{w||ce(b)};return f("div",{ref:v,id:le,role:"option","aria-selected":n,"aria-disabled":w||void 0,"data-highlighted":u||void 0,className:et(W,u,n,w,H),onMouseDown:J,onClick:g,onMouseEnter:x,children:[H?r("span",{"aria-hidden":"true",className:m("flex size-4 shrink-0 items-center justify-center rounded border-2 transition-colors",n?"border-synertech-primary-600 bg-synertech-primary-600 text-synertech-on-primary":"border-gray-500 dark:border-gray-400"),children:n?Bt:null}):null,a.icon?r("span",{className:"flex shrink-0 items-center",children:a.icon}):null,f("span",{className:"flex flex-col min-w-0 flex-1",children:[r("span",{className:"truncate",children:a.label}),a.description?r("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:a.description}):null]}),n&&!H?r("span",{className:"ml-auto text-synertech-primary-600 dark:text-synertech-primary-400",children:Tt}):null]})}));function qt(l){let{options:a=Dt,multiple:n=!1,value:u,defaultValue:w,onValueChange:H,maxTagCount:W,creatable:le=!1,searchable:ie=!1,clearable:ce=!1,disabled:b=!1,readOnly:v=!1,loading:g=!1,size:x="md",variant:de="default",placeholder:tt,label:ee,description:Ve,helperText:Pe,error:rt,required:Te=!1,noOptionsText:nt,clearLabel:Be,searchLabel:at,searchPlaceholder:st,labels:ot,onSearchChange:Re,name:ue,className:lt,triggerClassName:Ae,contentClassName:it,maxHeight:pe=256}=l,C=n&&le,P=ie||C,I=Mt(ot),He=tt??I.selectPlaceholder,ct=nt??I.selectNoOptions,z=wt(),ge=`${z}-label`,fe=`${z}-trigger`,he=`${z}-listbox`,h=Et(fe,{description:Ve,helperText:Pe,error:rt}),y=Z(null),me=Z(null),be=Z(null),ye=Z(null),xe=Z([]),ze=u!==void 0,[ve,dt]=X(()=>Je(w,n)??Oe),Fe=M(()=>Je(u,n),[u,n]),o=M(()=>Fe??(n?ve:ve.slice(0,1)),[Fe,ve,n]),[d,ke]=X(!1),[F,K]=X(""),[p,k]=X(-1),[T,Ke]=X(null),j=M(()=>{let e=new Map;for(let t of a)e.has(t.value)||e.set(t.value,t);return e},[a]),$=M(()=>{if(!C)return a;let e=[];for(let t of o)j.has(t)||e.push({value:t,label:t});return e.length>0?[...a,...e]:a},[C,a,o,j]),S=M(()=>P?zt($,F):$,[$,F,P]),D=F.trim(),_=M(()=>{if(!C||D==="")return null;let e=D.toLowerCase();return $.find(t=>t.label.toLowerCase()===e)??null},[C,D,$]),we=C&&D!==""&&_===null,B=we?S.length:-1,R=S.length+(we?1:0),q=M(()=>new Set(o),[o]),te=M(()=>n?null:j.get(o[0]??"")??null,[n,j,o]),Ce=M(()=>{let e=new Set;for(let t of a)t.disabled&&e.add(t.value);return e},[a]),re=i(e=>e<S.length&&Ce.has(S[e].value),[S,Ce]),je=i(e=>j.get(e)?.label??e,[j]),U=i(e=>{ze||dt(e),H?.(n?e:e[0]??"")},[ze,H,n]),ut=i(e=>{g||(U([e]),ke(!1),K(""),k(-1),y.current?.focus())},[U,g]),O=i(e=>{g||U(e)},[U,g]),pt=i(e=>{O(q.has(e)?o.filter(t=>t!==e):[...o,e])},[O,q,o]),gt=i(e=>{O(o.filter(t=>t!==e))},[O,o]),ne=i(()=>{o.length!==0&&O(o.slice(0,-1))},[O,o]),Y=i(()=>{if(!C||D===""||g||_?.disabled)return;let e=_?_.value:D;q.has(e)||O([...o,e]),K(""),k(-1)},[C,D,_,g,q,O,o]),Le=n?pt:ut,Ne=i(e=>{if(e===B){Y();return}e<0||e>=S.length||re(e)||Le(S[e].value)},[B,Y,S,re,Le]),Ie=i(()=>{((d&&P?ye.current:null)??y.current)?.focus()},[d,P]),Ue=i(e=>{e.stopPropagation(),U(Oe),K(""),Ie()},[U,Ie]),A=i(()=>{b||v||(ke(!0),K(""),k(-1))},[b,v]),L=i(()=>{ke(!1),K(""),k(-1),y.current?.focus()},[]),ft=i(()=>{d?L():A()},[d,L,A]),Q=i((e,t)=>{let s=R;if(s===0)return-1;let c=e;for(let V=0;V<s;V++)if(c=((c+t)%s+s)%s,!re(c))return c;return-1},[R,re]),ae=i((e,t)=>{switch(e.key){case"ArrowDown":{e.preventDefault();let s=Q(p,1);s!==-1&&k(s);break}case"ArrowUp":{e.preventDefault();let s=Q(p,-1);s!==-1&&k(s);break}case"Home":{e.preventDefault();let s=Q(-1,1);s!==-1&&k(s);break}case"End":{e.preventDefault();let s=Q(R,-1);s!==-1&&k(s);break}case"Enter":{e.preventDefault(),p>=0&&p<R?Ne(p):C&&Y();break}case" ":if(t)break;e.preventDefault(),p>=0&&p<R?Ne(p):L();break;case"Backspace":n&&(!t||F==="")&&(t||e.preventDefault(),ne());break;case"Escape":e.preventDefault(),L();break;case"Tab":L();break}},[Q,p,R,Ne,C,Y,L,n,F,ne]),ht=i(e=>{if(!(b||v)){if(d){ae(e,!1);return}switch(e.key){case"ArrowDown":case"ArrowUp":e.preventDefault(),A();break;case"Enter":case" ":e.preventDefault(),A();break;case"Backspace":n&&o.length>0&&(e.preventDefault(),ne());break}}},[b,v,d,ae,A,n,o.length,ne]),mt=i(e=>ae(e,!0),[ae]),bt=i(e=>{let t=e.target.value;K(t),k(-1),Re?.(t)},[Re]),N=!b&&!v,yt=i(e=>{N&&(y.current?.contains(e.target)||e.preventDefault())},[N]),xt=i(()=>{N&&(d?L():(y.current?.focus(),A()))},[N,d,L,A]);G(()=>{if(!d)return;let e=s=>{let c=s.target;y.current?.contains(c)||me.current?.contains(c)||be.current?.contains(c)||L()},t=Ze(y.current);return t.addEventListener("mousedown",e),t.addEventListener("touchstart",e,{passive:!0}),()=>{t.removeEventListener("mousedown",e),t.removeEventListener("touchstart",e)}},[d,L]);let vt=n?o.length:0;G(()=>{if(!d||!y.current){Ke(null);return}let e=St(y.current),t=()=>{let s=n?me.current:y.current;if(!s)return;let c=s.getBoundingClientRect(),V=e.innerHeight-c.bottom,Me=c.top,kt=pe+8,Xe=V<kt&&Me>V?"top":"bottom";Ke({top:Xe==="bottom"?c.bottom+e.scrollY+4:c.top+e.scrollY-4,left:c.left+e.scrollX,width:c.width,placement:Xe})};return t(),e.addEventListener("scroll",t,!0),e.addEventListener("resize",t),()=>{e.removeEventListener("scroll",t,!0),e.removeEventListener("resize",t)}},[d,pe,n,vt]);let se=d&&T!==null;G(()=>{se&&P&&ye.current?.focus()},[se,P]),G(()=>{let e=be.current;if(!(!se||!e))return It(e,()=>y.current)},[se]),G(()=>{if(p>=0){let e=xe.current[p];e&&typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest"})}},[p]);let oe=o.length>0,We=ce&&oe&&!b&&!v&&!g,$e=N&&!g,_e=d&&p>=0?`${z}-option-${p}`:void 0,qe={ref:y,id:fe,type:"button",role:"combobox","aria-expanded":d,"aria-haspopup":"listbox","aria-controls":d?he:void 0,"aria-labelledby":ee?ge:void 0,"aria-required":Te||void 0,"aria-invalid":h.invalid||void 0,"aria-describedby":h.describedBy,"aria-activedescendant":_e,disabled:b,onKeyDown:ht},Ye=g?r("span",{className:"text-gray-500 dark:text-gray-400",children:Pt}):null,Qe=r("span",{className:m("text-gray-500 dark:text-gray-400 transition-transform duration-200",d&&"rotate-180"),children:Ot}),Se;if(n){let e=W===void 0||!Number.isFinite(W)?o.length:Math.max(0,Math.floor(W)),t=o.slice(0,e),s=o.length-t.length;Se=f("div",{ref:me,className:m("w-full flex items-center rounded-md transition-colors","text-gray-900 dark:text-gray-100",E[x].frame,De[de].trigger,!h.invalid&&N&&At,h.invalid&&Ht,b&&"opacity-50 cursor-not-allowed bg-gray-50 dark:bg-gray-900",v&&"cursor-default",N&&"cursor-pointer",Ae),onMouseDown:yt,onClick:xt,children:[f("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1",children:[t.map(c=>{let V=je(c);return f("span",{className:m("inline-flex max-w-full items-center rounded","bg-synertech-primary-100 text-synertech-primary-700 dark:bg-synertech-primary-900/50 dark:text-synertech-primary-300",E[x].tag,!$e&&"pr-2"),children:[r("span",{className:"min-w-0 truncate","aria-hidden":"true",children:V}),$e?r("button",{type:"button",tabIndex:-1,"aria-label":Ee(I.selectRemoveValue,{label:V}),className:"flex shrink-0 items-center justify-center rounded-sm p-0.5 hover:bg-synertech-primary-200 dark:hover:bg-synertech-primary-800",onMouseDown:J,onClick:Me=>{Me.stopPropagation(),gt(c),Ie()},children:Vt}):null]},c)}),s>0?r("span",{"aria-hidden":"true",className:m("inline-flex items-center rounded bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-200",E[x].tag,"pr-2"),children:Ee(I.selectMoreValues,{count:s})}):null,r("button",{...qe,className:m("min-w-8 flex-1 text-left outline-hidden","flex items-center bg-transparent",E[x].combobox,N?"cursor-pointer":b?"cursor-not-allowed":"cursor-default"),children:oe?r("span",{className:"sr-only",children:o.map(je).join(", ")}):r("span",{className:"truncate text-gray-600 dark:text-gray-300",children:He})})]}),f("span",{className:"flex items-center gap-1 shrink-0",children:[Ye,We?r("button",{type:"button",tabIndex:-1,"aria-label":Be??I.selectClear,className:"text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 p-0.5 rounded transition-colors",onMouseDown:J,onClick:Ue,children:Ge}):null,Qe]})]})}else{let e=m("w-full flex items-center justify-between rounded-md transition-colors","text-gray-900 dark:text-gray-100",E[x].trigger,De[de].trigger,!h.invalid&&N&&De[de].focus,h.invalid&&"border-red-500 dark:border-red-400 focus:ring-2 focus:ring-red-500 focus:border-red-500",b&&"opacity-50 cursor-not-allowed bg-gray-50 dark:bg-gray-900",v&&"cursor-default",!b&&!v&&"cursor-pointer",Ae);Se=f("button",{...qe,className:e,onClick:N?ft:void 0,children:[f("span",{className:m("flex items-center gap-2 min-w-0 flex-1 truncate",!oe&&"text-gray-600 dark:text-gray-300"),children:[te?.icon?r("span",{className:"flex shrink-0 items-center",children:te.icon}):null,r("span",{className:"truncate",children:oe&&te?te.label:He})]}),f("span",{className:"flex items-center gap-1 shrink-0",children:[Ye,We?r("span",{role:"button",tabIndex:-1,"aria-label":Be??I.selectClear,className:"text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 p-0.5 rounded transition-colors",onClick:Ue,onMouseDown:J,children:Ge}):null,Qe]})]})}return f("div",{className:m("flex flex-col gap-1",lt),children:[ee?f("label",{id:ge,htmlFor:fe,className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:[ee,Te?r("span",{className:"text-red-600 dark:text-red-400 ml-0.5","aria-hidden":"true",children:"*"}):null]}):null,h.hasDescription?r("p",{id:h.ids.description,className:"text-xs text-gray-500 dark:text-gray-400",children:Ve}):null,Se,h.message!==void 0?r("p",{id:h.ids.error,className:"text-xs text-red-600 dark:text-red-400",children:h.message}):h.showHelper?r("p",{id:h.ids.helper,className:m("text-xs",h.invalid?"text-red-600 dark:text-red-400":"text-gray-500 dark:text-gray-400"),children:Pe}):null,ue?n?o.map(e=>r("input",{type:"hidden",name:ue,value:e},e)):r("input",{type:"hidden",name:ue,value:o[0]??""}):null,d&&T?Nt(f("div",{ref:be,className:m("fixed z-50 bg-white text-gray-900 dark:bg-gray-800 dark:text-gray-100 border border-gray-200 dark:border-gray-700","rounded-md shadow-lg overflow-hidden","animate-in fade-in-0 zoom-in-95",E[x].content,it),"data-placement":T.placement,style:{top:T.top,left:T.left,width:T.width,position:"absolute",translate:T.placement==="top"?"0 -100%":void 0},onKeyDown:mt,children:[P?r("div",{className:"border-b-2 border-gray-200 focus-within:border-synertech-primary-500 dark:border-gray-700 dark:focus-within:border-synertech-primary-400",children:r("input",{ref:ye,type:"text",role:"searchbox","aria-label":at??I.selectSearch,"aria-controls":he,"aria-activedescendant":_e,className:m(E[x].searchInput,"w-full outline-hidden bg-transparent text-gray-900 dark:text-gray-100","placeholder:text-gray-500 dark:placeholder:text-gray-400"),placeholder:st??I.selectSearchPlaceholder,value:F,onChange:bt})}):null,f("div",{role:"listbox",id:he,"aria-labelledby":ee?ge:void 0,"aria-multiselectable":n||void 0,className:"overflow-y-auto",style:{maxHeight:pe},children:[S.map((e,t)=>r(Ft,{option:e,isSelected:q.has(e.value),isHighlighted:t===p,isDisabled:g||Ce.has(e.value),multiple:n,sizeKey:x,optionId:`${z}-option-${t}`,onClick:Le,onMouseEnter:k,index:t,ref:s=>{xe.current[t]=s}},e.value)),we?f("div",{ref:e=>{xe.current[B]=e},id:`${z}-option-${B}`,role:"option","aria-selected":!1,"aria-disabled":g||void 0,"data-highlighted":B===p||void 0,className:et(x,B===p,!1,g,n),onMouseDown:J,onClick:g?void 0:Y,onMouseEnter:g?void 0:()=>k(B),children:[r("span",{className:"flex size-4 shrink-0 items-center justify-center text-gray-500 dark:text-gray-400",children:Rt}),r("span",{className:"truncate",children:Ee(I.selectCreateOption,{label:D})})]}):null]}),R===0?r("div",{className:m(E[x].option,"text-gray-500 dark:text-gray-400 text-center py-4"),children:ct}):null]}),Ze(y.current).body):null]})}export{qt as Select};
|
|
1
|
+
"use client";import{useState as Z,useRef as G,useEffect as J,useCallback as i,useMemo as M,useId as wt,memo as Ct,forwardRef as Lt}from"react";import{createPortal as Nt}from"react-dom";import{registerFloatingLayer as It}from"../../lib/aria-hide.js";import{ownerDocumentOf as Ze,ownerWindowOf as St}from"../../lib/owner-document.js";import{formatUILabel as De,useUILabels as Mt}from"../../lib/i18n.js";import{describeField as Et}from"../form/shared/field-error.js";import{jsx as r,jsxs as f}from"react/jsx-runtime";var Dt=[],ie=[],ee=l=>l.preventDefault(),Ot=r("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0",children:r("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Ge=r("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:r("path",{d:"M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Vt=r("svg",{width:"10",height:"10",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:r("path",{d:"M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})}),Pt=f("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0 animate-spin",children:[r("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",strokeOpacity:"0.25"}),r("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),Tt=r("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:r("path",{d:"M11.5 3.5L5.5 10.5L2.5 7.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Bt=r("svg",{width:"10",height:"10",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:r("path",{d:"M11.5 3.5L5.5 10.5L2.5 7.5",stroke:"currentColor",strokeWidth:"2.25",strokeLinecap:"round",strokeLinejoin:"round"})}),Rt=r("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",children:r("path",{d:"M7 2.5V11.5M2.5 7H11.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})}),E={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",frame:"min-h-8 pl-1 pr-2.5 py-1 text-xs gap-1.5",tag:"h-5 pl-1.5 pr-0.5 gap-0.5 text-xs",combobox:"h-5 px-1"},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",frame:"min-h-10 pl-1.5 pr-3 py-1.5 text-sm gap-2",tag:"h-6 pl-2 pr-1 gap-1 text-xs",combobox:"h-6 px-1.5"},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",frame:"min-h-12 pl-2 pr-4 py-2 text-base gap-2.5",tag:"h-7 pl-2.5 pr-1 gap-1 text-sm",combobox:"h-7 px-2"}},Oe={default:{trigger:"border border-gray-300 bg-white dark:border-gray-600 dark:bg-gray-800",focus:"focus:ring-2 focus:ring-synertech-primary-500 focus:border-synertech-primary-500"},outlined:{trigger:"border-2 border-gray-300 bg-transparent dark:border-gray-600",focus:"focus:ring-2 focus:ring-synertech-primary-500 focus:border-synertech-primary-500"},filled:{trigger:"border border-transparent bg-gray-100 dark:bg-gray-700",focus:"focus:ring-2 focus:ring-synertech-primary-500 focus:border-synertech-primary-500"}},At="focus-within:ring-2 focus-within:ring-synertech-primary-500 focus-within:border-synertech-primary-500",Ht="border-red-500 dark:border-red-400 focus-within:ring-2 focus-within:ring-red-500 focus-within:border-red-500";function m(...l){let a="";for(let n=0;n<l.length;n++){let p=l[n];p&&(a&&(a+=" "),a+=p)}return a}function zt(l,a){if(!a)return l;let n=a.toLowerCase();return l.filter(p=>{if(p.label.toLowerCase().includes(n)||p.value.toLowerCase().includes(n))return!0;if(p.keywords){for(let w of p.keywords)if(w.toLowerCase().includes(n))return!0}return!1})}function Je(l,a){if(l!==void 0)return Array.isArray(l)?a?new Set(l).size===l.length?l:Array.from(new Set(l)):l.slice(0,1):l===""?ie:[l]}function et(l,a,n,p,w){return m(E[l].option,"flex items-center gap-2 cursor-pointer select-none transition-colors",a&&!p&&"bg-synertech-primary-50 dark:bg-synertech-primary-900/30",n&&!a&&!w&&"bg-gray-50 dark:bg-gray-700/50",p&&"opacity-50 cursor-not-allowed")}var Ft=Ct(Lt(function({option:a,isSelected:n,isHighlighted:p,isDisabled:w,multiple:z,sizeKey:W,optionId:ce,onClick:de,onMouseEnter:$,index:b},v){let d=()=>{w||de(a.value)},x=()=>{w||$(b)};return f("div",{ref:v,id:ce,role:"option","aria-selected":n,"aria-disabled":w||void 0,"data-highlighted":p||void 0,className:et(W,p,n,w,z),onMouseDown:ee,onClick:d,onMouseEnter:x,children:[z?r("span",{"aria-hidden":"true",className:m("flex size-4 shrink-0 items-center justify-center rounded border-2 transition-colors",n?"border-synertech-primary-600 bg-synertech-primary-600 text-synertech-on-primary":"border-gray-500 dark:border-gray-400"),children:n?Bt:null}):null,a.icon?r("span",{className:"flex shrink-0 items-center",children:a.icon}):null,f("span",{className:"flex flex-col min-w-0 flex-1",children:[r("span",{className:"truncate",children:a.label}),a.description?r("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:a.description}):null]}),n&&!z?r("span",{className:"ml-auto text-synertech-primary-600 dark:text-synertech-primary-400",children:Tt}):null]})}));function qt(l){let{options:a=Dt,multiple:n=!1,value:p,defaultValue:w,onValueChange:z,maxTagCount:W,creatable:ce=!1,searchable:de=!1,clearable:$=!1,disabled:b=!1,readOnly:v=!1,loading:d=!1,size:x="md",variant:ue="default",placeholder:tt,label:te,description:Ve,helperText:Pe,error:rt,required:Te=!1,noOptionsText:nt,clearLabel:Be,searchLabel:at,searchPlaceholder:st,labels:ot,onSearchChange:Re,name:pe,className:lt,triggerClassName:Ae,contentClassName:it,maxHeight:ge=256}=l,C=n&&ce,T=de||C,I=Mt(ot),He=tt??I.selectPlaceholder,ct=nt??I.selectNoOptions,F=wt(),fe=`${F}-label`,he=`${F}-trigger`,me=`${F}-listbox`,h=Et(he,{description:Ve,helperText:Pe,error:rt}),y=G(null),be=G(null),ye=G(null),xe=G(null),ve=G([]),ze=p!==void 0,[ke,dt]=Z(()=>Je(w,n)??ie),Fe=M(()=>Je(p,n),[p,n]),s=M(()=>Fe??(n?ke:ke.slice(0,1)),[Fe,ke,n]),[u,we]=Z(!1),[K,j]=Z(""),[g,k]=Z(-1),[B,Ke]=Z(null),U=M(()=>{let e=new Map;for(let t of a)e.has(t.value)||e.set(t.value,t);return e},[a]),_=M(()=>{if(!C)return a;let e=[];for(let t of s)U.has(t)||e.push({value:t,label:t});return e.length>0?[...a,...e]:a},[C,a,s,U]),S=M(()=>T?zt(_,K):_,[_,K,T]),D=K.trim(),q=M(()=>{if(!C||D==="")return null;let e=D.toLowerCase();return _.find(t=>t.label.toLowerCase()===e)??null},[C,D,_]),Ce=C&&D!==""&&q===null,R=Ce?S.length:-1,A=S.length+(Ce?1:0),Y=M(()=>new Set(s),[s]),re=M(()=>n?null:U.get(s[0]??"")??null,[n,U,s]),Le=M(()=>{let e=new Set;for(let t of a)t.disabled&&e.add(t.value);return e},[a]),ne=i(e=>e<S.length&&Le.has(S[e].value),[S,Le]),je=i(e=>U.get(e)?.label??e,[U]),O=i(e=>{ze||dt(e),z?.(n?e:e[0]??"")},[ze,z,n]),ut=i(e=>{d||(O([e]),we(!1),j(""),k(-1),y.current?.focus())},[O,d]),V=i(e=>{d||O(e)},[O,d]),pt=i(e=>{V(Y.has(e)?s.filter(t=>t!==e):[...s,e])},[V,Y,s]),gt=i(e=>{V(s.filter(t=>t!==e))},[V,s]),ae=i(()=>{s.length!==0&&V(s.slice(0,-1))},[V,s]),Q=i(()=>{if(!C||D===""||d||q?.disabled)return;let e=q?q.value:D;Y.has(e)||V([...s,e]),j(""),k(-1)},[C,D,q,d,Y,V,s]),Ne=n?pt:ut,Ie=i(e=>{if(e===R){Q();return}e<0||e>=S.length||ne(e)||Ne(S[e].value)},[R,Q,S,ne,Ne]),Se=i(()=>{((u&&T?xe.current:null)??y.current)?.focus()},[u,T]),Ue=i(e=>{e.stopPropagation(),O(ie),j(""),Se()},[O,Se]),H=i(()=>{b||v||(we(!0),j(""),k(-1))},[b,v]),L=i(()=>{we(!1),j(""),k(-1),y.current?.focus()},[]),ft=i(()=>{u?L():H()},[u,L,H]),X=i((e,t)=>{let o=A;if(o===0)return-1;let c=e;for(let P=0;P<o;P++)if(c=((c+t)%o+o)%o,!ne(c))return c;return-1},[A,ne]),se=i((e,t)=>{switch(e.key){case"ArrowDown":{e.preventDefault();let o=X(g,1);o!==-1&&k(o);break}case"ArrowUp":{e.preventDefault();let o=X(g,-1);o!==-1&&k(o);break}case"Home":{e.preventDefault();let o=X(-1,1);o!==-1&&k(o);break}case"End":{e.preventDefault();let o=X(A,-1);o!==-1&&k(o);break}case"Enter":{e.preventDefault(),g>=0&&g<A?Ie(g):C&&Q();break}case" ":if(t)break;e.preventDefault(),g>=0&&g<A?Ie(g):L();break;case"Backspace":n&&(!t||K==="")&&(t||e.preventDefault(),ae());break;case"Escape":e.preventDefault(),L();break;case"Tab":L();break}},[X,g,A,Ie,C,Q,L,n,K,ae]),ht=i(e=>{if(!(b||v)){if(u){se(e,!1);return}switch(e.key){case"ArrowDown":case"ArrowUp":e.preventDefault(),H();break;case"Enter":case" ":e.preventDefault(),H();break;case"Backspace":case"Delete":n?e.key==="Backspace"&&s.length>0&&(e.preventDefault(),ae()):$&&!d&&s.length>0&&(e.preventDefault(),O(ie));break}}},[b,v,u,se,H,n,s.length,ae,$,d,O]),mt=i(e=>se(e,!0),[se]),bt=i(e=>{let t=e.target.value;j(t),k(-1),Re?.(t)},[Re]),N=!b&&!v,yt=i(e=>{N&&(y.current?.contains(e.target)||e.preventDefault())},[N]),xt=i(()=>{N&&(u?L():(y.current?.focus(),H()))},[N,u,L,H]);J(()=>{if(!u)return;let e=o=>{let c=o.target;y.current?.contains(c)||be.current?.contains(c)||ye.current?.contains(c)||L()},t=Ze(y.current);return t.addEventListener("mousedown",e),t.addEventListener("touchstart",e,{passive:!0}),()=>{t.removeEventListener("mousedown",e),t.removeEventListener("touchstart",e)}},[u,L]);let vt=n?s.length:0;J(()=>{if(!u||!y.current){Ke(null);return}let e=St(y.current),t=()=>{let o=n?be.current:y.current;if(!o)return;let c=o.getBoundingClientRect(),P=e.innerHeight-c.bottom,Ee=c.top,kt=ge+8,Xe=P<kt&&Ee>P?"top":"bottom";Ke({top:Xe==="bottom"?c.bottom+e.scrollY+4:c.top+e.scrollY-4,left:c.left+e.scrollX,width:c.width,placement:Xe})};return t(),e.addEventListener("scroll",t,!0),e.addEventListener("resize",t),()=>{e.removeEventListener("scroll",t,!0),e.removeEventListener("resize",t)}},[u,ge,n,vt]);let oe=u&&B!==null;J(()=>{oe&&T&&xe.current?.focus()},[oe,T]),J(()=>{let e=ye.current;if(!(!oe||!e))return It(e,()=>y.current)},[oe]),J(()=>{if(g>=0){let e=ve.current[g];e&&typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest"})}},[g]);let le=s.length>0,We=$&&le&&!b&&!v&&!d,$e=N&&!d,_e=u&&g>=0?`${F}-option-${g}`:void 0,qe={ref:y,id:he,type:"button",role:"combobox","aria-expanded":u,"aria-haspopup":"listbox","aria-controls":u?me:void 0,"aria-labelledby":te?fe:void 0,"aria-required":Te||void 0,"aria-invalid":h.invalid||void 0,"aria-describedby":h.describedBy,"aria-activedescendant":_e,disabled:b,onKeyDown:ht},Ye=d?r("span",{className:"text-gray-500 dark:text-gray-400",children:Pt}):null,Qe=r("span",{className:m("text-gray-500 dark:text-gray-400 transition-transform duration-200",u&&"rotate-180"),children:Ot}),Me;if(n){let e=W===void 0||!Number.isFinite(W)?s.length:Math.max(0,Math.floor(W)),t=s.slice(0,e),o=s.length-t.length;Me=f("div",{ref:be,className:m("w-full flex items-center rounded-md transition-colors","text-gray-900 dark:text-gray-100",E[x].frame,Oe[ue].trigger,!h.invalid&&N&&At,h.invalid&&Ht,b&&"opacity-50 cursor-not-allowed bg-gray-50 dark:bg-gray-900",v&&"cursor-default",N&&"cursor-pointer",Ae),onMouseDown:yt,onClick:xt,children:[f("div",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1",children:[t.map(c=>{let P=je(c);return f("span",{className:m("inline-flex max-w-full items-center rounded","bg-synertech-primary-100 text-synertech-primary-700 dark:bg-synertech-primary-900/50 dark:text-synertech-primary-300",E[x].tag,!$e&&"pr-2"),children:[r("span",{className:"min-w-0 truncate","aria-hidden":"true",children:P}),$e?r("button",{type:"button",tabIndex:-1,"aria-label":De(I.selectRemoveValue,{label:P}),className:"flex shrink-0 items-center justify-center rounded-sm p-0.5 hover:bg-synertech-primary-200 dark:hover:bg-synertech-primary-800",onMouseDown:ee,onClick:Ee=>{Ee.stopPropagation(),gt(c),Se()},children:Vt}):null]},c)}),o>0?r("span",{"aria-hidden":"true",className:m("inline-flex items-center rounded bg-gray-100 text-gray-700 dark:bg-gray-700 dark:text-gray-200",E[x].tag,"pr-2"),children:De(I.selectMoreValues,{count:o})}):null,r("button",{...qe,className:m("min-w-8 flex-1 text-left outline-hidden","flex items-center bg-transparent",E[x].combobox,N?"cursor-pointer":b?"cursor-not-allowed":"cursor-default"),children:le?r("span",{className:"sr-only",children:s.map(je).join(", ")}):r("span",{className:"truncate text-gray-600 dark:text-gray-300",children:He})})]}),f("span",{className:"flex items-center gap-1 shrink-0",children:[Ye,We?r("button",{type:"button",tabIndex:-1,"aria-label":Be??I.selectClear,className:"text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 p-0.5 rounded transition-colors",onMouseDown:ee,onClick:Ue,children:Ge}):null,Qe]})]})}else{let e=m("w-full flex items-center justify-between rounded-md transition-colors","text-gray-900 dark:text-gray-100",E[x].trigger,Oe[ue].trigger,!h.invalid&&N&&Oe[ue].focus,h.invalid&&"border-red-500 dark:border-red-400 focus:ring-2 focus:ring-red-500 focus:border-red-500",b&&"opacity-50 cursor-not-allowed bg-gray-50 dark:bg-gray-900",v&&"cursor-default",!b&&!v&&"cursor-pointer",Ae);Me=f("button",{...qe,className:e,onClick:N?ft:void 0,children:[f("span",{className:m("flex items-center gap-2 min-w-0 flex-1 truncate",!le&&"text-gray-600 dark:text-gray-300"),children:[re?.icon?r("span",{className:"flex shrink-0 items-center",children:re.icon}):null,r("span",{className:"truncate",children:le&&re?re.label:He})]}),f("span",{className:"flex items-center gap-1 shrink-0",children:[Ye,We?r("span",{role:"button",tabIndex:-1,"aria-label":Be??I.selectClear,className:"text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 p-0.5 rounded transition-colors",onClick:Ue,onMouseDown:ee,children:Ge}):null,Qe]})]})}return f("div",{className:m("flex flex-col gap-1",lt),children:[te?f("label",{id:fe,htmlFor:he,className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:[te,Te?r("span",{className:"text-red-600 dark:text-red-400 ml-0.5","aria-hidden":"true",children:"*"}):null]}):null,h.hasDescription?r("p",{id:h.ids.description,className:"text-xs text-gray-500 dark:text-gray-400",children:Ve}):null,Me,h.message!==void 0?r("p",{id:h.ids.error,className:"text-xs text-red-600 dark:text-red-400",children:h.message}):h.showHelper?r("p",{id:h.ids.helper,className:m("text-xs",h.invalid?"text-red-600 dark:text-red-400":"text-gray-500 dark:text-gray-400"),children:Pe}):null,pe?n?s.map(e=>r("input",{type:"hidden",name:pe,value:e},e)):r("input",{type:"hidden",name:pe,value:s[0]??""}):null,u&&B?Nt(f("div",{ref:ye,className:m("fixed z-50 bg-white text-gray-900 dark:bg-gray-800 dark:text-gray-100 border border-gray-200 dark:border-gray-700","rounded-md shadow-lg overflow-hidden","animate-in fade-in-0 zoom-in-95",E[x].content,it),"data-placement":B.placement,style:{top:B.top,left:B.left,width:B.width,position:"absolute",translate:B.placement==="top"?"0 -100%":void 0},onKeyDown:mt,children:[T?r("div",{className:"border-b-2 border-gray-200 focus-within:border-synertech-primary-500 dark:border-gray-700 dark:focus-within:border-synertech-primary-400",children:r("input",{ref:xe,type:"text",role:"searchbox","aria-label":at??I.selectSearch,"aria-controls":me,"aria-activedescendant":_e,className:m(E[x].searchInput,"w-full outline-hidden bg-transparent text-gray-900 dark:text-gray-100","placeholder:text-gray-500 dark:placeholder:text-gray-400"),placeholder:st??I.selectSearchPlaceholder,value:K,onChange:bt})}):null,f("div",{role:"listbox",id:me,"aria-labelledby":te?fe:void 0,"aria-multiselectable":n||void 0,className:"overflow-y-auto",style:{maxHeight:ge},children:[S.map((e,t)=>r(Ft,{option:e,isSelected:Y.has(e.value),isHighlighted:t===g,isDisabled:d||Le.has(e.value),multiple:n,sizeKey:x,optionId:`${F}-option-${t}`,onClick:Ne,onMouseEnter:k,index:t,ref:o=>{ve.current[t]=o}},e.value)),Ce?f("div",{ref:e=>{ve.current[R]=e},id:`${F}-option-${R}`,role:"option","aria-selected":!1,"aria-disabled":d||void 0,"data-highlighted":R===g||void 0,className:et(x,R===g,!1,d,n),onMouseDown:ee,onClick:d?void 0:Q,onMouseEnter:d?void 0:()=>k(R),children:[r("span",{className:"flex size-4 shrink-0 items-center justify-center text-gray-500 dark:text-gray-400",children:Rt}),r("span",{className:"truncate",children:De(I.selectCreateOption,{label:D})})]}):null]}),A===0?r("div",{className:m(E[x].option,"text-gray-500 dark:text-gray-400 text-center py-4"),children:ct}):null]}),Ze(y.current).body):null]})}export{qt as Select};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var l=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var k=(n,e)=>{for(var
|
|
1
|
+
"use strict";var l=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var f=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var k=(n,e)=>{for(var t in e)l(n,t,{get:e[t],enumerable:!0})},v=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of f(e))!S.call(n,a)&&a!==t&&l(n,a,{get:()=>e[a],enumerable:!(r=g(e,a))||r.enumerable});return n};var b=n=>v(l({},"__esModule",{value:!0}),n);var N={};k(N,{Skeleton:()=>d});module.exports=b(N);var m=require("../../lib/cn.cjs"),i=require("react/jsx-runtime"),x={text:"rounded h-4 w-full",circular:"rounded-full",rectangular:"rounded-none",rounded:"rounded-lg"},C={pulse:"animate-pulse motion-reduce:animate-none",wave:"animate-shimmer motion-reduce:animate-none bg-gradient-to-r from-gray-200 via-gray-100 to-gray-200 dark:from-gray-700 dark:via-gray-600 dark:to-gray-700 bg-[length:200%_100%]",none:""},A="bg-gray-200 dark:bg-gray-700";function d({variant:n="text",animation:e="pulse",width:t,height:r,count:a=1,className:p,style:c,...s}){let o={...t!==void 0&&{width:typeof t=="number"?`${t}px`:t},...r!==void 0&&{height:typeof r=="number"?`${r}px`:r},...c};n==="circular"&&t&&!r&&(o.height=o.width);let u=(0,m.cn)(A,x[n],C[e],p);return a===1?(0,i.jsx)("div",{className:u,style:o,"aria-busy":"true","aria-live":"polite",...s}):(0,i.jsx)("div",{className:"space-y-2",children:Array.from({length:a}).map((P,y)=>(0,i.jsx)("div",{className:u,style:o,"aria-busy":"true","aria-live":"polite",...s},y))})}d.displayName="Skeleton";0&&(module.exports={Skeleton});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{cn as p}from"../../lib/cn.js";import{jsx as
|
|
1
|
+
import{cn as p}from"../../lib/cn.js";import{jsx as r}from"react/jsx-runtime";var c={text:"rounded h-4 w-full",circular:"rounded-full",rectangular:"rounded-none",rounded:"rounded-lg"},y={pulse:"animate-pulse motion-reduce:animate-none",wave:"animate-shimmer motion-reduce:animate-none bg-gradient-to-r from-gray-200 via-gray-100 to-gray-200 dark:from-gray-700 dark:via-gray-600 dark:to-gray-700 bg-[length:200%_100%]",none:""},g="bg-gray-200 dark:bg-gray-700";function f({variant:a="text",animation:s="pulse",width:e,height:n,count:o=1,className:u,style:m,...i}){let t={...e!==void 0&&{width:typeof e=="number"?`${e}px`:e},...n!==void 0&&{height:typeof n=="number"?`${n}px`:n},...m};a==="circular"&&e&&!n&&(t.height=t.width);let l=p(g,c[a],y[s],u);return o===1?r("div",{className:l,style:t,"aria-busy":"true","aria-live":"polite",...i}):r("div",{className:"space-y-2",children:Array.from({length:o}).map((S,d)=>r("div",{className:l,style:t,"aria-busy":"true","aria-live":"polite",...i},d))})}f.displayName="Skeleton";export{f as Skeleton};
|