@synertech/ui 0.46.1 → 0.46.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/advance-detachable/AdvanceDetachable.cjs +1 -1
- package/dist/components/advance-detachable/AdvanceDetachable.js +1 -1
- package/dist/components/badge/Badge.cjs +1 -1
- package/dist/components/badge/Badge.js +1 -1
- package/dist/components/banner/Banner.cjs +1 -1
- package/dist/components/banner/Banner.js +1 -1
- package/dist/components/breadcrumb/Breadcrumb.cjs +1 -1
- package/dist/components/breadcrumb/Breadcrumb.js +1 -1
- package/dist/components/calendar/Calendar.cjs +1 -1
- package/dist/components/calendar/Calendar.js +1 -1
- package/dist/components/chart/ChartLegend.cjs +1 -1
- package/dist/components/chart/ChartLegend.js +1 -1
- package/dist/components/checkbox/Checkbox.cjs +1 -1
- package/dist/components/checkbox/Checkbox.js +1 -1
- package/dist/components/checkbox/CheckboxGroup.cjs +1 -1
- package/dist/components/checkbox/CheckboxGroup.js +1 -1
- package/dist/components/chip/Chip.cjs +1 -1
- package/dist/components/chip/Chip.js +1 -1
- package/dist/components/circular-progress/CircularProgress.cjs +1 -1
- package/dist/components/circular-progress/CircularProgress.js +1 -1
- package/dist/components/datagrid/DataGrid.cjs +1 -1
- package/dist/components/datagrid/DataGrid.js +1 -1
- package/dist/components/device-mockup/DeviceMockup.cjs +1 -1
- package/dist/components/device-mockup/DeviceMockup.js +1 -1
- package/dist/components/drawer/Drawer.cjs +1 -1
- package/dist/components/drawer/Drawer.js +1 -1
- package/dist/components/dropdown/DropdownItem.cjs +1 -1
- package/dist/components/dropdown/DropdownItem.js +1 -1
- package/dist/components/dropdown/DropdownRadio.cjs +1 -1
- package/dist/components/dropdown/DropdownRadio.js +1 -1
- package/dist/components/dropdown/DropdownSubMenu.cjs +1 -1
- package/dist/components/dropdown/DropdownSubMenu.js +1 -1
- package/dist/components/dropdown/DropdownTrigger.cjs +1 -1
- package/dist/components/dropdown/DropdownTrigger.js +1 -1
- package/dist/components/file-selector/FileSelector.cjs +1 -1
- package/dist/components/file-selector/FileSelector.js +1 -1
- package/dist/components/form/mention-input/MentionInput.cjs +1 -1
- package/dist/components/form/mention-input/MentionInput.js +1 -1
- package/dist/components/form/shared/inputStyles.cjs +1 -1
- package/dist/components/form/shared/inputStyles.js +1 -1
- package/dist/components/header/Header.cjs +1 -1
- package/dist/components/header/Header.js +1 -1
- package/dist/components/help-button/HelpButton.cjs +2 -2
- package/dist/components/help-button/HelpButton.js +3 -3
- package/dist/components/image-uploader/ImageUploader.cjs +1 -1
- package/dist/components/image-uploader/ImageUploader.js +1 -1
- package/dist/components/indicator/Indicator.cjs +1 -1
- package/dist/components/indicator/Indicator.js +1 -1
- package/dist/components/label/Label.cjs +1 -1
- package/dist/components/label/Label.js +1 -1
- package/dist/components/modal/Modal.cjs +1 -1
- package/dist/components/modal/Modal.js +1 -1
- package/dist/components/pagination/Pagination.cjs +1 -1
- package/dist/components/pagination/Pagination.js +1 -1
- package/dist/components/progress-bar/ProgressBar.cjs +1 -1
- package/dist/components/progress-bar/ProgressBar.js +1 -1
- package/dist/components/radio-button/RadioButton.cjs +1 -1
- package/dist/components/radio-button/RadioButton.js +1 -1
- package/dist/components/schema-editor/SchemaEditor.cjs +1 -1
- package/dist/components/schema-editor/SchemaEditor.js +1 -1
- package/dist/components/schema-editor/legend/SchemaLegend.cjs +1 -1
- package/dist/components/schema-editor/legend/SchemaLegend.js +1 -1
- package/dist/components/schema-editor/relations/SchemaRelationRenderer.cjs +1 -1
- package/dist/components/schema-editor/relations/SchemaRelationRenderer.js +1 -1
- package/dist/components/schema-editor/tables/SchemaTableRenderer.cjs +1 -1
- package/dist/components/schema-editor/tables/SchemaTableRenderer.js +1 -1
- package/dist/components/schema-editor/utils/foreign-keys.cjs +1 -0
- package/dist/components/schema-editor/utils/foreign-keys.js +1 -0
- package/dist/components/schema-editor/utils/geometry.cjs +1 -1
- package/dist/components/schema-editor/utils/geometry.js +1 -1
- package/dist/components/schema-editor/utils/sql-export.cjs +5 -5
- package/dist/components/schema-editor/utils/sql-export.js +5 -5
- package/dist/components/select/Select.cjs +1 -1
- package/dist/components/select/Select.js +1 -1
- package/dist/components/sidebar/Sidebar.cjs +1 -1
- package/dist/components/sidebar/Sidebar.js +1 -1
- package/dist/components/slider/Slider.cjs +1 -1
- package/dist/components/slider/Slider.js +1 -1
- package/dist/components/stat-card/StatCard.cjs +1 -1
- package/dist/components/stat-card/StatCard.js +1 -1
- package/dist/components/table/TableHeader.cjs +1 -1
- package/dist/components/table/TableHeader.js +1 -1
- package/dist/components/tabs/TabsTrigger.cjs +1 -1
- package/dist/components/tabs/TabsTrigger.js +1 -1
- package/dist/components/toast/Toast.cjs +1 -1
- package/dist/components/toast/Toast.js +1 -1
- package/dist/components/tooltip/Tooltip.cjs +1 -1
- package/dist/components/tooltip/Tooltip.js +1 -1
- package/dist/components/wizard/Wizard.cjs +1 -1
- package/dist/components/wizard/Wizard.js +1 -1
- package/dist/components/workflow-editor/WorkflowEditor.cjs +1 -1
- package/dist/components/workflow-editor/WorkflowEditor.js +1 -1
- package/dist/index.d.cts +12 -0
- package/dist/index.d.ts +12 -0
- package/dist/lib/editable-target.cjs +1 -0
- package/dist/lib/editable-target.js +1 -0
- package/dist/styles.css +82 -143
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var o=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var x=(
|
|
1
|
+
"use strict";var o=Object.defineProperty;var d=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var x=(r,t)=>{for(var a in t)o(r,a,{get:t[a],enumerable:!0})},g=(r,t,a,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of l(t))!m.call(r,s)&&s!==a&&o(r,s,{get:()=>t[s],enumerable:!(n=d(t,s))||n.enumerable});return r};var p=r=>g(o({},"__esModule",{value:!0}),r);var f={};x(f,{SchemaLegend:()=>N});module.exports=p(f);var i=require("react"),c=require("../../../lib/cn.cjs"),e=require("react/jsx-runtime"),h=()=>(0,e.jsxs)("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),(0,e.jsx)("circle",{cx:"4.5",cy:"11.5",r:"3"})]}),k=()=>(0,e.jsx)("span",{className:"text-xs font-bold text-gray-500 dark:text-gray-400 w-3.5 text-center",children:"?"}),v=()=>(0,e.jsxs)("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"currentColor",children:[(0,e.jsx)("circle",{cx:"8",cy:"8",r:"6",className:"fill-blue-500"}),(0,e.jsx)("path",{d:"M5 8h6M8 5l3 3-3 3",stroke:"white",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})]}),y=()=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5 text-amber-700 dark:text-amber-400",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"M3 2v12M7 4h6M7 8h4M7 12h5"})}),u=()=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5 text-purple-600 dark:text-purple-400",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"M4 2v8a4 4 0 008 0V2"})}),N=(0,i.memo)(function({className:t,labels:a}){return(0,e.jsxs)("div",{className:(0,c.cn)("absolute top-3 right-3 z-20 flex items-center gap-4 bg-white dark:bg-gray-800 rounded-lg shadow-md border border-gray-200 dark:border-gray-600 px-3 py-2",t),"data-testid":"schema-legend",children:[(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,e.jsx)(h,{}),(0,e.jsx)("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorPrimaryKey})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,e.jsx)(k,{}),(0,e.jsx)("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorNullable})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,e.jsx)(v,{}),(0,e.jsx)("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorForeignKey})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,e.jsx)(y,{}),(0,e.jsx)("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorIndex})]}),(0,e.jsxs)("div",{className:"flex items-center gap-1.5",children:[(0,e.jsx)(u,{}),(0,e.jsx)("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorUnique})]})]})});0&&(module.exports={SchemaLegend});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{memo as
|
|
1
|
+
import{memo as s}from"react";import{cn as o}from"../../../lib/cn.js";import{jsx as e,jsxs as t}from"react/jsx-runtime";var n=()=>t("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),e("circle",{cx:"4.5",cy:"11.5",r:"3"})]}),i=()=>e("span",{className:"text-xs font-bold text-gray-500 dark:text-gray-400 w-3.5 text-center",children:"?"}),c=()=>t("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"currentColor",children:[e("circle",{cx:"8",cy:"8",r:"6",className:"fill-blue-500"}),e("path",{d:"M5 8h6M8 5l3 3-3 3",stroke:"white",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})]}),d=()=>e("svg",{className:"w-3.5 h-3.5 text-amber-700 dark:text-amber-400",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e("path",{d:"M3 2v12M7 4h6M7 8h4M7 12h5"})}),l=()=>e("svg",{className:"w-3.5 h-3.5 text-purple-600 dark:text-purple-400",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:e("path",{d:"M4 2v8a4 4 0 008 0V2"})}),p=s(function({className:r,labels:a}){return t("div",{className:o("absolute top-3 right-3 z-20 flex items-center gap-4 bg-white dark:bg-gray-800 rounded-lg shadow-md border border-gray-200 dark:border-gray-600 px-3 py-2",r),"data-testid":"schema-legend",children:[t("div",{className:"flex items-center gap-1.5",children:[e(n,{}),e("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorPrimaryKey})]}),t("div",{className:"flex items-center gap-1.5",children:[e(i,{}),e("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorNullable})]}),t("div",{className:"flex items-center gap-1.5",children:[e(c,{}),e("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorForeignKey})]}),t("div",{className:"flex items-center gap-1.5",children:[e(d,{}),e("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorIndex})]}),t("div",{className:"flex items-center gap-1.5",children:[e(l,{}),e("span",{className:"text-xs text-gray-600 dark:text-gray-300",children:a.schemaEditorUnique})]})]})});export{p as SchemaLegend};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var R=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var N=Object.prototype.hasOwnProperty;var E=(t,n)=>{for(var r in n)R(t,r,{get:n[r],enumerable:!0})},F=(t,n,r,i)=>{if(n&&typeof n=="object"||typeof n=="function")for(let e of w(n))!N.call(t,e)&&e!==r&&R(t,e,{get:()=>n[e],enumerable:!(i=T(n,e))||i.enumerable});return t};var W=t=>F(R({},"__esModule",{value:!0}),t);var L={};E(L,{SchemaRelationRenderer:()=>P});module.exports=W(L);var v=require("react"),l=require("../utils/geometry.cjs"),o=require("react/jsx-runtime");function Y(t,n,r){let i=n.find(a=>a.id===t.from.tableId),e=n.find(a=>a.id===t.to.tableId);if(!i||!e||i.collapsed||e.collapsed)return null;let m=i.fields.findIndex(a=>a.id===t.from.fieldId),y=e.fields.findIndex(a=>a.id===t.to.fieldId);if(m===-1||y===-1)return null;let x=i.width??l.DEFAULT_TABLE_WIDTH,p=e.width??l.DEFAULT_TABLE_WIDTH,c=i.x+x/2,b=e.x+p/2,h=i.y+(0,l.getFieldConnectionY)(m,(0,l.hasNotesRow)(i,r)),u=e.y+(0,l.getFieldConnectionY)(y,(0,l.hasNotesRow)(e,r)),d,s;return c<=b?(d=i.x+x,s=e.x):(d=i.x,s=e.x+p),{x1:d,y1:h,x2:s,y2:u,cardinality:t.cardinality??"1:n"}}var S=["1:1","1:n","n:1","n:n"];function A(t){let n=S.indexOf(t);return S[(n+1)%S.length]}var P=(0,v.memo)(function({relations:n,tables:r,viewport:i,selectedRelationId:e,disabled:m,editable:y,onRelationClick:x,onCardinalityChange:p}){return(0,o.jsx)("svg",{className:"absolute top-0 left-0 pointer-events-none",style:{width:"100%",height:"100%",overflow:"visible"},children:(0,o.jsx)("g",{transform:`translate(${i.x}, ${i.y}) scale(${i.zoom})`,children:n.map(c=>{let b=Y(c,r,y);if(!b)return null;let{x1:h,y1:u,x2:d,y2:s,cardinality:a}=b,C=(0,l.computeBezierPath)(h,u,d,s),f=e===c.id,I=(h+d)/2,k=(u+s)/2;return(0,o.jsxs)("g",{children:[(0,o.jsx)("path",{d:C,fill:"none",stroke:"transparent",strokeWidth:16,className:"pointer-events-auto cursor-pointer",onClick:g=>{m||x?.(c.id,g)}}),(0,o.jsx)("path",{d:C,fill:"none",stroke:f?"#3b82f6":"#9ca3af",strokeWidth:f?2.5:1.5,className:"transition-colors"}),(0,o.jsx)("circle",{cx:h,cy:u,r:3,fill:f?"#3b82f6":"#9ca3af"}),(0,o.jsx)("circle",{cx:d,cy:s,r:3,fill:f?"#3b82f6":"#9ca3af"}),a&&(0,o.jsxs)("g",{className:m?void 0:"pointer-events-auto cursor-pointer",onClick:m?void 0:g=>{g.stopPropagation(),p?.(c.id,A(a))},children:[(0,o.jsx)("rect",{x:I-14,y:k-9,width:28,height:18,rx:4,fill:"white",stroke:f?"#3b82f6":"#d1d5db",strokeWidth:1}),(0,o.jsx)("text",{x:I,y:k+4,textAnchor:"middle",className:"text-[10px] font-mono",fill:f?"#3b82f6":"#6b7280",children:a})]})]},c.id)})})})});0&&(module.exports={SchemaRelationRenderer});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{memo as
|
|
1
|
+
import{memo as w}from"react";import{computeBezierPath as N,DEFAULT_TABLE_WIDTH as I,getFieldConnectionY as k,hasNotesRow as v}from"../utils/geometry.js";import{jsx as o,jsxs as T}from"react/jsx-runtime";function E(i,c,h){let e=c.find(n=>n.id===i.from.tableId),t=c.find(n=>n.id===i.to.tableId);if(!e||!t||e.collapsed||t.collapsed)return null;let d=e.fields.findIndex(n=>n.id===i.from.fieldId),u=t.fields.findIndex(n=>n.id===i.to.fieldId);if(d===-1||u===-1)return null;let y=e.width??I,x=t.width??I,a=e.x+y/2,p=t.x+x/2,m=e.y+k(d,v(e,h)),f=t.y+k(u,v(t,h)),l,r;return a<=p?(l=e.x+y,r=t.x):(l=e.x,r=t.x+x),{x1:l,y1:m,x2:r,y2:f,cardinality:i.cardinality??"1:n"}}var g=["1:1","1:n","n:1","n:n"];function F(i){let c=g.indexOf(i);return g[(c+1)%g.length]}var A=w(function({relations:c,tables:h,viewport:e,selectedRelationId:t,disabled:d,editable:u,onRelationClick:y,onCardinalityChange:x}){return o("svg",{className:"absolute top-0 left-0 pointer-events-none",style:{width:"100%",height:"100%",overflow:"visible"},children:o("g",{transform:`translate(${e.x}, ${e.y}) scale(${e.zoom})`,children:c.map(a=>{let p=E(a,h,u);if(!p)return null;let{x1:m,y1:f,x2:l,y2:r,cardinality:n}=p,R=N(m,f,l,r),s=t===a.id,S=(m+l)/2,C=(f+r)/2;return T("g",{children:[o("path",{d:R,fill:"none",stroke:"transparent",strokeWidth:16,className:"pointer-events-auto cursor-pointer",onClick:b=>{d||y?.(a.id,b)}}),o("path",{d:R,fill:"none",stroke:s?"#3b82f6":"#9ca3af",strokeWidth:s?2.5:1.5,className:"transition-colors"}),o("circle",{cx:m,cy:f,r:3,fill:s?"#3b82f6":"#9ca3af"}),o("circle",{cx:l,cy:r,r:3,fill:s?"#3b82f6":"#9ca3af"}),n&&T("g",{className:d?void 0:"pointer-events-auto cursor-pointer",onClick:d?void 0:b=>{b.stopPropagation(),x?.(a.id,F(n))},children:[o("rect",{x:S-14,y:C-9,width:28,height:18,rx:4,fill:"white",stroke:s?"#3b82f6":"#d1d5db",strokeWidth:1}),o("text",{x:S,y:C+4,textAnchor:"middle",className:"text-[10px] font-mono",fill:s?"#3b82f6":"#6b7280",children:n})]})]},a.id)})})})});export{A as SchemaRelationRenderer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var C=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var Q=(h,o)=>{for(var m in o)C(h,m,{get:o[m],enumerable:!0})},Z=(h,o,m,s)=>{if(o&&typeof o=="object"||typeof o=="function")for(let a of X(o))!J.call(h,a)&&a!==m&&C(h,a,{get:()=>o[a],enumerable:!(s=Y(o,a))||s.enumerable});return h};var $=h=>Z(C({},"__esModule",{value:!0}),h);var ae={};Q(ae,{SchemaTableRenderer:()=>re});module.exports=$(ae);var l=require("react"),g=require("../../../lib/cn.cjs"),d=require("../utils/geometry.cjs"),_=require("../utils/schema-helpers.cjs"),M=require("../../../lib/ui-labels.cjs"),e=require("react/jsx-runtime"),P=()=>(0,e.jsxs)("svg",{className:"w-3.5 h-3.5 text-indigo-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),(0,e.jsx)("circle",{cx:"4.5",cy:"11.5",r:"3"})]}),V=()=>(0,e.jsxs)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[(0,e.jsx)("circle",{cx:"8",cy:"8",r:"6",className:"fill-blue-500"}),(0,e.jsx)("path",{d:"M5 8h6M8 5l3 3-3 3",stroke:"white",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})]}),O=({collapsed:h})=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"currentColor",children:h?(0,e.jsx)("path",{d:"M6 3l5 5-5 5V3z"}):(0,e.jsx)("path",{d:"M3 6l5 5 5-5H3z"})}),F=()=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5 text-amber-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"M3 2v12M7 4h6M7 8h4M7 12h5"})}),H=()=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5 text-purple-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"M4 2v8a4 4 0 008 0V2"})}),ee=()=>(0,e.jsx)("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:(0,e.jsx)("path",{d:"M4 8h8"})}),te=()=>(0,e.jsxs)("svg",{className:"w-3 h-3 text-gray-300",viewBox:"0 0 16 16",fill:"currentColor",children:[(0,e.jsx)("circle",{cx:"5",cy:"4",r:"1.5"}),(0,e.jsx)("circle",{cx:"11",cy:"4",r:"1.5"}),(0,e.jsx)("circle",{cx:"5",cy:"8",r:"1.5"}),(0,e.jsx)("circle",{cx:"11",cy:"8",r:"1.5"}),(0,e.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,e.jsx)("circle",{cx:"11",cy:"12",r:"1.5"})]}),oe=(0,l.memo)(function({field:o,tableId:m,editable:s,readOnly:a,disabled:c,onFieldChange:b,labels:x}){let[k,v]=(0,l.useState)(!1),[f,u]=(0,l.useState)(o.defaultValue??""),w=s&&!a&&!c,N=()=>{v(!1),b?.(m,o.id,{defaultValue:f||void 0})};return w?k?(0,e.jsx)("input",{className:"text-xs w-16 text-emerald-500 bg-transparent border-b border-emerald-300 outline-none focus:ring-0 p-0 flex-shrink-0","aria-label":(0,M.formatUILabel)(x.schemaEditorDefaultValueFor,{field:o.name}),value:f,onChange:p=>u(p.target.value),onBlur:N,onKeyDown:p=>{p.key==="Enter"&&N(),p.key==="Escape"&&v(!1)},onMouseDown:p=>p.stopPropagation(),autoFocus:!0}):o.defaultValue?(0,e.jsxs)("button",{type:"button",className:"text-xs text-emerald-500 flex-shrink-0 truncate max-w-16 cursor-pointer",onClick:p=>{p.stopPropagation(),u(o.defaultValue??""),v(!0)},onMouseDown:p=>p.stopPropagation(),title:(0,M.formatUILabel)(x.schemaEditorDefaultValue,{value:o.defaultValue}),children:["= ",o.defaultValue]}):(0,e.jsx)("button",{type:"button",className:"text-xs text-gray-300 flex-shrink-0 opacity-0 group-hover:opacity-30 hover:!opacity-100 cursor-pointer transition-opacity",onClick:p=>{p.stopPropagation(),u(""),v(!0)},onMouseDown:p=>p.stopPropagation(),title:x.schemaEditorSetDefaultValue,children:"= \u2205"}):o.defaultValue?(0,e.jsxs)("span",{className:"text-xs text-emerald-500 flex-shrink-0 truncate max-w-16",title:(0,M.formatUILabel)(x.schemaEditorDefaultValue,{value:o.defaultValue}),children:["= ",o.defaultValue]}):null}),re=(0,l.memo)(function({table:o,selected:m,disabled:s,readOnly:a,editable:c,dropTarget:b,fieldTypes:x,onTableNameChange:k,onTableNotesChange:v,onToggleCollapse:f,onFieldChange:u,onFieldAdd:w,onFieldRemove:N,onFieldReorder:p,onResizeStart:K,labels:i}){let L=o.width??d.DEFAULT_TABLE_WIDTH,D=o.collapsed??!1,S=x.length>0?x:_.DEFAULT_FIELD_TYPES,[B,T]=(0,l.useState)(null),[R,E]=(0,l.useState)(null),y=(0,l.useRef)(null),z=(0,l.useCallback)(t=>{k?.(o.id,t.target.value)},[o.id,k]),W=(0,l.useCallback)((t,n)=>{u?.(o.id,t,{name:n})},[o.id,u]),U=(0,l.useCallback)((t,n)=>{u?.(o.id,t,{type:n})},[o.id,u]),I=(0,l.useCallback)((t,n)=>{u?.(o.id,t,{primaryKey:!n})},[o.id,u]),A=(0,l.useCallback)((t,n)=>{u?.(o.id,t,{nullable:!n})},[o.id,u]),q=(0,l.useCallback)((t,n)=>{u?.(o.id,t,{indexed:!n})},[o.id,u]),j=(0,l.useCallback)((t,n)=>{u?.(o.id,t,{unique:!n})},[o.id,u]),G=(0,l.useCallback)(()=>{w?.(o.id)},[o.id,w]);return(0,e.jsxs)("div",{"data-table-id":o.id,className:(0,g.cn)("absolute bg-white dark:bg-gray-800 border-2 border-dashed rounded-lg shadow-sm cursor-grab active:cursor-grabbing",o.height?"flex flex-col":void 0,b?"border-green-400 shadow-green-100 dark:shadow-green-900/30 shadow-md":m?"border-blue-500 shadow-blue-100 dark:shadow-blue-900/30":"border-gray-300 dark:border-gray-600",s&&"opacity-60",o.locked&&"!cursor-default"),style:{left:o.x,top:o.y,width:L,height:o.height,userSelect:"none",overflow:o.height?"hidden":void 0},children:[(0,e.jsxs)("div",{className:(0,g.cn)("flex items-center justify-between px-3 gap-2","bg-gray-50 dark:bg-gray-700 border-b border-gray-200 dark:border-gray-600"),style:{height:d.HEADER_HEIGHT},children:[c&&!a&&!s?(0,e.jsx)("input",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text","aria-label":i.schemaEditorTableName,value:o.name,onChange:z,onMouseDown:t=>t.stopPropagation()}):(0,e.jsx)("span",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 truncate",children:o.name}),(0,e.jsx)("button",{type:"button",className:"flex-shrink-0 p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-500 dark:text-gray-400",onClick:t=>{t.stopPropagation(),f?.(o.id)},onMouseDown:t=>t.stopPropagation(),"aria-label":D?i.schemaEditorExpandTable:i.schemaEditorCollapseTable,children:(0,e.jsx)(O,{collapsed:D})})]}),!D&&(c&&!a&&!s?(0,e.jsx)("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:d.NOTES_ROW_HEIGHT},children:(0,e.jsx)("input",{className:"w-full text-xs italic text-gray-400 dark:text-gray-500 bg-transparent border-none outline-none focus:ring-0 p-0 placeholder-gray-400 dark:placeholder-gray-500","aria-label":i.schemaEditorTableNotes,placeholder:i.schemaEditorNotesPlaceholder,value:o.notes??"",onChange:t=>v?.(o.id,t.target.value),onMouseDown:t=>t.stopPropagation()})}):o.notes?(0,e.jsx)("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:d.NOTES_ROW_HEIGHT},children:(0,e.jsx)("span",{className:"text-xs italic text-gray-400 dark:text-gray-500 truncate",children:o.notes})}):null),!D&&(0,e.jsxs)("div",{className:o.height?"overflow-y-auto flex-1 min-h-0":void 0,children:[o.fields.map((t,n)=>(0,e.jsxs)("div",{"data-field-id":t.id,"data-table-id":o.id,className:(0,g.cn)("flex items-center gap-1.5 pr-2 relative group",c&&!a&&!s?"pl-[18px]":"pl-2","border-b border-gray-100 dark:border-gray-700 last:border-b-0",b?"bg-blue-50/50 dark:bg-blue-900/10":"hover:bg-gray-50 dark:hover:bg-gray-700/50",B===n&&"opacity-40",R===n&&"!border-t-2 !border-t-blue-400"),style:{height:d.FIELD_ROW_HEIGHT},draggable:c&&!a&&!s,onDragStart:r=>{!c||a||s||(r.stopPropagation(),y.current=n,T(n),r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",String(n)))},onDragOver:r=>{y.current!==null&&(r.preventDefault(),r.stopPropagation(),E(n))},onDragLeave:()=>{R===n&&E(null)},onDrop:r=>{r.preventDefault(),r.stopPropagation(),y.current!==null&&y.current!==n&&p?.(o.id,y.current,n),y.current=null,T(null),E(null)},onDragEnd:()=>{y.current=null,T(null),E(null)},children:[(0,e.jsx)("div",{"data-connection-side":"left","data-field-id":t.id,"data-table-id":o.id,className:(0,g.cn)("absolute -left-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",b?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-blue-400"),style:{top:d.FIELD_ROW_HEIGHT/2-5}}),c&&!a&&!s&&(0,e.jsx)("span",{className:"absolute left-[3px] cursor-grab active:cursor-grabbing opacity-0 group-hover:opacity-100 transition-opacity z-10",style:{top:d.FIELD_ROW_HEIGHT/2-6},children:(0,e.jsx)(te,{})}),c&&!a&&!s?(0,e.jsx)("button",{type:"button",className:(0,g.cn)("w-4 text-xs font-bold flex-shrink-0 text-center cursor-pointer",t.nullable?"text-gray-400":"text-transparent"),onClick:r=>{r.stopPropagation(),A(t.id,t.nullable??!1)},onMouseDown:r=>r.stopPropagation(),title:t.nullable?i.schemaEditorNullable:i.schemaEditorNotNullable,children:"?"}):(0,e.jsx)("span",{className:(0,g.cn)("w-4 text-xs font-bold flex-shrink-0 text-center",t.nullable?"text-gray-400":"text-transparent"),children:t.nullable?"?":""}),t.primaryKey&&t.foreignKey?(0,e.jsxs)("span",{className:"flex items-center gap-0.5 flex-shrink-0",children:[c&&!a&&!s?(0,e.jsx)("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:r=>{r.stopPropagation(),I(t.id,!0)},onMouseDown:r=>r.stopPropagation(),title:i.schemaEditorRemovePrimaryKey,children:(0,e.jsx)(P,{})}):(0,e.jsx)(P,{}),(0,e.jsx)(V,{})]}):t.primaryKey?c&&!a&&!s?(0,e.jsx)("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:r=>{r.stopPropagation(),I(t.id,!0)},onMouseDown:r=>r.stopPropagation(),title:i.schemaEditorRemovePrimaryKey,children:(0,e.jsx)(P,{})}):(0,e.jsx)(P,{}):t.foreignKey?(0,e.jsx)(V,{}):c&&!a&&!s?(0,e.jsx)("button",{type:"button",className:"w-3.5 h-3.5 flex-shrink-0 rounded text-gray-300 hover:text-indigo-400 transition-colors cursor-pointer",onClick:r=>{r.stopPropagation(),I(t.id,!1)},onMouseDown:r=>r.stopPropagation(),title:i.schemaEditorSetPrimaryKey,"aria-label":i.schemaEditorSetPrimaryKey,children:(0,e.jsxs)("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",opacity:"0.3",children:[(0,e.jsx)("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),(0,e.jsx)("circle",{cx:"4.5",cy:"11.5",r:"3"})]})}):(0,e.jsx)("span",{className:"w-3.5 flex-shrink-0"}),c&&!a&&!s?(0,e.jsx)("input",{className:(0,g.cn)("flex-1 min-w-0 text-xs bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text",t.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),"aria-label":i.schemaEditorFieldName,value:t.name,onChange:r=>W(t.id,r.target.value),onMouseDown:r=>r.stopPropagation()}):(0,e.jsx)("span",{className:(0,g.cn)("flex-1 min-w-0 text-xs truncate",t.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),children:t.name}),c&&!a&&!s?(0,e.jsxs)("select",{className:"text-xs text-gray-400 dark:text-gray-500 bg-transparent border-none outline-none focus:ring-0 p-0 cursor-pointer text-right",value:t.type,onChange:r=>U(t.id,r.target.value),onMouseDown:r=>r.stopPropagation(),children:[S.map(r=>(0,e.jsx)("option",{value:r,children:r},r)),!S.includes(t.type)&&(0,e.jsx)("option",{value:t.type,children:t.type})]}):(0,e.jsx)("span",{className:"text-xs text-gray-400 dark:text-gray-500 flex-shrink-0",children:t.type}),(0,e.jsx)(oe,{field:t,tableId:o.id,editable:c,readOnly:a,disabled:s,onFieldChange:u,labels:i}),t.indexed&&(0,e.jsx)(F,{}),t.unique&&(0,e.jsx)(H,{}),c&&!a&&!s&&(0,e.jsxs)("div",{className:"absolute right-1 top-0 bottom-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity bg-gradient-to-l from-white via-white to-transparent dark:from-gray-800 dark:via-gray-800 pl-4 pr-1 z-10",children:[(0,e.jsx)("button",{type:"button",className:(0,g.cn)("cursor-pointer transition-opacity",t.indexed?"opacity-100":"opacity-30 hover:opacity-100"),onClick:r=>{r.stopPropagation(),q(t.id,t.indexed??!1)},onMouseDown:r=>r.stopPropagation(),title:t.indexed?i.schemaEditorRemoveIndex:i.schemaEditorAddIndex,children:(0,e.jsx)(F,{})}),(0,e.jsx)("button",{type:"button",className:(0,g.cn)("cursor-pointer transition-opacity",t.unique?"opacity-100":"opacity-30 hover:opacity-100"),onClick:r=>{r.stopPropagation(),j(t.id,t.unique??!1)},onMouseDown:r=>r.stopPropagation(),title:t.unique?i.schemaEditorRemoveUnique:i.schemaEditorAddUnique,children:(0,e.jsx)(H,{})}),(0,e.jsx)("button",{type:"button",className:"p-0.5 rounded text-gray-300 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 cursor-pointer",onClick:r=>{r.stopPropagation(),N?.(o.id,t.id)},onMouseDown:r=>r.stopPropagation(),title:i.schemaEditorRemoveField,children:(0,e.jsx)(ee,{})})]}),(0,e.jsx)("div",{"data-connection-side":"right","data-field-id":t.id,"data-table-id":o.id,className:(0,g.cn)("absolute -right-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",b?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-green-400"),style:{top:d.FIELD_ROW_HEIGHT/2-5}})]},t.id)),c&&!a&&!s&&(0,e.jsxs)("button",{type:"button",className:"flex items-center justify-center w-full gap-1 text-xs text-gray-400 hover:text-blue-500 hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors cursor-pointer",style:{height:d.ADD_BUTTON_HEIGHT},onClick:t=>{t.stopPropagation(),G()},onMouseDown:t=>t.stopPropagation(),children:[(0,e.jsx)("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:(0,e.jsx)("path",{d:"M8 4v8M4 8h8"})}),i.schemaEditorAddField]})]}),!s&&!a&&(0,e.jsx)("div",{"data-resize-handle":"corner",className:"absolute -bottom-[5px] -right-[5px] w-[14px] h-[14px] cursor-nwse-resize z-20 group/resize",onMouseDown:t=>{t.stopPropagation(),t.preventDefault();let n=o.height??(0,d.getTableHeight)(o,c);K?.(o.id,t.clientX,t.clientY,L,n)},children:(0,e.jsxs)("svg",{className:"w-full h-full text-gray-300 group-hover/resize:text-blue-400 transition-colors",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,e.jsx)("path",{d:"M12 2v10H2",opacity:"0"}),(0,e.jsx)("path",{d:"M6 12L12 6"}),(0,e.jsx)("path",{d:"M10 12L12 10"})]})})]})});0&&(module.exports={SchemaTableRenderer});
|
|
1
|
+
"use strict";var L=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var X=Object.getOwnPropertyNames;var J=Object.prototype.hasOwnProperty;var Q=(p,r)=>{for(var h in r)L(p,h,{get:r[h],enumerable:!0})},Z=(p,r,h,m)=>{if(r&&typeof r=="object"||typeof r=="function")for(let g of X(r))!J.call(p,g)&&g!==h&&L(p,g,{get:()=>r[g],enumerable:!(m=Y(r,g))||m.enumerable});return p};var $=p=>Z(L({},"__esModule",{value:!0}),p);var ne={};Q(ne,{SchemaTableRenderer:()=>ae});module.exports=$(ne);var s=require("react"),u=require("../../../lib/cn.cjs"),i=require("../utils/geometry.cjs"),K=require("../utils/schema-helpers.cjs"),M=require("../../../lib/ui-labels.cjs"),e=require("react/jsx-runtime"),P=()=>(0,e.jsxs)("svg",{className:"w-3.5 h-3.5 text-indigo-500 dark:text-indigo-400 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,e.jsx)("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),(0,e.jsx)("circle",{cx:"4.5",cy:"11.5",r:"3"})]}),F=()=>(0,e.jsxs)("svg",{className:"w-3.5 h-3.5 flex-shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[(0,e.jsx)("circle",{cx:"8",cy:"8",r:"6",className:"fill-blue-500"}),(0,e.jsx)("path",{d:"M5 8h6M8 5l3 3-3 3",stroke:"white",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})]}),ee=({collapsed:p})=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"currentColor",children:p?(0,e.jsx)("path",{d:"M6 3l5 5-5 5V3z"}):(0,e.jsx)("path",{d:"M3 6l5 5 5-5H3z"})}),H=()=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5 text-amber-700 dark:text-amber-400 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"M3 2v12M7 4h6M7 8h4M7 12h5"})}),_=()=>(0,e.jsx)("svg",{className:"w-3.5 h-3.5 text-purple-600 dark:text-purple-400 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,e.jsx)("path",{d:"M4 2v8a4 4 0 008 0V2"})}),te=()=>(0,e.jsx)("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:(0,e.jsx)("path",{d:"M4 8h8"})}),re=()=>(0,e.jsxs)("svg",{className:"w-3 h-3 text-gray-500 dark:text-gray-400",viewBox:"0 0 16 16",fill:"currentColor",children:[(0,e.jsx)("circle",{cx:"5",cy:"4",r:"1.5"}),(0,e.jsx)("circle",{cx:"11",cy:"4",r:"1.5"}),(0,e.jsx)("circle",{cx:"5",cy:"8",r:"1.5"}),(0,e.jsx)("circle",{cx:"11",cy:"8",r:"1.5"}),(0,e.jsx)("circle",{cx:"5",cy:"12",r:"1.5"}),(0,e.jsx)("circle",{cx:"11",cy:"12",r:"1.5"})]}),oe=(0,s.memo)(function({field:r,tableId:h,editable:m,readOnly:g,disabled:k,onFieldChange:b,labels:x}){let[f,v]=(0,s.useState)(!1),[w,l]=(0,s.useState)(r.defaultValue??""),N=m&&!g&&!k,E=()=>{v(!1),b?.(h,r.id,{defaultValue:w||void 0})};return N?f?(0,e.jsx)("input",{className:"text-xs w-16 text-emerald-700 dark:text-emerald-400 bg-transparent border-b border-emerald-300 outline-none focus:ring-0 p-0 flex-shrink-0","aria-label":(0,M.formatUILabel)(x.schemaEditorDefaultValueFor,{field:r.name}),value:w,onChange:d=>l(d.target.value),onBlur:E,onKeyDown:d=>{d.key==="Enter"&&E(),d.key==="Escape"&&v(!1)},onMouseDown:d=>d.stopPropagation(),autoFocus:!0}):r.defaultValue?(0,e.jsxs)("button",{type:"button",className:"text-xs text-emerald-700 dark:text-emerald-400 flex-shrink-0 truncate max-w-16 cursor-pointer",onClick:d=>{d.stopPropagation(),l(r.defaultValue??""),v(!0)},onMouseDown:d=>d.stopPropagation(),title:(0,M.formatUILabel)(x.schemaEditorDefaultValue,{value:r.defaultValue}),children:["= ",r.defaultValue]}):(0,e.jsx)("button",{type:"button",className:"text-xs text-gray-500 dark:text-gray-400 flex-shrink-0 opacity-0 group-hover:opacity-30 hover:!opacity-100 cursor-pointer transition-opacity",onClick:d=>{d.stopPropagation(),l(""),v(!0)},onMouseDown:d=>d.stopPropagation(),title:x.schemaEditorSetDefaultValue,children:"= \u2205"}):r.defaultValue?(0,e.jsxs)("span",{className:"text-xs text-emerald-700 dark:text-emerald-400 flex-shrink-0 truncate max-w-16",title:(0,M.formatUILabel)(x.schemaEditorDefaultValue,{value:r.defaultValue}),children:["= ",r.defaultValue]}):null}),ae=(0,s.memo)(function({table:r,selected:h,disabled:m,readOnly:g,editable:k,dropTarget:b,fieldTypes:x,onTableNameChange:f,onTableNotesChange:v,onToggleCollapse:w,onFieldChange:l,onFieldAdd:N,onFieldRemove:E,onFieldReorder:d,onResizeStart:B,labels:n}){let S=r.width??i.DEFAULT_TABLE_WIDTH,T=r.collapsed??!1,c=k&&!g&&!m,R=x.length>0?x:K.DEFAULT_FIELD_TYPES,[z,I]=(0,s.useState)(null),[V,D]=(0,s.useState)(null),y=(0,s.useRef)(null),W=(0,s.useCallback)(t=>{f?.(r.id,t.target.value)},[r.id,f]),U=(0,s.useCallback)((t,a)=>{l?.(r.id,t,{name:a})},[r.id,l]),A=(0,s.useCallback)((t,a)=>{l?.(r.id,t,{type:a})},[r.id,l]),C=(0,s.useCallback)((t,a)=>{l?.(r.id,t,{primaryKey:!a})},[r.id,l]),q=(0,s.useCallback)((t,a)=>{l?.(r.id,t,{nullable:!a})},[r.id,l]),j=(0,s.useCallback)((t,a)=>{l?.(r.id,t,{indexed:!a})},[r.id,l]),O=(0,s.useCallback)((t,a)=>{l?.(r.id,t,{unique:!a})},[r.id,l]),G=(0,s.useCallback)(()=>{N?.(r.id)},[r.id,N]);return(0,e.jsxs)("div",{"data-table-id":r.id,className:(0,u.cn)("absolute bg-white dark:bg-gray-800 border-2 border-dashed rounded-lg shadow-sm cursor-grab active:cursor-grabbing",r.height?"flex flex-col":void 0,b?"border-green-400 shadow-green-100 dark:shadow-green-900/30 shadow-md":h?"border-blue-500 shadow-blue-100 dark:shadow-blue-900/30":"border-gray-300 dark:border-gray-600",r.locked&&"!cursor-default"),style:{left:r.x,top:r.y,width:S,height:r.height,userSelect:"none",overflow:r.height?"hidden":void 0},children:[(0,e.jsxs)("div",{className:(0,u.cn)("flex items-center justify-between px-3 gap-2","bg-gray-50 dark:bg-gray-700 border-b border-gray-200 dark:border-gray-600"),style:{height:i.HEADER_HEIGHT},children:[c?(0,e.jsx)("input",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text","aria-label":n.schemaEditorTableName,value:r.name,onChange:W,onMouseDown:t=>t.stopPropagation()}):(0,e.jsx)("span",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 truncate",children:r.name}),(0,e.jsx)("button",{type:"button",className:"flex-shrink-0 p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-500 dark:text-gray-400",onClick:t=>{t.stopPropagation(),w?.(r.id)},onMouseDown:t=>t.stopPropagation(),"aria-label":T?n.schemaEditorExpandTable:n.schemaEditorCollapseTable,children:(0,e.jsx)(ee,{collapsed:T})})]}),(0,i.hasNotesRow)(r,c)&&(c?(0,e.jsx)("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:i.NOTES_ROW_HEIGHT},children:(0,e.jsx)("input",{className:"w-full text-xs italic text-gray-500 dark:text-gray-400 bg-transparent border-none outline-none focus:ring-0 p-0 placeholder-gray-500 dark:placeholder-gray-400","aria-label":n.schemaEditorTableNotes,placeholder:n.schemaEditorNotesPlaceholder,value:r.notes??"",onChange:t=>v?.(r.id,t.target.value),onMouseDown:t=>t.stopPropagation()})}):(0,e.jsx)("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:i.NOTES_ROW_HEIGHT},children:(0,e.jsx)("span",{className:"text-xs italic text-gray-500 dark:text-gray-400 truncate",children:r.notes})})),!T&&(0,e.jsxs)("div",{className:r.height?"overflow-y-auto flex-1 min-h-0":void 0,children:[r.fields.map((t,a)=>(0,e.jsxs)("div",{"data-field-id":t.id,"data-table-id":r.id,className:(0,u.cn)("flex items-center gap-1.5 pr-2 relative group",c?"pl-[18px]":"pl-2","border-b border-gray-100 dark:border-gray-700 last:border-b-0",b?"bg-blue-50/50 dark:bg-blue-900/10":"hover:bg-gray-50 dark:hover:bg-gray-700/50",z===a&&"opacity-40",V===a&&"!border-t-2 !border-t-blue-400"),style:{height:i.FIELD_ROW_HEIGHT},draggable:c,onDragStart:o=>{c&&(o.stopPropagation(),y.current=a,I(a),o.dataTransfer.effectAllowed="move",o.dataTransfer.setData("text/plain",String(a)))},onDragOver:o=>{y.current!==null&&(o.preventDefault(),o.stopPropagation(),D(a))},onDragLeave:()=>{V===a&&D(null)},onDrop:o=>{o.preventDefault(),o.stopPropagation(),y.current!==null&&y.current!==a&&d?.(r.id,y.current,a),y.current=null,I(null),D(null)},onDragEnd:()=>{y.current=null,I(null),D(null)},children:[(0,e.jsx)("div",{"data-connection-side":"left","data-field-id":t.id,"data-table-id":r.id,className:(0,u.cn)("absolute -left-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",b?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-blue-400"),style:{top:i.FIELD_ROW_HEIGHT/2-5}}),c&&(0,e.jsx)("span",{className:"absolute left-[3px] cursor-grab active:cursor-grabbing opacity-0 group-hover:opacity-100 transition-opacity z-10",style:{top:i.FIELD_ROW_HEIGHT/2-6},children:(0,e.jsx)(re,{})}),c?(0,e.jsx)("button",{type:"button",className:(0,u.cn)("w-4 text-xs font-bold flex-shrink-0 text-center cursor-pointer",t.nullable?"text-gray-500 dark:text-gray-400":"text-transparent"),onClick:o=>{o.stopPropagation(),q(t.id,t.nullable??!1)},onMouseDown:o=>o.stopPropagation(),title:t.nullable?n.schemaEditorNullable:n.schemaEditorNotNullable,children:"?"}):(0,e.jsx)("span",{className:(0,u.cn)("w-4 text-xs font-bold flex-shrink-0 text-center",t.nullable?"text-gray-500 dark:text-gray-400":"text-transparent"),children:t.nullable?"?":""}),t.primaryKey&&t.foreignKey?(0,e.jsxs)("span",{className:"flex items-center gap-0.5 flex-shrink-0",children:[c?(0,e.jsx)("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:o=>{o.stopPropagation(),C(t.id,!0)},onMouseDown:o=>o.stopPropagation(),title:n.schemaEditorRemovePrimaryKey,children:(0,e.jsx)(P,{})}):(0,e.jsx)(P,{}),(0,e.jsx)(F,{})]}):t.primaryKey?c?(0,e.jsx)("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:o=>{o.stopPropagation(),C(t.id,!0)},onMouseDown:o=>o.stopPropagation(),title:n.schemaEditorRemovePrimaryKey,children:(0,e.jsx)(P,{})}):(0,e.jsx)(P,{}):t.foreignKey?(0,e.jsx)(F,{}):c?(0,e.jsx)("button",{type:"button",className:"w-3.5 h-3.5 flex-shrink-0 rounded text-gray-500 dark:text-gray-400 hover:text-indigo-400 transition-colors cursor-pointer",onClick:o=>{o.stopPropagation(),C(t.id,!1)},onMouseDown:o=>o.stopPropagation(),title:n.schemaEditorSetPrimaryKey,"aria-label":n.schemaEditorSetPrimaryKey,children:(0,e.jsxs)("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",opacity:"0.3",children:[(0,e.jsx)("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),(0,e.jsx)("circle",{cx:"4.5",cy:"11.5",r:"3"})]})}):(0,e.jsx)("span",{className:"w-3.5 flex-shrink-0"}),c?(0,e.jsx)("input",{className:(0,u.cn)("flex-1 min-w-0 text-xs bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text",t.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),"aria-label":n.schemaEditorFieldName,value:t.name,onChange:o=>U(t.id,o.target.value),onMouseDown:o=>o.stopPropagation()}):(0,e.jsx)("span",{className:(0,u.cn)("flex-1 min-w-0 text-xs truncate",t.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),children:t.name}),c?(0,e.jsxs)("select",{className:"text-xs text-gray-500 dark:text-gray-400 bg-transparent border-none outline-none focus:ring-0 p-0 cursor-pointer text-right",value:t.type,onChange:o=>A(t.id,o.target.value),onMouseDown:o=>o.stopPropagation(),children:[R.map(o=>(0,e.jsx)("option",{value:o,children:o},o)),!R.includes(t.type)&&(0,e.jsx)("option",{value:t.type,children:t.type})]}):(0,e.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400 flex-shrink-0",children:t.type}),(0,e.jsx)(oe,{field:t,tableId:r.id,editable:k,readOnly:g,disabled:m,onFieldChange:l,labels:n}),t.indexed&&(0,e.jsx)(H,{}),t.unique&&(0,e.jsx)(_,{}),c&&(0,e.jsxs)("div",{className:"absolute right-1 top-0 bottom-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity bg-gradient-to-l from-white via-white to-transparent dark:from-gray-800 dark:via-gray-800 pl-4 pr-1 z-10",children:[(0,e.jsx)("button",{type:"button",className:(0,u.cn)("cursor-pointer transition-opacity",t.indexed?"opacity-100":"opacity-30 hover:opacity-100"),onClick:o=>{o.stopPropagation(),j(t.id,t.indexed??!1)},onMouseDown:o=>o.stopPropagation(),title:t.indexed?n.schemaEditorRemoveIndex:n.schemaEditorAddIndex,children:(0,e.jsx)(H,{})}),(0,e.jsx)("button",{type:"button",className:(0,u.cn)("cursor-pointer transition-opacity",t.unique?"opacity-100":"opacity-30 hover:opacity-100"),onClick:o=>{o.stopPropagation(),O(t.id,t.unique??!1)},onMouseDown:o=>o.stopPropagation(),title:t.unique?n.schemaEditorRemoveUnique:n.schemaEditorAddUnique,children:(0,e.jsx)(_,{})}),(0,e.jsx)("button",{type:"button",className:"p-0.5 rounded text-gray-500 dark:text-gray-400 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 cursor-pointer",onClick:o=>{o.stopPropagation(),E?.(r.id,t.id)},onMouseDown:o=>o.stopPropagation(),title:n.schemaEditorRemoveField,children:(0,e.jsx)(te,{})})]}),(0,e.jsx)("div",{"data-connection-side":"right","data-field-id":t.id,"data-table-id":r.id,className:(0,u.cn)("absolute -right-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",b?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-green-400"),style:{top:i.FIELD_ROW_HEIGHT/2-5}})]},t.id)),c&&(0,e.jsxs)("button",{type:"button",className:"flex items-center justify-center w-full gap-1 text-xs text-gray-500 dark:text-gray-400 hover:text-blue-600 hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors cursor-pointer",style:{height:i.ADD_BUTTON_HEIGHT},onClick:t=>{t.stopPropagation(),G()},onMouseDown:t=>t.stopPropagation(),children:[(0,e.jsx)("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:(0,e.jsx)("path",{d:"M8 4v8M4 8h8"})}),n.schemaEditorAddField]})]}),!m&&!g&&(0,e.jsx)("div",{"data-resize-handle":"corner",className:"absolute -bottom-[5px] -right-[5px] w-[14px] h-[14px] cursor-nwse-resize z-20 group/resize",onMouseDown:t=>{t.stopPropagation(),t.preventDefault();let a=r.height??(0,i.getTableHeight)(r,c);B?.(r.id,t.clientX,t.clientY,S,a)},children:(0,e.jsxs)("svg",{className:"w-full h-full text-gray-500 dark:text-gray-400 group-hover/resize:text-blue-400 transition-colors",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[(0,e.jsx)("path",{d:"M12 2v10H2",opacity:"0"}),(0,e.jsx)("path",{d:"M6 12L12 6"}),(0,e.jsx)("path",{d:"M10 12L12 10"})]})})]})});0&&(module.exports={SchemaTableRenderer});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{memo as B,useCallback as g,useRef as J,useState as P}from"react";import{cn as d}from"../../../lib/cn.js";import{ADD_BUTTON_HEIGHT as Q,DEFAULT_TABLE_WIDTH as Z,FIELD_ROW_HEIGHT as D,getTableHeight as $,HEADER_HEIGHT as O,NOTES_ROW_HEIGHT as F}from"../utils/geometry.js";import{DEFAULT_FIELD_TYPES as ee}from"../utils/schema-helpers.js";import{formatUILabel as L}from"../../../lib/ui-labels.js";import{jsx as t,jsxs as p}from"react/jsx-runtime";var E=()=>p("svg",{className:"w-3.5 h-3.5 text-indigo-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),t("circle",{cx:"4.5",cy:"11.5",r:"3"})]}),H=()=>p("svg",{className:"w-3.5 h-3.5 flex-shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[t("circle",{cx:"8",cy:"8",r:"6",className:"fill-blue-500"}),t("path",{d:"M5 8h6M8 5l3 3-3 3",stroke:"white",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})]}),te=({collapsed:M})=>t("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"currentColor",children:M?t("path",{d:"M6 3l5 5-5 5V3z"}):t("path",{d:"M3 6l5 5 5-5H3z"})}),_=()=>t("svg",{className:"w-3.5 h-3.5 text-amber-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:t("path",{d:"M3 2v12M7 4h6M7 8h4M7 12h5"})}),K=()=>t("svg",{className:"w-3.5 h-3.5 text-purple-500 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:t("path",{d:"M4 2v8a4 4 0 008 0V2"})}),oe=()=>t("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:t("path",{d:"M4 8h8"})}),re=()=>p("svg",{className:"w-3 h-3 text-gray-300",viewBox:"0 0 16 16",fill:"currentColor",children:[t("circle",{cx:"5",cy:"4",r:"1.5"}),t("circle",{cx:"11",cy:"4",r:"1.5"}),t("circle",{cx:"5",cy:"8",r:"1.5"}),t("circle",{cx:"11",cy:"8",r:"1.5"}),t("circle",{cx:"5",cy:"12",r:"1.5"}),t("circle",{cx:"11",cy:"12",r:"1.5"})]}),ae=B(function({field:o,tableId:T,editable:n,readOnly:i,disabled:l,onFieldChange:x,labels:h}){let[b,y]=P(!1),[v,c]=P(o.defaultValue??""),k=n&&!i&&!l,f=()=>{y(!1),x?.(T,o.id,{defaultValue:v||void 0})};return k?b?t("input",{className:"text-xs w-16 text-emerald-500 bg-transparent border-b border-emerald-300 outline-none focus:ring-0 p-0 flex-shrink-0","aria-label":L(h.schemaEditorDefaultValueFor,{field:o.name}),value:v,onChange:u=>c(u.target.value),onBlur:f,onKeyDown:u=>{u.key==="Enter"&&f(),u.key==="Escape"&&y(!1)},onMouseDown:u=>u.stopPropagation(),autoFocus:!0}):o.defaultValue?p("button",{type:"button",className:"text-xs text-emerald-500 flex-shrink-0 truncate max-w-16 cursor-pointer",onClick:u=>{u.stopPropagation(),c(o.defaultValue??""),y(!0)},onMouseDown:u=>u.stopPropagation(),title:L(h.schemaEditorDefaultValue,{value:o.defaultValue}),children:["= ",o.defaultValue]}):t("button",{type:"button",className:"text-xs text-gray-300 flex-shrink-0 opacity-0 group-hover:opacity-30 hover:!opacity-100 cursor-pointer transition-opacity",onClick:u=>{u.stopPropagation(),c(""),y(!0)},onMouseDown:u=>u.stopPropagation(),title:h.schemaEditorSetDefaultValue,children:"= \u2205"}):o.defaultValue?p("span",{className:"text-xs text-emerald-500 flex-shrink-0 truncate max-w-16",title:L(h.schemaEditorDefaultValue,{value:o.defaultValue}),children:["= ",o.defaultValue]}):null}),ue=B(function({table:o,selected:T,disabled:n,readOnly:i,editable:l,dropTarget:x,fieldTypes:h,onTableNameChange:b,onTableNotesChange:y,onToggleCollapse:v,onFieldChange:c,onFieldAdd:k,onFieldRemove:f,onFieldReorder:u,onResizeStart:z,labels:s}){let S=o.width??Z,w=o.collapsed??!1,R=h.length>0?h:ee,[W,I]=P(null),[V,N]=P(null),m=J(null),U=g(e=>{b?.(o.id,e.target.value)},[o.id,b]),A=g((e,a)=>{c?.(o.id,e,{name:a})},[o.id,c]),q=g((e,a)=>{c?.(o.id,e,{type:a})},[o.id,c]),C=g((e,a)=>{c?.(o.id,e,{primaryKey:!a})},[o.id,c]),j=g((e,a)=>{c?.(o.id,e,{nullable:!a})},[o.id,c]),G=g((e,a)=>{c?.(o.id,e,{indexed:!a})},[o.id,c]),Y=g((e,a)=>{c?.(o.id,e,{unique:!a})},[o.id,c]),X=g(()=>{k?.(o.id)},[o.id,k]);return p("div",{"data-table-id":o.id,className:d("absolute bg-white dark:bg-gray-800 border-2 border-dashed rounded-lg shadow-sm cursor-grab active:cursor-grabbing",o.height?"flex flex-col":void 0,x?"border-green-400 shadow-green-100 dark:shadow-green-900/30 shadow-md":T?"border-blue-500 shadow-blue-100 dark:shadow-blue-900/30":"border-gray-300 dark:border-gray-600",n&&"opacity-60",o.locked&&"!cursor-default"),style:{left:o.x,top:o.y,width:S,height:o.height,userSelect:"none",overflow:o.height?"hidden":void 0},children:[p("div",{className:d("flex items-center justify-between px-3 gap-2","bg-gray-50 dark:bg-gray-700 border-b border-gray-200 dark:border-gray-600"),style:{height:O},children:[l&&!i&&!n?t("input",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text","aria-label":s.schemaEditorTableName,value:o.name,onChange:U,onMouseDown:e=>e.stopPropagation()}):t("span",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 truncate",children:o.name}),t("button",{type:"button",className:"flex-shrink-0 p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-500 dark:text-gray-400",onClick:e=>{e.stopPropagation(),v?.(o.id)},onMouseDown:e=>e.stopPropagation(),"aria-label":w?s.schemaEditorExpandTable:s.schemaEditorCollapseTable,children:t(te,{collapsed:w})})]}),!w&&(l&&!i&&!n?t("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:F},children:t("input",{className:"w-full text-xs italic text-gray-400 dark:text-gray-500 bg-transparent border-none outline-none focus:ring-0 p-0 placeholder-gray-400 dark:placeholder-gray-500","aria-label":s.schemaEditorTableNotes,placeholder:s.schemaEditorNotesPlaceholder,value:o.notes??"",onChange:e=>y?.(o.id,e.target.value),onMouseDown:e=>e.stopPropagation()})}):o.notes?t("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:F},children:t("span",{className:"text-xs italic text-gray-400 dark:text-gray-500 truncate",children:o.notes})}):null),!w&&p("div",{className:o.height?"overflow-y-auto flex-1 min-h-0":void 0,children:[o.fields.map((e,a)=>p("div",{"data-field-id":e.id,"data-table-id":o.id,className:d("flex items-center gap-1.5 pr-2 relative group",l&&!i&&!n?"pl-[18px]":"pl-2","border-b border-gray-100 dark:border-gray-700 last:border-b-0",x?"bg-blue-50/50 dark:bg-blue-900/10":"hover:bg-gray-50 dark:hover:bg-gray-700/50",W===a&&"opacity-40",V===a&&"!border-t-2 !border-t-blue-400"),style:{height:D},draggable:l&&!i&&!n,onDragStart:r=>{!l||i||n||(r.stopPropagation(),m.current=a,I(a),r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",String(a)))},onDragOver:r=>{m.current!==null&&(r.preventDefault(),r.stopPropagation(),N(a))},onDragLeave:()=>{V===a&&N(null)},onDrop:r=>{r.preventDefault(),r.stopPropagation(),m.current!==null&&m.current!==a&&u?.(o.id,m.current,a),m.current=null,I(null),N(null)},onDragEnd:()=>{m.current=null,I(null),N(null)},children:[t("div",{"data-connection-side":"left","data-field-id":e.id,"data-table-id":o.id,className:d("absolute -left-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",x?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-blue-400"),style:{top:D/2-5}}),l&&!i&&!n&&t("span",{className:"absolute left-[3px] cursor-grab active:cursor-grabbing opacity-0 group-hover:opacity-100 transition-opacity z-10",style:{top:D/2-6},children:t(re,{})}),l&&!i&&!n?t("button",{type:"button",className:d("w-4 text-xs font-bold flex-shrink-0 text-center cursor-pointer",e.nullable?"text-gray-400":"text-transparent"),onClick:r=>{r.stopPropagation(),j(e.id,e.nullable??!1)},onMouseDown:r=>r.stopPropagation(),title:e.nullable?s.schemaEditorNullable:s.schemaEditorNotNullable,children:"?"}):t("span",{className:d("w-4 text-xs font-bold flex-shrink-0 text-center",e.nullable?"text-gray-400":"text-transparent"),children:e.nullable?"?":""}),e.primaryKey&&e.foreignKey?p("span",{className:"flex items-center gap-0.5 flex-shrink-0",children:[l&&!i&&!n?t("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:r=>{r.stopPropagation(),C(e.id,!0)},onMouseDown:r=>r.stopPropagation(),title:s.schemaEditorRemovePrimaryKey,children:t(E,{})}):t(E,{}),t(H,{})]}):e.primaryKey?l&&!i&&!n?t("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:r=>{r.stopPropagation(),C(e.id,!0)},onMouseDown:r=>r.stopPropagation(),title:s.schemaEditorRemovePrimaryKey,children:t(E,{})}):t(E,{}):e.foreignKey?t(H,{}):l&&!i&&!n?t("button",{type:"button",className:"w-3.5 h-3.5 flex-shrink-0 rounded text-gray-300 hover:text-indigo-400 transition-colors cursor-pointer",onClick:r=>{r.stopPropagation(),C(e.id,!1)},onMouseDown:r=>r.stopPropagation(),title:s.schemaEditorSetPrimaryKey,"aria-label":s.schemaEditorSetPrimaryKey,children:p("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",opacity:"0.3",children:[t("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),t("circle",{cx:"4.5",cy:"11.5",r:"3"})]})}):t("span",{className:"w-3.5 flex-shrink-0"}),l&&!i&&!n?t("input",{className:d("flex-1 min-w-0 text-xs bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text",e.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),"aria-label":s.schemaEditorFieldName,value:e.name,onChange:r=>A(e.id,r.target.value),onMouseDown:r=>r.stopPropagation()}):t("span",{className:d("flex-1 min-w-0 text-xs truncate",e.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),children:e.name}),l&&!i&&!n?p("select",{className:"text-xs text-gray-400 dark:text-gray-500 bg-transparent border-none outline-none focus:ring-0 p-0 cursor-pointer text-right",value:e.type,onChange:r=>q(e.id,r.target.value),onMouseDown:r=>r.stopPropagation(),children:[R.map(r=>t("option",{value:r,children:r},r)),!R.includes(e.type)&&t("option",{value:e.type,children:e.type})]}):t("span",{className:"text-xs text-gray-400 dark:text-gray-500 flex-shrink-0",children:e.type}),t(ae,{field:e,tableId:o.id,editable:l,readOnly:i,disabled:n,onFieldChange:c,labels:s}),e.indexed&&t(_,{}),e.unique&&t(K,{}),l&&!i&&!n&&p("div",{className:"absolute right-1 top-0 bottom-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity bg-gradient-to-l from-white via-white to-transparent dark:from-gray-800 dark:via-gray-800 pl-4 pr-1 z-10",children:[t("button",{type:"button",className:d("cursor-pointer transition-opacity",e.indexed?"opacity-100":"opacity-30 hover:opacity-100"),onClick:r=>{r.stopPropagation(),G(e.id,e.indexed??!1)},onMouseDown:r=>r.stopPropagation(),title:e.indexed?s.schemaEditorRemoveIndex:s.schemaEditorAddIndex,children:t(_,{})}),t("button",{type:"button",className:d("cursor-pointer transition-opacity",e.unique?"opacity-100":"opacity-30 hover:opacity-100"),onClick:r=>{r.stopPropagation(),Y(e.id,e.unique??!1)},onMouseDown:r=>r.stopPropagation(),title:e.unique?s.schemaEditorRemoveUnique:s.schemaEditorAddUnique,children:t(K,{})}),t("button",{type:"button",className:"p-0.5 rounded text-gray-300 hover:text-red-500 hover:bg-red-50 dark:hover:bg-red-900/20 cursor-pointer",onClick:r=>{r.stopPropagation(),f?.(o.id,e.id)},onMouseDown:r=>r.stopPropagation(),title:s.schemaEditorRemoveField,children:t(oe,{})})]}),t("div",{"data-connection-side":"right","data-field-id":e.id,"data-table-id":o.id,className:d("absolute -right-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",x?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-green-400"),style:{top:D/2-5}})]},e.id)),l&&!i&&!n&&p("button",{type:"button",className:"flex items-center justify-center w-full gap-1 text-xs text-gray-400 hover:text-blue-500 hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors cursor-pointer",style:{height:Q},onClick:e=>{e.stopPropagation(),X()},onMouseDown:e=>e.stopPropagation(),children:[t("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:t("path",{d:"M8 4v8M4 8h8"})}),s.schemaEditorAddField]})]}),!n&&!i&&t("div",{"data-resize-handle":"corner",className:"absolute -bottom-[5px] -right-[5px] w-[14px] h-[14px] cursor-nwse-resize z-20 group/resize",onMouseDown:e=>{e.stopPropagation(),e.preventDefault();let a=o.height??$(o,l);z?.(o.id,e.clientX,e.clientY,S,a)},children:p("svg",{className:"w-full h-full text-gray-300 group-hover/resize:text-blue-400 transition-colors",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[t("path",{d:"M12 2v10H2",opacity:"0"}),t("path",{d:"M6 12L12 6"}),t("path",{d:"M10 12L12 10"})]})})]})});export{ue as SchemaTableRenderer};
|
|
1
|
+
import{memo as z,useCallback as u,useRef as J,useState as P}from"react";import{cn as c}from"../../../lib/cn.js";import{ADD_BUTTON_HEIGHT as Q,DEFAULT_TABLE_WIDTH as Z,FIELD_ROW_HEIGHT as E,getTableHeight as $,hasNotesRow as ee,HEADER_HEIGHT as te,NOTES_ROW_HEIGHT as H}from"../utils/geometry.js";import{DEFAULT_FIELD_TYPES as re}from"../utils/schema-helpers.js";import{formatUILabel as S}from"../../../lib/ui-labels.js";import{jsx as t,jsxs as d}from"react/jsx-runtime";var D=()=>d("svg",{className:"w-3.5 h-3.5 text-indigo-500 dark:text-indigo-400 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[t("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),t("circle",{cx:"4.5",cy:"11.5",r:"3"})]}),_=()=>d("svg",{className:"w-3.5 h-3.5 flex-shrink-0",viewBox:"0 0 16 16",fill:"currentColor",children:[t("circle",{cx:"8",cy:"8",r:"6",className:"fill-blue-500"}),t("path",{d:"M5 8h6M8 5l3 3-3 3",stroke:"white",strokeWidth:"1.5",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"})]}),oe=({collapsed:M})=>t("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"currentColor",children:M?t("path",{d:"M6 3l5 5-5 5V3z"}):t("path",{d:"M3 6l5 5 5-5H3z"})}),K=()=>t("svg",{className:"w-3.5 h-3.5 text-amber-700 dark:text-amber-400 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:t("path",{d:"M3 2v12M7 4h6M7 8h4M7 12h5"})}),B=()=>t("svg",{className:"w-3.5 h-3.5 text-purple-600 dark:text-purple-400 flex-shrink-0",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:t("path",{d:"M4 2v8a4 4 0 008 0V2"})}),ae=()=>t("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:t("path",{d:"M4 8h8"})}),ne=()=>d("svg",{className:"w-3 h-3 text-gray-500 dark:text-gray-400",viewBox:"0 0 16 16",fill:"currentColor",children:[t("circle",{cx:"5",cy:"4",r:"1.5"}),t("circle",{cx:"11",cy:"4",r:"1.5"}),t("circle",{cx:"5",cy:"8",r:"1.5"}),t("circle",{cx:"11",cy:"8",r:"1.5"}),t("circle",{cx:"5",cy:"12",r:"1.5"}),t("circle",{cx:"11",cy:"12",r:"1.5"})]}),se=z(function({field:r,tableId:T,editable:x,readOnly:y,disabled:b,onFieldChange:h,labels:p}){let[v,m]=P(!1),[k,s]=P(r.defaultValue??""),f=x&&!y&&!b,w=()=>{m(!1),h?.(T,r.id,{defaultValue:k||void 0})};return f?v?t("input",{className:"text-xs w-16 text-emerald-700 dark:text-emerald-400 bg-transparent border-b border-emerald-300 outline-none focus:ring-0 p-0 flex-shrink-0","aria-label":S(p.schemaEditorDefaultValueFor,{field:r.name}),value:k,onChange:i=>s(i.target.value),onBlur:w,onKeyDown:i=>{i.key==="Enter"&&w(),i.key==="Escape"&&m(!1)},onMouseDown:i=>i.stopPropagation(),autoFocus:!0}):r.defaultValue?d("button",{type:"button",className:"text-xs text-emerald-700 dark:text-emerald-400 flex-shrink-0 truncate max-w-16 cursor-pointer",onClick:i=>{i.stopPropagation(),s(r.defaultValue??""),m(!0)},onMouseDown:i=>i.stopPropagation(),title:S(p.schemaEditorDefaultValue,{value:r.defaultValue}),children:["= ",r.defaultValue]}):t("button",{type:"button",className:"text-xs text-gray-500 dark:text-gray-400 flex-shrink-0 opacity-0 group-hover:opacity-30 hover:!opacity-100 cursor-pointer transition-opacity",onClick:i=>{i.stopPropagation(),s(""),m(!0)},onMouseDown:i=>i.stopPropagation(),title:p.schemaEditorSetDefaultValue,children:"= \u2205"}):r.defaultValue?d("span",{className:"text-xs text-emerald-700 dark:text-emerald-400 flex-shrink-0 truncate max-w-16",title:S(p.schemaEditorDefaultValue,{value:r.defaultValue}),children:["= ",r.defaultValue]}):null}),pe=z(function({table:r,selected:T,disabled:x,readOnly:y,editable:b,dropTarget:h,fieldTypes:p,onTableNameChange:v,onTableNotesChange:m,onToggleCollapse:k,onFieldChange:s,onFieldAdd:f,onFieldRemove:w,onFieldReorder:i,onResizeStart:W,labels:n}){let R=r.width??Z,I=r.collapsed??!1,l=b&&!y&&!x,V=p.length>0?p:re,[U,C]=P(null),[F,N]=P(null),g=J(null),A=u(e=>{v?.(r.id,e.target.value)},[r.id,v]),q=u((e,a)=>{s?.(r.id,e,{name:a})},[r.id,s]),j=u((e,a)=>{s?.(r.id,e,{type:a})},[r.id,s]),L=u((e,a)=>{s?.(r.id,e,{primaryKey:!a})},[r.id,s]),O=u((e,a)=>{s?.(r.id,e,{nullable:!a})},[r.id,s]),G=u((e,a)=>{s?.(r.id,e,{indexed:!a})},[r.id,s]),Y=u((e,a)=>{s?.(r.id,e,{unique:!a})},[r.id,s]),X=u(()=>{f?.(r.id)},[r.id,f]);return d("div",{"data-table-id":r.id,className:c("absolute bg-white dark:bg-gray-800 border-2 border-dashed rounded-lg shadow-sm cursor-grab active:cursor-grabbing",r.height?"flex flex-col":void 0,h?"border-green-400 shadow-green-100 dark:shadow-green-900/30 shadow-md":T?"border-blue-500 shadow-blue-100 dark:shadow-blue-900/30":"border-gray-300 dark:border-gray-600",r.locked&&"!cursor-default"),style:{left:r.x,top:r.y,width:R,height:r.height,userSelect:"none",overflow:r.height?"hidden":void 0},children:[d("div",{className:c("flex items-center justify-between px-3 gap-2","bg-gray-50 dark:bg-gray-700 border-b border-gray-200 dark:border-gray-600"),style:{height:te},children:[l?t("input",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text","aria-label":n.schemaEditorTableName,value:r.name,onChange:A,onMouseDown:e=>e.stopPropagation()}):t("span",{className:"flex-1 min-w-0 text-sm font-semibold text-gray-800 dark:text-gray-100 truncate",children:r.name}),t("button",{type:"button",className:"flex-shrink-0 p-1 rounded hover:bg-gray-200 dark:hover:bg-gray-600 text-gray-500 dark:text-gray-400",onClick:e=>{e.stopPropagation(),k?.(r.id)},onMouseDown:e=>e.stopPropagation(),"aria-label":I?n.schemaEditorExpandTable:n.schemaEditorCollapseTable,children:t(oe,{collapsed:I})})]}),ee(r,l)&&(l?t("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:H},children:t("input",{className:"w-full text-xs italic text-gray-500 dark:text-gray-400 bg-transparent border-none outline-none focus:ring-0 p-0 placeholder-gray-500 dark:placeholder-gray-400","aria-label":n.schemaEditorTableNotes,placeholder:n.schemaEditorNotesPlaceholder,value:r.notes??"",onChange:e=>m?.(r.id,e.target.value),onMouseDown:e=>e.stopPropagation()})}):t("div",{className:"px-3 border-b border-gray-100 dark:border-gray-700 flex items-center",style:{height:H},children:t("span",{className:"text-xs italic text-gray-500 dark:text-gray-400 truncate",children:r.notes})})),!I&&d("div",{className:r.height?"overflow-y-auto flex-1 min-h-0":void 0,children:[r.fields.map((e,a)=>d("div",{"data-field-id":e.id,"data-table-id":r.id,className:c("flex items-center gap-1.5 pr-2 relative group",l?"pl-[18px]":"pl-2","border-b border-gray-100 dark:border-gray-700 last:border-b-0",h?"bg-blue-50/50 dark:bg-blue-900/10":"hover:bg-gray-50 dark:hover:bg-gray-700/50",U===a&&"opacity-40",F===a&&"!border-t-2 !border-t-blue-400"),style:{height:E},draggable:l,onDragStart:o=>{l&&(o.stopPropagation(),g.current=a,C(a),o.dataTransfer.effectAllowed="move",o.dataTransfer.setData("text/plain",String(a)))},onDragOver:o=>{g.current!==null&&(o.preventDefault(),o.stopPropagation(),N(a))},onDragLeave:()=>{F===a&&N(null)},onDrop:o=>{o.preventDefault(),o.stopPropagation(),g.current!==null&&g.current!==a&&i?.(r.id,g.current,a),g.current=null,C(null),N(null)},onDragEnd:()=>{g.current=null,C(null),N(null)},children:[t("div",{"data-connection-side":"left","data-field-id":e.id,"data-table-id":r.id,className:c("absolute -left-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",h?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-blue-400"),style:{top:E/2-5}}),l&&t("span",{className:"absolute left-[3px] cursor-grab active:cursor-grabbing opacity-0 group-hover:opacity-100 transition-opacity z-10",style:{top:E/2-6},children:t(ne,{})}),l?t("button",{type:"button",className:c("w-4 text-xs font-bold flex-shrink-0 text-center cursor-pointer",e.nullable?"text-gray-500 dark:text-gray-400":"text-transparent"),onClick:o=>{o.stopPropagation(),O(e.id,e.nullable??!1)},onMouseDown:o=>o.stopPropagation(),title:e.nullable?n.schemaEditorNullable:n.schemaEditorNotNullable,children:"?"}):t("span",{className:c("w-4 text-xs font-bold flex-shrink-0 text-center",e.nullable?"text-gray-500 dark:text-gray-400":"text-transparent"),children:e.nullable?"?":""}),e.primaryKey&&e.foreignKey?d("span",{className:"flex items-center gap-0.5 flex-shrink-0",children:[l?t("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:o=>{o.stopPropagation(),L(e.id,!0)},onMouseDown:o=>o.stopPropagation(),title:n.schemaEditorRemovePrimaryKey,children:t(D,{})}):t(D,{}),t(_,{})]}):e.primaryKey?l?t("button",{type:"button",className:"flex-shrink-0 cursor-pointer",onClick:o=>{o.stopPropagation(),L(e.id,!0)},onMouseDown:o=>o.stopPropagation(),title:n.schemaEditorRemovePrimaryKey,children:t(D,{})}):t(D,{}):e.foreignKey?t(_,{}):l?t("button",{type:"button",className:"w-3.5 h-3.5 flex-shrink-0 rounded text-gray-500 dark:text-gray-400 hover:text-indigo-400 transition-colors cursor-pointer",onClick:o=>{o.stopPropagation(),L(e.id,!1)},onMouseDown:o=>o.stopPropagation(),title:n.schemaEditorSetPrimaryKey,"aria-label":n.schemaEditorSetPrimaryKey,children:d("svg",{className:"w-3.5 h-3.5",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",opacity:"0.3",children:[t("path",{d:"M10 1l2 2-5 5M8.5 4.5L11 7"}),t("circle",{cx:"4.5",cy:"11.5",r:"3"})]})}):t("span",{className:"w-3.5 flex-shrink-0"}),l?t("input",{className:c("flex-1 min-w-0 text-xs bg-transparent border-none outline-none focus:ring-0 p-0 truncate cursor-text",e.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),"aria-label":n.schemaEditorFieldName,value:e.name,onChange:o=>q(e.id,o.target.value),onMouseDown:o=>o.stopPropagation()}):t("span",{className:c("flex-1 min-w-0 text-xs truncate",e.primaryKey?"text-blue-600 dark:text-blue-400 font-medium":"text-gray-700 dark:text-gray-300"),children:e.name}),l?d("select",{className:"text-xs text-gray-500 dark:text-gray-400 bg-transparent border-none outline-none focus:ring-0 p-0 cursor-pointer text-right",value:e.type,onChange:o=>j(e.id,o.target.value),onMouseDown:o=>o.stopPropagation(),children:[V.map(o=>t("option",{value:o,children:o},o)),!V.includes(e.type)&&t("option",{value:e.type,children:e.type})]}):t("span",{className:"text-xs text-gray-500 dark:text-gray-400 flex-shrink-0",children:e.type}),t(se,{field:e,tableId:r.id,editable:b,readOnly:y,disabled:x,onFieldChange:s,labels:n}),e.indexed&&t(K,{}),e.unique&&t(B,{}),l&&d("div",{className:"absolute right-1 top-0 bottom-0 flex items-center gap-0.5 opacity-0 group-hover:opacity-100 transition-opacity bg-gradient-to-l from-white via-white to-transparent dark:from-gray-800 dark:via-gray-800 pl-4 pr-1 z-10",children:[t("button",{type:"button",className:c("cursor-pointer transition-opacity",e.indexed?"opacity-100":"opacity-30 hover:opacity-100"),onClick:o=>{o.stopPropagation(),G(e.id,e.indexed??!1)},onMouseDown:o=>o.stopPropagation(),title:e.indexed?n.schemaEditorRemoveIndex:n.schemaEditorAddIndex,children:t(K,{})}),t("button",{type:"button",className:c("cursor-pointer transition-opacity",e.unique?"opacity-100":"opacity-30 hover:opacity-100"),onClick:o=>{o.stopPropagation(),Y(e.id,e.unique??!1)},onMouseDown:o=>o.stopPropagation(),title:e.unique?n.schemaEditorRemoveUnique:n.schemaEditorAddUnique,children:t(B,{})}),t("button",{type:"button",className:"p-0.5 rounded text-gray-500 dark:text-gray-400 hover:text-red-600 hover:bg-red-50 dark:hover:bg-red-900/20 cursor-pointer",onClick:o=>{o.stopPropagation(),w?.(r.id,e.id)},onMouseDown:o=>o.stopPropagation(),title:n.schemaEditorRemoveField,children:t(ae,{})})]}),t("div",{"data-connection-side":"right","data-field-id":e.id,"data-table-id":r.id,className:c("absolute -right-[5px] w-2.5 h-2.5 rounded-full border-2 border-white dark:border-gray-800 cursor-crosshair z-10 transition-all",h?"opacity-100 bg-green-400 scale-150 shadow-[0_0_6px_rgba(74,222,128,0.6)]":"opacity-0 group-hover:opacity-100 bg-green-400"),style:{top:E/2-5}})]},e.id)),l&&d("button",{type:"button",className:"flex items-center justify-center w-full gap-1 text-xs text-gray-500 dark:text-gray-400 hover:text-blue-600 hover:bg-gray-50 dark:hover:bg-gray-700/50 transition-colors cursor-pointer",style:{height:Q},onClick:e=>{e.stopPropagation(),X()},onMouseDown:e=>e.stopPropagation(),children:[t("svg",{className:"w-3 h-3",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:t("path",{d:"M8 4v8M4 8h8"})}),n.schemaEditorAddField]})]}),!x&&!y&&t("div",{"data-resize-handle":"corner",className:"absolute -bottom-[5px] -right-[5px] w-[14px] h-[14px] cursor-nwse-resize z-20 group/resize",onMouseDown:e=>{e.stopPropagation(),e.preventDefault();let a=r.height??$(r,l);W?.(r.id,e.clientX,e.clientY,R,a)},children:d("svg",{className:"w-full h-full text-gray-500 dark:text-gray-400 group-hover/resize:text-blue-400 transition-colors",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",children:[t("path",{d:"M12 2v10H2",opacity:"0"}),t("path",{d:"M6 12L12 6"}),t("path",{d:"M10 12L12 10"})]})})]})});export{pe as SchemaTableRenderer};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var y=Object.getOwnPropertyNames;var h=Object.prototype.hasOwnProperty;var T=(e,o)=>{for(var n in o)c(e,n,{get:o[n],enumerable:!0})},I=(e,o,n,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let t of y(o))!h.call(e,t)&&t!==n&&c(e,t,{get:()=>o[t],enumerable:!(r=b(o,t))||r.enumerable});return e};var R=e=>I(c({},"__esModule",{value:!0}),e);var w={};T(w,{addRelationToSchema:()=>K,getFieldReferences:()=>g,removeFieldFromSchema:()=>v,removeRelationFromSchema:()=>x,removeTableFromSchema:()=>k,resolveForeignKeys:()=>s});module.exports=R(w);function f(e,o){return!!e&&e.tableId===o.tableId&&e.fieldId===o.fieldId}function m(e){let o=new Map(e.map(n=>[n.id,n]));return n=>n?o.get(n.tableId)?.fields.find(r=>r.id===n.fieldId):void 0}function F(e){let{foreignKey:o,...n}=e;return n}function p(e,o){let n=o(e.from),r=o(e.to);if(!n||!r)return null;let t={holder:e.to,holderField:r,target:e.from},i={holder:e.from,holderField:n,target:e.to};return f(r.foreignKey,e.from)?t:f(n.foreignKey,e.to)||r.primaryKey&&!n.primaryKey?i:t}function g(e){let o=m(e.tables),n=new Map,r=(t,i)=>{let l=n.get(t);l?l.some(d=>f(d,i))||l.push(i):n.set(t,[i])};for(let t of e.tables)for(let i of t.fields)i.foreignKey&&o(i.foreignKey)&&r(i,i.foreignKey);for(let t of e.relations){let i=p(t,o);i&&r(i.holderField,{tableId:i.target.tableId,fieldId:i.target.fieldId})}return n}function s(e){let o=g(e),n=!1,r=e.tables.map(t=>{let i=!1,l=t.fields.map(d=>{let a=o.get(d),u=d.foreignKey;return(a?a.some(S=>f(u,S)):!u)?d:(i=!0,a?{...d,foreignKey:a[0]}:F(d))});return i?(n=!0,{...t,fields:l}):t});return n?{...e,tables:r}:e}function K(e,o){let n={tableId:o.from.tableId,fieldId:o.from.fieldId};return s({...e,tables:e.tables.map(r=>r.id===o.to.tableId?{...r,fields:r.fields.map(t=>t.id===o.to.fieldId?{...t,foreignKey:n}:t)}:r),relations:[...e.relations,o]})}function x(e,o){let n=e.relations.find(t=>t.id===o);if(!n)return e;let r=p(n,m(e.tables));return s({...e,tables:r?e.tables.map(t=>t.id===r.holder.tableId?{...t,fields:t.fields.map(i=>i.id===r.holder.fieldId&&f(i.foreignKey,r.target)?F(i):i)}:t):e.tables,relations:e.relations.filter(t=>t.id!==o)})}function k(e,o){return e.tables.some(n=>n.id===o)?s({...e,tables:e.tables.filter(n=>n.id!==o),relations:e.relations.filter(n=>n.from.tableId!==o&&n.to.tableId!==o)}):e}function v(e,o,n){return e.tables.find(t=>t.id===o)?.fields.some(t=>t.id===n)?s({...e,tables:e.tables.map(t=>t.id===o?{...t,fields:t.fields.filter(i=>i.id!==n)}:t),relations:e.relations.filter(t=>!(t.from.tableId===o&&t.from.fieldId===n)&&!(t.to.tableId===o&&t.to.fieldId===n))}):e}0&&(module.exports={addRelationToSchema,getFieldReferences,removeFieldFromSchema,removeRelationFromSchema,removeTableFromSchema,resolveForeignKeys});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function f(e,n){return!!e&&e.tableId===n.tableId&&e.fieldId===n.fieldId}function u(e){let n=new Map(e.map(o=>[o.id,o]));return o=>o?n.get(o.tableId)?.fields.find(r=>r.id===o.fieldId):void 0}function m(e){let{foreignKey:n,...o}=e;return o}function F(e,n){let o=n(e.from),r=n(e.to);if(!o||!r)return null;let t={holder:e.to,holderField:r,target:e.from},i={holder:e.from,holderField:o,target:e.to};return f(r.foreignKey,e.from)?t:f(o.foreignKey,e.to)||r.primaryKey&&!o.primaryKey?i:t}function g(e){let n=u(e.tables),o=new Map,r=(t,i)=>{let l=o.get(t);l?l.some(d=>f(d,i))||l.push(i):o.set(t,[i])};for(let t of e.tables)for(let i of t.fields)i.foreignKey&&n(i.foreignKey)&&r(i,i.foreignKey);for(let t of e.relations){let i=F(t,n);i&&r(i.holderField,{tableId:i.target.tableId,fieldId:i.target.fieldId})}return o}function a(e){let n=g(e),o=!1,r=e.tables.map(t=>{let i=!1,l=t.fields.map(d=>{let s=n.get(d),c=d.foreignKey;return(s?s.some(p=>f(c,p)):!c)?d:(i=!0,s?{...d,foreignKey:s[0]}:m(d))});return i?(o=!0,{...t,fields:l}):t});return o?{...e,tables:r}:e}function b(e,n){let o={tableId:n.from.tableId,fieldId:n.from.fieldId};return a({...e,tables:e.tables.map(r=>r.id===n.to.tableId?{...r,fields:r.fields.map(t=>t.id===n.to.fieldId?{...t,foreignKey:o}:t)}:r),relations:[...e.relations,n]})}function y(e,n){let o=e.relations.find(t=>t.id===n);if(!o)return e;let r=F(o,u(e.tables));return a({...e,tables:r?e.tables.map(t=>t.id===r.holder.tableId?{...t,fields:t.fields.map(i=>i.id===r.holder.fieldId&&f(i.foreignKey,r.target)?m(i):i)}:t):e.tables,relations:e.relations.filter(t=>t.id!==n)})}function h(e,n){return e.tables.some(o=>o.id===n)?a({...e,tables:e.tables.filter(o=>o.id!==n),relations:e.relations.filter(o=>o.from.tableId!==n&&o.to.tableId!==n)}):e}function T(e,n,o){return e.tables.find(t=>t.id===n)?.fields.some(t=>t.id===o)?a({...e,tables:e.tables.map(t=>t.id===n?{...t,fields:t.fields.filter(i=>i.id!==o)}:t),relations:e.relations.filter(t=>!(t.from.tableId===n&&t.from.fieldId===o)&&!(t.to.tableId===n&&t.to.fieldId===o))}):e}export{b as addRelationToSchema,g as getFieldReferences,T as removeFieldFromSchema,y as removeRelationFromSchema,h as removeTableFromSchema,a as resolveForeignKeys};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var _=Object.defineProperty;var b=Object.getOwnPropertyDescriptor;var l=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var R=(n,t)=>{for(var e in t)_(n,e,{get:t[e],enumerable:!0})},y=(n,t,e,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of l(t))!p.call(n,o)&&o!==e&&_(n,o,{get:()=>t[o],enumerable:!(r=b(t,o))||r.enumerable});return n};var A=n=>y(_({},"__esModule",{value:!0}),n);var w={};R(w,{ADD_BUTTON_HEIGHT:()=>L,DEFAULT_TABLE_WIDTH:()=>F,FIELD_ROW_HEIGHT:()=>B,HEADER_HEIGHT:()=>N,NOTES_ROW_HEIGHT:()=>S,TABLE_BORDER_WIDTH:()=>W,clampZoom:()=>C,computeBezierPath:()=>$,fitViewport:()=>g,getFieldConnectionPosition:()=>G,getFieldConnectionY:()=>I,getTableHeight:()=>x,hasNotesRow:()=>H,screenToCanvas:()=>d,snapValue:()=>M});module.exports=A(w);var F=260,N=40,B=32,L=36,S=24,W=2;function H(n,t){return!n.collapsed&&(t||!!n.notes)}function x(n,t){return n.collapsed?44:n.height?n.height:44+(H(n,t)?24:0)+n.fields.length*32+(t?36:0)}function I(n,t){return 42+(t?24:0)+n*32+32/2}function G(n,t,e,r){let o=n.fields.findIndex(T=>T.id===t);if(o===-1)return null;let c=n.width??260,m=n.y+I(o,H(n,r));return{x:e==="left"?n.x+0:n.x+c-0,y:m}}function M(n,t){return Math.round(n/t)*t}function C(n,t,e){return Math.min(e,Math.max(t,n))}function d(n,t,e,r){return{x:(n-r.left-e.x)/e.zoom,y:(t-r.top-e.y)/e.zoom}}function $(n,t,e,r){let o=Math.abs(e-n),c=Math.max(50,o*.5),m=n+c,u=t,T=e-c;return`M ${n} ${t} C ${m} ${u}, ${T} ${r}, ${e} ${r}`}function g(n,t,e,r,o=40){if(n.length===0)return{x:0,y:0,zoom:1};let c=1/0,m=1/0,u=-1/0,T=-1/0;for(let E of n){let a=E.width??260,D=x(E,r);c=Math.min(c,E.x),m=Math.min(m,E.y),u=Math.max(u,E.x+a),T=Math.max(T,E.y+D)}let i=u-c+o*2,f=T-m+o*2,s=Math.min(t/i,e/f,1),h=(t-i*s)/2-(c-o)*s,O=(e-f*s)/2-(m-o)*s;return{x:h,y:O,zoom:s}}0&&(module.exports={ADD_BUTTON_HEIGHT,DEFAULT_TABLE_WIDTH,FIELD_ROW_HEIGHT,HEADER_HEIGHT,NOTES_ROW_HEIGHT,TABLE_BORDER_WIDTH,clampZoom,computeBezierPath,fitViewport,getFieldConnectionPosition,getFieldConnectionY,getTableHeight,hasNotesRow,screenToCanvas,snapValue});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var D=260,b=40,l=32,p=36,R=24,y=2;function H(n,t){return!n.collapsed&&(t||!!n.notes)}function O(n,t){return n.collapsed?44:n.height?n.height:44+(H(n,t)?24:0)+n.fields.length*32+(t?36:0)}function a(n,t){return 42+(t?24:0)+n*32+32/2}function A(n,t,e,o){let r=n.fields.findIndex(T=>T.id===t);if(r===-1)return null;let c=n.width??260,m=n.y+a(r,H(n,o));return{x:e==="left"?n.x+0:n.x+c-0,y:m}}function F(n,t){return Math.round(n/t)*t}function N(n,t,e){return Math.min(e,Math.max(t,n))}function B(n,t,e,o){return{x:(n-o.left-e.x)/e.zoom,y:(t-o.top-e.y)/e.zoom}}function L(n,t,e,o){let r=Math.abs(e-n),c=Math.max(50,r*.5),m=n+c,u=t,T=e-c;return`M ${n} ${t} C ${m} ${u}, ${T} ${o}, ${e} ${o}`}function S(n,t,e,o,r=40){if(n.length===0)return{x:0,y:0,zoom:1};let c=1/0,m=1/0,u=-1/0,T=-1/0;for(let E of n){let I=E.width??260,h=O(E,o);c=Math.min(c,E.x),m=Math.min(m,E.y),u=Math.max(u,E.x+I),T=Math.max(T,E.y+h)}let i=u-c+r*2,_=T-m+r*2,s=Math.min(t/i,e/_,1),f=(t-i*s)/2-(c-r)*s,x=(e-_*s)/2-(m-r)*s;return{x:f,y:x,zoom:s}}export{p as ADD_BUTTON_HEIGHT,D as DEFAULT_TABLE_WIDTH,l as FIELD_ROW_HEIGHT,b as HEADER_HEIGHT,R as NOTES_ROW_HEIGHT,y as TABLE_BORDER_WIDTH,N as clampZoom,L as computeBezierPath,S as fitViewport,A as getFieldConnectionPosition,a as getFieldConnectionY,O as getTableHeight,H as hasNotesRow,B as screenToCanvas,F as snapValue};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
${
|
|
1
|
+
"use strict";var E=Object.defineProperty;var S=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var y=Object.prototype.hasOwnProperty;var N=(e,n)=>{for(var s in n)E(e,s,{get:n[s],enumerable:!0})},A=(e,n,s,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of R(n))!y.call(e,r)&&r!==s&&E(e,r,{get:()=>n[r],enumerable:!(o=S(n,r))||o.enumerable});return e};var $=e=>A(E({},"__esModule",{value:!0}),e);var b={};N(b,{generateSQL:()=>M});module.exports=$(b);var I=require("./foreign-keys.cjs");function a(e){return`"${e.replace(/"/g,'""')}"`}function h(e){return{text:"TEXT",varchar:"VARCHAR(255)",char:"CHAR(1)",int2:"SMALLINT",int4:"INTEGER",int8:"BIGINT",serial:"SERIAL",bigserial:"BIGSERIAL",float4:"REAL",float8:"DOUBLE PRECISION",numeric:"NUMERIC",decimal:"DECIMAL",bool:"BOOLEAN",date:"DATE",time:"TIME",timestamp:"TIMESTAMP",timestamptz:"TIMESTAMP WITH TIME ZONE",uuid:"UUID",json:"JSON",jsonb:"JSONB",bytea:"BYTEA"}[e]??e.toUpperCase()}function L(e){let n=[a(e.name)];return e.type==="serial"||e.type,n.push(h(e.type)),e.primaryKey&&n.push("PRIMARY KEY"),!e.nullable&&!e.primaryKey&&n.push("NOT NULL"),e.unique&&!e.primaryKey&&n.push("UNIQUE"),e.defaultValue&&n.push(`DEFAULT ${e.defaultValue}`)," "+n.join(" ")}function F(e,n,s){let o=[],r=[];for(let t of e.fields)o.push(L(t));let p=new Set;for(let t of e.fields)for(let d of s.get(t)??[]){let l=n.find(c=>c.id===d.tableId),T=l?.fields.find(c=>c.id===d.fieldId);if(!l||!T)continue;let g=`fk_${e.name}_${t.name}`,u=g;for(let c=2;p.has(u);c++)u=`${g}_${c}`;p.add(u),r.push(` CONSTRAINT ${a(u)} FOREIGN KEY (${a(t.name)}) REFERENCES ${a(l.name)} (${a(T.name)})`)}let i=[];for(let t of e.fields)t.indexed&&!t.primaryKey&&!t.unique&&i.push(`CREATE INDEX ${a(`idx_${e.name}_${t.name}`)} ON ${a(e.name)} (${a(t.name)});`);let m=[...o,...r],f=`CREATE TABLE ${a(e.name)} (
|
|
2
|
+
${m.join(`,
|
|
3
3
|
`)}
|
|
4
|
-
);`;return
|
|
4
|
+
);`;return i.length>0?f+`
|
|
5
5
|
|
|
6
|
-
`+
|
|
7
|
-
`):
|
|
6
|
+
`+i.join(`
|
|
7
|
+
`):f}function M(e){let{tables:n}=e;if(n.length===0)return"-- No tables defined";let s=(0,I.getFieldReferences)(e),o=i=>i.fields.some(m=>s.has(m));return[...n].sort((i,m)=>{let f=o(i),t=o(m);return f&&!t?1:!f&&t?-1:0}).map(i=>F(i,n,s)).join(`
|
|
8
8
|
|
|
9
9
|
`)}0&&(module.exports={generateSQL});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
function
|
|
2
|
-
${
|
|
1
|
+
import{getFieldReferences as h}from"./foreign-keys.js";function r(e){return`"${e.replace(/"/g,'""')}"`}function g(e){return{text:"TEXT",varchar:"VARCHAR(255)",char:"CHAR(1)",int2:"SMALLINT",int4:"INTEGER",int8:"BIGINT",serial:"SERIAL",bigserial:"BIGSERIAL",float4:"REAL",float8:"DOUBLE PRECISION",numeric:"NUMERIC",decimal:"DECIMAL",bool:"BOOLEAN",date:"DATE",time:"TIME",timestamp:"TIMESTAMP",timestamptz:"TIMESTAMP WITH TIME ZONE",uuid:"UUID",json:"JSON",jsonb:"JSONB",bytea:"BYTEA"}[e]??e.toUpperCase()}function I(e){let n=[r(e.name)];return e.type==="serial"||e.type,n.push(g(e.type)),e.primaryKey&&n.push("PRIMARY KEY"),!e.nullable&&!e.primaryKey&&n.push("NOT NULL"),e.unique&&!e.primaryKey&&n.push("UNIQUE"),e.defaultValue&&n.push(`DEFAULT ${e.defaultValue}`)," "+n.join(" ")}function S(e,n,m){let a=[],u=[];for(let t of e.fields)a.push(I(t));let p=new Set;for(let t of e.fields)for(let E of m.get(t)??[]){let l=n.find(i=>i.id===E.tableId),d=l?.fields.find(i=>i.id===E.fieldId);if(!l||!d)continue;let T=`fk_${e.name}_${t.name}`,f=T;for(let i=2;p.has(f);i++)f=`${T}_${i}`;p.add(f),u.push(` CONSTRAINT ${r(f)} FOREIGN KEY (${r(t.name)}) REFERENCES ${r(l.name)} (${r(d.name)})`)}let s=[];for(let t of e.fields)t.indexed&&!t.primaryKey&&!t.unique&&s.push(`CREATE INDEX ${r(`idx_${e.name}_${t.name}`)} ON ${r(e.name)} (${r(t.name)});`);let o=[...a,...u],c=`CREATE TABLE ${r(e.name)} (
|
|
2
|
+
${o.join(`,
|
|
3
3
|
`)}
|
|
4
|
-
);`;return s.length>0?
|
|
4
|
+
);`;return s.length>0?c+`
|
|
5
5
|
|
|
6
6
|
`+s.join(`
|
|
7
|
-
`):
|
|
7
|
+
`):c}function y(e){let{tables:n}=e;if(n.length===0)return"-- No tables defined";let m=h(e),a=s=>s.fields.some(o=>m.has(o));return[...n].sort((s,o)=>{let c=a(s),t=a(o);return c&&!t?1:!c&&t?-1:0}).map(s=>S(s,n,m)).join(`
|
|
8
8
|
|
|
9
|
-
`)}export{
|
|
9
|
+
`)}export{y as generateSQL};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var q=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var Te=Object.prototype.hasOwnProperty;var Ae=(s,o)=>{for(var c in o)q(s,c,{get:o[c],enumerable:!0})},Pe=(s,o,c,l)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of Oe(o))!Te.call(s,i)&&i!==c&&q(s,i,{get:()=>o[i],enumerable:!(l=Me(o,i))||l.enumerable});return s};var Re=s=>Pe(q({},"__esModule",{value:!0}),s);var je={};Ae(je,{Select:()=>Ye});module.exports=Re(je);var r=require("react"),ue=require("react-dom"),de=require("../../lib/aria-hide.cjs"),pe=require("../../lib/i18n.cjs"),n=require("react/jsx-runtime"),F=()=>{},He=[],Ke=(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,n.jsx)("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Ve=(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,n.jsx)("path",{d:"M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Be=(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0 animate-spin",children:[(0,n.jsx)("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",strokeOpacity:"0.25"}),(0,n.jsx)("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),$e=(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,n.jsx)("path",{d:"M11.5 3.5L5.5 10.5L2.5 7.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),P={sm:{trigger:"h-8 px-2.5 text-xs gap-1.5",content:"text-xs",option:"px-2.5 py-1.5",searchInput:"px-2.5 py-1.5 text-xs"},md:{trigger:"h-10 px-3 text-sm gap-2",content:"text-sm",option:"px-3 py-2",searchInput:"px-3 py-2 text-sm"},lg:{trigger:"h-12 px-4 text-base gap-2.5",content:"text-base",option:"px-4 py-2.5",searchInput:"px-4 py-2.5 text-base"}},ce={default:{trigger:"border border-gray-300 bg-white dark:border-gray-600 dark:bg-gray-800",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"},outlined:{trigger:"border-2 border-gray-300 bg-transparent dark:border-gray-600",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"},filled:{trigger:"border border-transparent bg-gray-100 dark:bg-gray-700",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}};function w(...s){let o="";for(let c=0;c<s.length;c++){let l=s[c];l&&(o&&(o+=" "),o+=l)}return o}function We(s,o){if(!o)return s;let c=o.toLowerCase();return s.filter(l=>{if(l.label.toLowerCase().includes(c)||l.value.toLowerCase().includes(c))return!0;if(l.keywords){for(let i of l.keywords)if(i.toLowerCase().includes(c))return!0}return!1})}var Ue=(0,r.memo)((0,r.forwardRef)(function({option:o,isSelected:c,isHighlighted:l,isDisabled:i,sizeKey:B,optionId:g,onClick:m,onMouseEnter:I,index:k},R){let $=()=>{i||m(o.value)},E=()=>{i||I(k)};return(0,n.jsxs)("div",{ref:R,id:g,role:"option","aria-selected":c,"aria-disabled":i||void 0,"data-highlighted":l||void 0,className:w(P[B].option,"flex items-center gap-2 cursor-pointer select-none transition-colors",l&&!i&&"bg-blue-50 dark:bg-blue-900/30",c&&!l&&"bg-gray-50 dark:bg-gray-700/50",i&&"opacity-50 cursor-not-allowed"),onClick:$,onMouseEnter:E,children:[o.icon?(0,n.jsx)("span",{className:"flex shrink-0 items-center",children:o.icon}):null,(0,n.jsxs)("span",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"truncate",children:o.label}),o.description?(0,n.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:o.description}):null]}),c?(0,n.jsx)("span",{className:"ml-auto text-blue-600 dark:text-blue-400",children:$e}):null]})}));function Ye({options:s=He,value:o,defaultValue:c,onValueChange:l,searchable:i=!1,clearable:B=!1,disabled:g=!1,readOnly:m=!1,loading:I=!1,size:k="md",variant:R="default",placeholder:$,label:E,description:Q,helperText:X,error:D,required:Z=!1,noOptionsText:fe,clearLabel:ge,searchLabel:be,searchPlaceholder:me,onSearchChange:G,name:J,className:he,triggerClassName:ve,contentClassName:xe,maxHeight:W=256}){let C=(0,pe.useUILabels)(),we=$??C.selectPlaceholder,ke=fe??C.selectNoOptions,S=(0,r.useId)(),U=`${S}-label`,ee=`${S}-trigger`,te=`${S}-listbox`,v=(0,r.useRef)(null),Y=(0,r.useRef)(null),ne=(0,r.useRef)(null),re=(0,r.useRef)([]),M=o!==void 0,[ye,oe]=(0,r.useState)(c??""),L=M?o:ye,[p,j]=(0,r.useState)(!1),[z,O]=(0,r.useState)(""),[a,f]=(0,r.useState)(-1),[T,se]=(0,r.useState)(null),d=(0,r.useMemo)(()=>i?We(s,z):s,[s,z,i]),H=(0,r.useMemo)(()=>s.find(e=>e.value===L)??null,[s,L]),x=(0,r.useMemo)(()=>{let e=new Set;for(let t of s)t.disabled&&e.add(t.value);return e},[s]),N=(0,r.useCallback)(e=>{M||oe(e),(l??F)(e),j(!1),O(""),f(-1),v.current?.focus()},[M,l]),Ee=(0,r.useCallback)(e=>{e.stopPropagation(),M||oe(""),(l??F)(""),O(""),v.current?.focus()},[M,l]),A=(0,r.useCallback)(()=>{g||m||(j(!0),O(""),f(-1))},[g,m]),b=(0,r.useCallback)(()=>{j(!1),O(""),f(-1),v.current?.focus()},[]),Le=(0,r.useCallback)(()=>{p?b():A()},[p,b,A]),h=(0,r.useCallback)((e,t)=>{let u=d.length;if(u===0)return-1;let y=e;for(let V=0;V<u;V++)if(y=((y+t)%u+u)%u,!x.has(d[y].value))return y;return-1},[d,x]),Ne=(0,r.useCallback)(e=>{if(!(g||m)){if(p){switch(e.key){case"ArrowDown":{e.preventDefault();let t=h(a,1);t!==-1&&f(t);break}case"ArrowUp":{e.preventDefault();let t=h(a,-1);t!==-1&&f(t);break}case"Home":{e.preventDefault();let t=h(-1,1);t!==-1&&f(t);break}case"End":{e.preventDefault();let t=h(d.length,-1);t!==-1&&f(t);break}case"Enter":{if(e.preventDefault(),a>=0&&a<d.length){let t=d[a];x.has(t.value)||N(t.value)}break}case" ":if(e.preventDefault(),a>=0&&a<d.length){let t=d[a];x.has(t.value)||N(t.value)}else b();break;case"Escape":e.preventDefault(),b();break;case"Tab":b();break}return}switch(e.key){case"ArrowDown":case"ArrowUp":e.preventDefault(),A();break;case"Enter":case" ":e.preventDefault(),A();break}}},[g,m,p,A,b,a,d,x,h,N]),Ie=(0,r.useCallback)(e=>{switch(e.key){case"ArrowDown":{e.preventDefault();let t=h(a,1);t!==-1&&f(t);break}case"ArrowUp":{e.preventDefault();let t=h(a,-1);t!==-1&&f(t);break}case"Home":{e.preventDefault();let t=h(-1,1);t!==-1&&f(t);break}case"End":{e.preventDefault();let t=h(d.length,-1);t!==-1&&f(t);break}case"Enter":{if(e.preventDefault(),a>=0&&a<d.length){let t=d[a];x.has(t.value)||N(t.value)}break}case"Escape":e.preventDefault(),b();break;case"Tab":b();break}},[a,d,x,h,N,b]),De=(0,r.useCallback)(e=>{let t=e.target.value;O(t),f(-1),(G??F)(t)},[G]);(0,r.useEffect)(()=>{if(!p)return;let e=t=>{let u=t.target;v.current?.contains(u)||Y.current?.contains(u)||b()};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e,{passive:!0}),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)}},[p,b]),(0,r.useEffect)(()=>{if(!p||!v.current){se(null);return}let e=()=>{let t=v.current;if(!t)return;let u=t.getBoundingClientRect(),y=window.innerHeight-u.bottom,V=u.top,le=W+8,ie=y<le&&V>y?"top":"bottom";se({top:ie==="bottom"?u.bottom+window.scrollY+4:u.top+window.scrollY-le,left:u.left+window.scrollX,width:u.width,placement:ie})};return e(),window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[p,W]);let K=p&&T!==null;(0,r.useEffect)(()=>{K&&i&&ne.current?.focus()},[K,i]),(0,r.useEffect)(()=>{let e=Y.current;if(!(!K||!e))return(0,de.registerFloatingLayer)(e,()=>v.current)},[K]),(0,r.useEffect)(()=>{if(a>=0){let e=re.current[a];e&&typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest"})}},[a]);let _=L!==""&&L!==void 0,Ce=B&&_&&!g&&!m&&!I,ae=!g&&!m,Se=w("w-full flex items-center justify-between rounded-md transition-colors","text-gray-900 dark:text-gray-100",P[k].trigger,ce[R].trigger,!D&&ae&&ce[R].focus,D&&"border-red-500 dark:border-red-400 focus:ring-2 focus:ring-red-500 focus:border-red-500",g&&"opacity-50 cursor-not-allowed bg-gray-50 dark:bg-gray-900",m&&"cursor-default",!g&&!m&&"cursor-pointer",ve);return(0,n.jsxs)("div",{className:w("flex flex-col gap-1",he),children:[E?(0,n.jsxs)("label",{id:U,htmlFor:ee,className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:[E,Z?(0,n.jsx)("span",{className:"text-red-500 ml-0.5","aria-hidden":"true",children:"*"}):null]}):null,Q?(0,n.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:Q}):null,(0,n.jsxs)("button",{ref:v,id:ee,type:"button",role:"combobox","aria-expanded":p,"aria-haspopup":"listbox","aria-controls":p?te:void 0,"aria-labelledby":E?U:void 0,"aria-required":Z||void 0,"aria-invalid":D?!0:void 0,"aria-activedescendant":p&&a>=0?`${S}-option-${a}`:void 0,disabled:g,className:Se,onClick:ae?Le:void 0,onKeyDown:Ne,children:[(0,n.jsxs)("span",{className:w("flex items-center gap-2 min-w-0 flex-1 truncate",!_&&"text-gray-400 dark:text-gray-500"),children:[H?.icon?(0,n.jsx)("span",{className:"flex shrink-0 items-center",children:H.icon}):null,(0,n.jsx)("span",{className:"truncate",children:_&&H?H.label:we})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1 shrink-0",children:[I?(0,n.jsx)("span",{className:"text-gray-400",children:Be}):null,Ce?(0,n.jsx)("span",{role:"button",tabIndex:-1,"aria-label":ge??C.selectClear,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 p-0.5 rounded transition-colors",onClick:Ee,onMouseDown:e=>e.preventDefault(),children:Ve}):null,(0,n.jsx)("span",{className:w("text-gray-400 transition-transform duration-200",p&&"rotate-180"),children:Ke})]})]}),D?(0,n.jsx)("p",{role:"alert",className:"text-xs text-red-500 dark:text-red-400",children:D}):X?(0,n.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:X}):null,J?(0,n.jsx)("input",{type:"hidden",name:J,value:L??""}):null,p&&T?(0,ue.createPortal)((0,n.jsxs)("div",{ref:Y,role:"listbox",id:te,"aria-labelledby":E?U:void 0,className:w("fixed z-50 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700","rounded-md shadow-lg overflow-hidden","animate-in fade-in-0 zoom-in-95",P[k].content,xe),style:{top:T.top,left:T.left,width:T.width,position:"absolute"},onKeyDown:Ie,children:[i?(0,n.jsx)("div",{className:"border-b border-gray-200 dark:border-gray-700",children:(0,n.jsx)("input",{ref:ne,type:"text",role:"searchbox","aria-label":be??C.selectSearch,className:w(P[k].searchInput,"w-full outline-none bg-transparent text-gray-900 dark:text-gray-100","placeholder:text-gray-400 dark:placeholder:text-gray-500"),placeholder:me??C.selectSearchPlaceholder,value:z,onChange:De})}):null,(0,n.jsx)("div",{className:"overflow-y-auto",style:{maxHeight:W},children:d.length===0?(0,n.jsx)("div",{className:w(P[k].option,"text-gray-500 dark:text-gray-400 text-center py-4"),children:ke}):d.map((e,t)=>(0,n.jsx)(Ue,{option:e,isSelected:e.value===L,isHighlighted:t===a,isDisabled:I||x.has(e.value),sizeKey:k,optionId:`${S}-option-${t}`,onClick:N,onMouseEnter:f,index:t,ref:u=>{re.current[t]=u}},e.value))})]}),document.body):null]})}0&&(module.exports={Select});
|
|
1
|
+
"use strict";"use client";var q=Object.defineProperty;var Me=Object.getOwnPropertyDescriptor;var Oe=Object.getOwnPropertyNames;var Te=Object.prototype.hasOwnProperty;var Ae=(a,o)=>{for(var c in o)q(a,c,{get:o[c],enumerable:!0})},Pe=(a,o,c,l)=>{if(o&&typeof o=="object"||typeof o=="function")for(let i of Oe(o))!Te.call(a,i)&&i!==c&&q(a,i,{get:()=>o[i],enumerable:!(l=Me(o,i))||l.enumerable});return a};var Re=a=>Pe(q({},"__esModule",{value:!0}),a);var je={};Ae(je,{Select:()=>Ye});module.exports=Re(je);var r=require("react"),ue=require("react-dom"),de=require("../../lib/aria-hide.cjs"),pe=require("../../lib/i18n.cjs"),n=require("react/jsx-runtime"),F=()=>{},He=[],Ke=(0,n.jsx)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,n.jsx)("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Ve=(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,n.jsx)("path",{d:"M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Be=(0,n.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0 animate-spin",children:[(0,n.jsx)("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",strokeOpacity:"0.25"}),(0,n.jsx)("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),$e=(0,n.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:(0,n.jsx)("path",{d:"M11.5 3.5L5.5 10.5L2.5 7.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),P={sm:{trigger:"h-8 px-2.5 text-xs gap-1.5",content:"text-xs",option:"px-2.5 py-1.5",searchInput:"px-2.5 py-1.5 text-xs"},md:{trigger:"h-10 px-3 text-sm gap-2",content:"text-sm",option:"px-3 py-2",searchInput:"px-3 py-2 text-sm"},lg:{trigger:"h-12 px-4 text-base gap-2.5",content:"text-base",option:"px-4 py-2.5",searchInput:"px-4 py-2.5 text-base"}},ce={default:{trigger:"border border-gray-300 bg-white dark:border-gray-600 dark:bg-gray-800",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"},outlined:{trigger:"border-2 border-gray-300 bg-transparent dark:border-gray-600",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"},filled:{trigger:"border border-transparent bg-gray-100 dark:bg-gray-700",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}};function k(...a){let o="";for(let c=0;c<a.length;c++){let l=a[c];l&&(o&&(o+=" "),o+=l)}return o}function We(a,o){if(!o)return a;let c=o.toLowerCase();return a.filter(l=>{if(l.label.toLowerCase().includes(c)||l.value.toLowerCase().includes(c))return!0;if(l.keywords){for(let i of l.keywords)if(i.toLowerCase().includes(c))return!0}return!1})}var Ue=(0,r.memo)((0,r.forwardRef)(function({option:o,isSelected:c,isHighlighted:l,isDisabled:i,sizeKey:B,optionId:g,onClick:m,onMouseEnter:I,index:w},R){let $=()=>{i||m(o.value)},E=()=>{i||I(w)};return(0,n.jsxs)("div",{ref:R,id:g,role:"option","aria-selected":c,"aria-disabled":i||void 0,"data-highlighted":l||void 0,className:k(P[B].option,"flex items-center gap-2 cursor-pointer select-none transition-colors",l&&!i&&"bg-blue-50 dark:bg-blue-900/30",c&&!l&&"bg-gray-50 dark:bg-gray-700/50",i&&"opacity-50 cursor-not-allowed"),onClick:$,onMouseEnter:E,children:[o.icon?(0,n.jsx)("span",{className:"flex shrink-0 items-center",children:o.icon}):null,(0,n.jsxs)("span",{className:"flex flex-col min-w-0 flex-1",children:[(0,n.jsx)("span",{className:"truncate",children:o.label}),o.description?(0,n.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:o.description}):null]}),c?(0,n.jsx)("span",{className:"ml-auto text-blue-600 dark:text-blue-400",children:$e}):null]})}));function Ye({options:a=He,value:o,defaultValue:c,onValueChange:l,searchable:i=!1,clearable:B=!1,disabled:g=!1,readOnly:m=!1,loading:I=!1,size:w="md",variant:R="default",placeholder:$,label:E,description:Q,helperText:X,error:D,required:Z=!1,noOptionsText:fe,clearLabel:ge,searchLabel:be,searchPlaceholder:me,onSearchChange:G,name:J,className:he,triggerClassName:xe,contentClassName:ve,maxHeight:W=256}){let C=(0,pe.useUILabels)(),ke=$??C.selectPlaceholder,we=fe??C.selectNoOptions,S=(0,r.useId)(),U=`${S}-label`,ee=`${S}-trigger`,te=`${S}-listbox`,x=(0,r.useRef)(null),Y=(0,r.useRef)(null),ne=(0,r.useRef)(null),re=(0,r.useRef)([]),M=o!==void 0,[ye,oe]=(0,r.useState)(c??""),L=M?o:ye,[p,j]=(0,r.useState)(!1),[z,O]=(0,r.useState)(""),[s,f]=(0,r.useState)(-1),[T,ae]=(0,r.useState)(null),d=(0,r.useMemo)(()=>i?We(a,z):a,[a,z,i]),H=(0,r.useMemo)(()=>a.find(e=>e.value===L)??null,[a,L]),v=(0,r.useMemo)(()=>{let e=new Set;for(let t of a)t.disabled&&e.add(t.value);return e},[a]),N=(0,r.useCallback)(e=>{M||oe(e),(l??F)(e),j(!1),O(""),f(-1),x.current?.focus()},[M,l]),Ee=(0,r.useCallback)(e=>{e.stopPropagation(),M||oe(""),(l??F)(""),O(""),x.current?.focus()},[M,l]),A=(0,r.useCallback)(()=>{g||m||(j(!0),O(""),f(-1))},[g,m]),b=(0,r.useCallback)(()=>{j(!1),O(""),f(-1),x.current?.focus()},[]),Le=(0,r.useCallback)(()=>{p?b():A()},[p,b,A]),h=(0,r.useCallback)((e,t)=>{let u=d.length;if(u===0)return-1;let y=e;for(let V=0;V<u;V++)if(y=((y+t)%u+u)%u,!v.has(d[y].value))return y;return-1},[d,v]),Ne=(0,r.useCallback)(e=>{if(!(g||m)){if(p){switch(e.key){case"ArrowDown":{e.preventDefault();let t=h(s,1);t!==-1&&f(t);break}case"ArrowUp":{e.preventDefault();let t=h(s,-1);t!==-1&&f(t);break}case"Home":{e.preventDefault();let t=h(-1,1);t!==-1&&f(t);break}case"End":{e.preventDefault();let t=h(d.length,-1);t!==-1&&f(t);break}case"Enter":{if(e.preventDefault(),s>=0&&s<d.length){let t=d[s];v.has(t.value)||N(t.value)}break}case" ":if(e.preventDefault(),s>=0&&s<d.length){let t=d[s];v.has(t.value)||N(t.value)}else b();break;case"Escape":e.preventDefault(),b();break;case"Tab":b();break}return}switch(e.key){case"ArrowDown":case"ArrowUp":e.preventDefault(),A();break;case"Enter":case" ":e.preventDefault(),A();break}}},[g,m,p,A,b,s,d,v,h,N]),Ie=(0,r.useCallback)(e=>{switch(e.key){case"ArrowDown":{e.preventDefault();let t=h(s,1);t!==-1&&f(t);break}case"ArrowUp":{e.preventDefault();let t=h(s,-1);t!==-1&&f(t);break}case"Home":{e.preventDefault();let t=h(-1,1);t!==-1&&f(t);break}case"End":{e.preventDefault();let t=h(d.length,-1);t!==-1&&f(t);break}case"Enter":{if(e.preventDefault(),s>=0&&s<d.length){let t=d[s];v.has(t.value)||N(t.value)}break}case"Escape":e.preventDefault(),b();break;case"Tab":b();break}},[s,d,v,h,N,b]),De=(0,r.useCallback)(e=>{let t=e.target.value;O(t),f(-1),(G??F)(t)},[G]);(0,r.useEffect)(()=>{if(!p)return;let e=t=>{let u=t.target;x.current?.contains(u)||Y.current?.contains(u)||b()};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e,{passive:!0}),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)}},[p,b]),(0,r.useEffect)(()=>{if(!p||!x.current){ae(null);return}let e=()=>{let t=x.current;if(!t)return;let u=t.getBoundingClientRect(),y=window.innerHeight-u.bottom,V=u.top,le=W+8,ie=y<le&&V>y?"top":"bottom";ae({top:ie==="bottom"?u.bottom+window.scrollY+4:u.top+window.scrollY-le,left:u.left+window.scrollX,width:u.width,placement:ie})};return e(),window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[p,W]);let K=p&&T!==null;(0,r.useEffect)(()=>{K&&i&&ne.current?.focus()},[K,i]),(0,r.useEffect)(()=>{let e=Y.current;if(!(!K||!e))return(0,de.registerFloatingLayer)(e,()=>x.current)},[K]),(0,r.useEffect)(()=>{if(s>=0){let e=re.current[s];e&&typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest"})}},[s]);let _=L!==""&&L!==void 0,Ce=B&&_&&!g&&!m&&!I,se=!g&&!m,Se=k("w-full flex items-center justify-between rounded-md transition-colors","text-gray-900 dark:text-gray-100",P[w].trigger,ce[R].trigger,!D&&se&&ce[R].focus,D&&"border-red-500 dark:border-red-400 focus:ring-2 focus:ring-red-500 focus:border-red-500",g&&"opacity-50 cursor-not-allowed bg-gray-50 dark:bg-gray-900",m&&"cursor-default",!g&&!m&&"cursor-pointer",xe);return(0,n.jsxs)("div",{className:k("flex flex-col gap-1",he),children:[E?(0,n.jsxs)("label",{id:U,htmlFor:ee,className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:[E,Z?(0,n.jsx)("span",{className:"text-red-600 dark:text-red-400 ml-0.5","aria-hidden":"true",children:"*"}):null]}):null,Q?(0,n.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:Q}):null,(0,n.jsxs)("button",{ref:x,id:ee,type:"button",role:"combobox","aria-expanded":p,"aria-haspopup":"listbox","aria-controls":p?te:void 0,"aria-labelledby":E?U:void 0,"aria-required":Z||void 0,"aria-invalid":D?!0:void 0,"aria-activedescendant":p&&s>=0?`${S}-option-${s}`:void 0,disabled:g,className:Se,onClick:se?Le:void 0,onKeyDown:Ne,children:[(0,n.jsxs)("span",{className:k("flex items-center gap-2 min-w-0 flex-1 truncate",!_&&"text-gray-600 dark:text-gray-300"),children:[H?.icon?(0,n.jsx)("span",{className:"flex shrink-0 items-center",children:H.icon}):null,(0,n.jsx)("span",{className:"truncate",children:_&&H?H.label:ke})]}),(0,n.jsxs)("span",{className:"flex items-center gap-1 shrink-0",children:[I?(0,n.jsx)("span",{className:"text-gray-500 dark:text-gray-400",children:Be}):null,Ce?(0,n.jsx)("span",{role:"button",tabIndex:-1,"aria-label":ge??C.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:Ee,onMouseDown:e=>e.preventDefault(),children:Ve}):null,(0,n.jsx)("span",{className:k("text-gray-500 dark:text-gray-400 transition-transform duration-200",p&&"rotate-180"),children:Ke})]})]}),D?(0,n.jsx)("p",{role:"alert",className:"text-xs text-red-600 dark:text-red-400",children:D}):X?(0,n.jsx)("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:X}):null,J?(0,n.jsx)("input",{type:"hidden",name:J,value:L??""}):null,p&&T?(0,ue.createPortal)((0,n.jsxs)("div",{ref:Y,role:"listbox",id:te,"aria-labelledby":E?U:void 0,className:k("fixed z-50 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700","rounded-md shadow-lg overflow-hidden","animate-in fade-in-0 zoom-in-95",P[w].content,ve),style:{top:T.top,left:T.left,width:T.width,position:"absolute"},onKeyDown:Ie,children:[i?(0,n.jsx)("div",{className:"border-b border-gray-200 dark:border-gray-700",children:(0,n.jsx)("input",{ref:ne,type:"text",role:"searchbox","aria-label":be??C.selectSearch,className:k(P[w].searchInput,"w-full outline-none bg-transparent text-gray-900 dark:text-gray-100","placeholder:text-gray-500 dark:placeholder:text-gray-400"),placeholder:me??C.selectSearchPlaceholder,value:z,onChange:De})}):null,(0,n.jsx)("div",{className:"overflow-y-auto",style:{maxHeight:W},children:d.length===0?(0,n.jsx)("div",{className:k(P[w].option,"text-gray-500 dark:text-gray-400 text-center py-4"),children:we}):d.map((e,t)=>(0,n.jsx)(Ue,{option:e,isSelected:e.value===L,isHighlighted:t===s,isDisabled:I||v.has(e.value),sizeKey:w,optionId:`${S}-option-${t}`,onClick:N,onMouseEnter:f,index:t,ref:u=>{re.current[t]=u}},e.value))})]}),document.body):null]})}0&&(module.exports={Select});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{useState as R,useRef as U,useEffect as H,useCallback as h,useMemo as Z,useId as Oe,memo as Te,forwardRef as Ae}from"react";import{createPortal as Pe}from"react-dom";import{registerFloatingLayer as Re}from"../../lib/aria-hide.js";import{useUILabels as He}from"../../lib/i18n.js";import{jsx as n,jsxs as v}from"react/jsx-runtime";var G=()=>{},Ke=[],Ve=n("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0",children:n("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Be=n("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:n("path",{d:"M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),$e=v("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0 animate-spin",children:[n("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",strokeOpacity:"0.25"}),n("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),We=n("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:n("path",{d:"M11.5 3.5L5.5 10.5L2.5 7.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),K={sm:{trigger:"h-8 px-2.5 text-xs gap-1.5",content:"text-xs",option:"px-2.5 py-1.5",searchInput:"px-2.5 py-1.5 text-xs"},md:{trigger:"h-10 px-3 text-sm gap-2",content:"text-sm",option:"px-3 py-2",searchInput:"px-3 py-2 text-sm"},lg:{trigger:"h-12 px-4 text-base gap-2.5",content:"text-base",option:"px-4 py-2.5",searchInput:"px-4 py-2.5 text-base"}},fe={default:{trigger:"border border-gray-300 bg-white dark:border-gray-600 dark:bg-gray-800",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"},outlined:{trigger:"border-2 border-gray-300 bg-transparent dark:border-gray-600",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"},filled:{trigger:"border border-transparent bg-gray-100 dark:bg-gray-700",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}};function k(...i){let o="";for(let u=0;u<i.length;u++){let a=i[u];a&&(o&&(o+=" "),o+=a)}return o}function Ue(i,o){if(!o)return i;let u=o.toLowerCase();return i.filter(a=>{if(a.label.toLowerCase().includes(u)||a.value.toLowerCase().includes(u))return!0;if(a.keywords){for(let d of a.keywords)if(d.toLowerCase().includes(u))return!0}return!1})}var Ye=Te(Ae(function({option:o,isSelected:u,isHighlighted:a,isDisabled:d,sizeKey:Y,optionId:f,onClick:b,onMouseEnter:D,index:y},V){let j=()=>{d||b(o.value)},L=()=>{d||D(y)};return v("div",{ref:V,id:f,role:"option","aria-selected":u,"aria-disabled":d||void 0,"data-highlighted":a||void 0,className:k(K[Y].option,"flex items-center gap-2 cursor-pointer select-none transition-colors",a&&!d&&"bg-blue-50 dark:bg-blue-900/30",u&&!a&&"bg-gray-50 dark:bg-gray-700/50",d&&"opacity-50 cursor-not-allowed"),onClick:j,onMouseEnter:L,children:[o.icon?n("span",{className:"flex shrink-0 items-center",children:o.icon}):null,v("span",{className:"flex flex-col min-w-0 flex-1",children:[n("span",{className:"truncate",children:o.label}),o.description?n("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:o.description}):null]}),u?n("span",{className:"ml-auto text-blue-600 dark:text-blue-400",children:We}):null]})}));function Fe({options:i=Ke,value:o,defaultValue:u,onValueChange:a,searchable:d=!1,clearable:Y=!1,disabled:f=!1,readOnly:b=!1,loading:D=!1,size:y="md",variant:V="default",placeholder:j,label:L,description:J,helperText:ee,error:C,required:te=!1,noOptionsText:ge,clearLabel:be,searchLabel:me,searchPlaceholder:he,onSearchChange:ne,name:re,className:ve,triggerClassName:xe,contentClassName:we,maxHeight:z=256}){let S=He(),ke=j??S.selectPlaceholder,ye=ge??S.selectNoOptions,M=Oe(),_=`${M}-label`,oe=`${M}-trigger`,se=`${M}-listbox`,x=U(null),q=U(null),ae=U(null),le=U([]),O=o!==void 0,[Ee,ie]=R(u??""),N=O?o:Ee,[c,F]=R(!1),[Q,T]=R(""),[r,p]=R(-1),[A,ce]=R(null),l=Z(()=>d?Ue(i,Q):i,[i,Q,d]),B=Z(()=>i.find(e=>e.value===N)??null,[i,N]),w=Z(()=>{let e=new Set;for(let t of i)t.disabled&&e.add(t.value);return e},[i]),I=h(e=>{O||ie(e),(a??G)(e),F(!1),T(""),p(-1),x.current?.focus()},[O,a]),Le=h(e=>{e.stopPropagation(),O||ie(""),(a??G)(""),T(""),x.current?.focus()},[O,a]),P=h(()=>{f||b||(F(!0),T(""),p(-1))},[f,b]),g=h(()=>{F(!1),T(""),p(-1),x.current?.focus()},[]),Ne=h(()=>{c?g():P()},[c,g,P]),m=h((e,t)=>{let s=l.length;if(s===0)return-1;let E=e;for(let W=0;W<s;W++)if(E=((E+t)%s+s)%s,!w.has(l[E].value))return E;return-1},[l,w]),Ie=h(e=>{if(!(f||b)){if(c){switch(e.key){case"ArrowDown":{e.preventDefault();let t=m(r,1);t!==-1&&p(t);break}case"ArrowUp":{e.preventDefault();let t=m(r,-1);t!==-1&&p(t);break}case"Home":{e.preventDefault();let t=m(-1,1);t!==-1&&p(t);break}case"End":{e.preventDefault();let t=m(l.length,-1);t!==-1&&p(t);break}case"Enter":{if(e.preventDefault(),r>=0&&r<l.length){let t=l[r];w.has(t.value)||I(t.value)}break}case" ":if(e.preventDefault(),r>=0&&r<l.length){let t=l[r];w.has(t.value)||I(t.value)}else g();break;case"Escape":e.preventDefault(),g();break;case"Tab":g();break}return}switch(e.key){case"ArrowDown":case"ArrowUp":e.preventDefault(),P();break;case"Enter":case" ":e.preventDefault(),P();break}}},[f,b,c,P,g,r,l,w,m,I]),De=h(e=>{switch(e.key){case"ArrowDown":{e.preventDefault();let t=m(r,1);t!==-1&&p(t);break}case"ArrowUp":{e.preventDefault();let t=m(r,-1);t!==-1&&p(t);break}case"Home":{e.preventDefault();let t=m(-1,1);t!==-1&&p(t);break}case"End":{e.preventDefault();let t=m(l.length,-1);t!==-1&&p(t);break}case"Enter":{if(e.preventDefault(),r>=0&&r<l.length){let t=l[r];w.has(t.value)||I(t.value)}break}case"Escape":e.preventDefault(),g();break;case"Tab":g();break}},[r,l,w,m,I,g]),Ce=h(e=>{let t=e.target.value;T(t),p(-1),(ne??G)(t)},[ne]);H(()=>{if(!c)return;let e=t=>{let s=t.target;x.current?.contains(s)||q.current?.contains(s)||g()};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e,{passive:!0}),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)}},[c,g]),H(()=>{if(!c||!x.current){ce(null);return}let e=()=>{let t=x.current;if(!t)return;let s=t.getBoundingClientRect(),E=window.innerHeight-s.bottom,W=s.top,de=z+8,pe=E<de&&W>E?"top":"bottom";ce({top:pe==="bottom"?s.bottom+window.scrollY+4:s.top+window.scrollY-de,left:s.left+window.scrollX,width:s.width,placement:pe})};return e(),window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[c,z]);let $=c&&A!==null;H(()=>{$&&d&&ae.current?.focus()},[$,d]),H(()=>{let e=q.current;if(!(!$||!e))return Re(e,()=>x.current)},[$]),H(()=>{if(r>=0){let e=le.current[r];e&&typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest"})}},[r]);let X=N!==""&&N!==void 0,Se=Y&&X&&!f&&!b&&!D,ue=!f&&!b,Me=k("w-full flex items-center justify-between rounded-md transition-colors","text-gray-900 dark:text-gray-100",K[y].trigger,fe[V].trigger,!C&&ue&&fe[V].focus,C&&"border-red-500 dark:border-red-400 focus:ring-2 focus:ring-red-500 focus:border-red-500",f&&"opacity-50 cursor-not-allowed bg-gray-50 dark:bg-gray-900",b&&"cursor-default",!f&&!b&&"cursor-pointer",xe);return v("div",{className:k("flex flex-col gap-1",ve),children:[L?v("label",{id:_,htmlFor:oe,className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:[L,te?n("span",{className:"text-red-500 ml-0.5","aria-hidden":"true",children:"*"}):null]}):null,J?n("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:J}):null,v("button",{ref:x,id:oe,type:"button",role:"combobox","aria-expanded":c,"aria-haspopup":"listbox","aria-controls":c?se:void 0,"aria-labelledby":L?_:void 0,"aria-required":te||void 0,"aria-invalid":C?!0:void 0,"aria-activedescendant":c&&r>=0?`${M}-option-${r}`:void 0,disabled:f,className:Me,onClick:ue?Ne:void 0,onKeyDown:Ie,children:[v("span",{className:k("flex items-center gap-2 min-w-0 flex-1 truncate",!X&&"text-gray-400 dark:text-gray-500"),children:[B?.icon?n("span",{className:"flex shrink-0 items-center",children:B.icon}):null,n("span",{className:"truncate",children:X&&B?B.label:ke})]}),v("span",{className:"flex items-center gap-1 shrink-0",children:[D?n("span",{className:"text-gray-400",children:$e}):null,Se?n("span",{role:"button",tabIndex:-1,"aria-label":be??S.selectClear,className:"text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 p-0.5 rounded transition-colors",onClick:Le,onMouseDown:e=>e.preventDefault(),children:Be}):null,n("span",{className:k("text-gray-400 transition-transform duration-200",c&&"rotate-180"),children:Ve})]})]}),C?n("p",{role:"alert",className:"text-xs text-red-500 dark:text-red-400",children:C}):ee?n("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:ee}):null,re?n("input",{type:"hidden",name:re,value:N??""}):null,c&&A?Pe(v("div",{ref:q,role:"listbox",id:se,"aria-labelledby":L?_:void 0,className:k("fixed z-50 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700","rounded-md shadow-lg overflow-hidden","animate-in fade-in-0 zoom-in-95",K[y].content,we),style:{top:A.top,left:A.left,width:A.width,position:"absolute"},onKeyDown:De,children:[d?n("div",{className:"border-b border-gray-200 dark:border-gray-700",children:n("input",{ref:ae,type:"text",role:"searchbox","aria-label":me??S.selectSearch,className:k(K[y].searchInput,"w-full outline-none bg-transparent text-gray-900 dark:text-gray-100","placeholder:text-gray-400 dark:placeholder:text-gray-500"),placeholder:he??S.selectSearchPlaceholder,value:Q,onChange:Ce})}):null,n("div",{className:"overflow-y-auto",style:{maxHeight:z},children:l.length===0?n("div",{className:k(K[y].option,"text-gray-500 dark:text-gray-400 text-center py-4"),children:ye}):l.map((e,t)=>n(Ye,{option:e,isSelected:e.value===N,isHighlighted:t===r,isDisabled:D||w.has(e.value),sizeKey:y,optionId:`${M}-option-${t}`,onClick:I,onMouseEnter:p,index:t,ref:s=>{le.current[t]=s}},e.value))})]}),document.body):null]})}export{Fe as Select};
|
|
1
|
+
"use client";import{useState as R,useRef as U,useEffect as H,useCallback as h,useMemo as Z,useId as Oe,memo as Te,forwardRef as Ae}from"react";import{createPortal as Pe}from"react-dom";import{registerFloatingLayer as Re}from"../../lib/aria-hide.js";import{useUILabels as He}from"../../lib/i18n.js";import{jsx as n,jsxs as x}from"react/jsx-runtime";var G=()=>{},Ke=[],Ve=n("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0",children:n("path",{d:"M4 6L8 10L12 6",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),Be=n("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:n("path",{d:"M10.5 3.5L3.5 10.5M3.5 3.5L10.5 10.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),$e=x("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none","aria-hidden":"true",className:"shrink-0 animate-spin",children:[n("circle",{cx:"8",cy:"8",r:"6",stroke:"currentColor",strokeWidth:"2",strokeOpacity:"0.25"}),n("path",{d:"M14 8a6 6 0 00-6-6",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})]}),We=n("svg",{width:"14",height:"14",viewBox:"0 0 14 14",fill:"none","aria-hidden":"true",className:"shrink-0",children:n("path",{d:"M11.5 3.5L5.5 10.5L2.5 7.5",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),K={sm:{trigger:"h-8 px-2.5 text-xs gap-1.5",content:"text-xs",option:"px-2.5 py-1.5",searchInput:"px-2.5 py-1.5 text-xs"},md:{trigger:"h-10 px-3 text-sm gap-2",content:"text-sm",option:"px-3 py-2",searchInput:"px-3 py-2 text-sm"},lg:{trigger:"h-12 px-4 text-base gap-2.5",content:"text-base",option:"px-4 py-2.5",searchInput:"px-4 py-2.5 text-base"}},fe={default:{trigger:"border border-gray-300 bg-white dark:border-gray-600 dark:bg-gray-800",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"},outlined:{trigger:"border-2 border-gray-300 bg-transparent dark:border-gray-600",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"},filled:{trigger:"border border-transparent bg-gray-100 dark:bg-gray-700",focus:"focus:ring-2 focus:ring-blue-500 focus:border-blue-500"}};function w(...i){let o="";for(let u=0;u<i.length;u++){let s=i[u];s&&(o&&(o+=" "),o+=s)}return o}function Ue(i,o){if(!o)return i;let u=o.toLowerCase();return i.filter(s=>{if(s.label.toLowerCase().includes(u)||s.value.toLowerCase().includes(u))return!0;if(s.keywords){for(let d of s.keywords)if(d.toLowerCase().includes(u))return!0}return!1})}var Ye=Te(Ae(function({option:o,isSelected:u,isHighlighted:s,isDisabled:d,sizeKey:Y,optionId:f,onClick:b,onMouseEnter:D,index:y},V){let j=()=>{d||b(o.value)},L=()=>{d||D(y)};return x("div",{ref:V,id:f,role:"option","aria-selected":u,"aria-disabled":d||void 0,"data-highlighted":s||void 0,className:w(K[Y].option,"flex items-center gap-2 cursor-pointer select-none transition-colors",s&&!d&&"bg-blue-50 dark:bg-blue-900/30",u&&!s&&"bg-gray-50 dark:bg-gray-700/50",d&&"opacity-50 cursor-not-allowed"),onClick:j,onMouseEnter:L,children:[o.icon?n("span",{className:"flex shrink-0 items-center",children:o.icon}):null,x("span",{className:"flex flex-col min-w-0 flex-1",children:[n("span",{className:"truncate",children:o.label}),o.description?n("span",{className:"text-xs text-gray-500 dark:text-gray-400 truncate",children:o.description}):null]}),u?n("span",{className:"ml-auto text-blue-600 dark:text-blue-400",children:We}):null]})}));function Fe({options:i=Ke,value:o,defaultValue:u,onValueChange:s,searchable:d=!1,clearable:Y=!1,disabled:f=!1,readOnly:b=!1,loading:D=!1,size:y="md",variant:V="default",placeholder:j,label:L,description:J,helperText:ee,error:C,required:te=!1,noOptionsText:ge,clearLabel:be,searchLabel:me,searchPlaceholder:he,onSearchChange:ne,name:re,className:xe,triggerClassName:ve,contentClassName:ke,maxHeight:z=256}){let S=He(),we=j??S.selectPlaceholder,ye=ge??S.selectNoOptions,M=Oe(),_=`${M}-label`,oe=`${M}-trigger`,ae=`${M}-listbox`,v=U(null),q=U(null),se=U(null),le=U([]),O=o!==void 0,[Ee,ie]=R(u??""),N=O?o:Ee,[c,F]=R(!1),[Q,T]=R(""),[r,p]=R(-1),[A,ce]=R(null),l=Z(()=>d?Ue(i,Q):i,[i,Q,d]),B=Z(()=>i.find(e=>e.value===N)??null,[i,N]),k=Z(()=>{let e=new Set;for(let t of i)t.disabled&&e.add(t.value);return e},[i]),I=h(e=>{O||ie(e),(s??G)(e),F(!1),T(""),p(-1),v.current?.focus()},[O,s]),Le=h(e=>{e.stopPropagation(),O||ie(""),(s??G)(""),T(""),v.current?.focus()},[O,s]),P=h(()=>{f||b||(F(!0),T(""),p(-1))},[f,b]),g=h(()=>{F(!1),T(""),p(-1),v.current?.focus()},[]),Ne=h(()=>{c?g():P()},[c,g,P]),m=h((e,t)=>{let a=l.length;if(a===0)return-1;let E=e;for(let W=0;W<a;W++)if(E=((E+t)%a+a)%a,!k.has(l[E].value))return E;return-1},[l,k]),Ie=h(e=>{if(!(f||b)){if(c){switch(e.key){case"ArrowDown":{e.preventDefault();let t=m(r,1);t!==-1&&p(t);break}case"ArrowUp":{e.preventDefault();let t=m(r,-1);t!==-1&&p(t);break}case"Home":{e.preventDefault();let t=m(-1,1);t!==-1&&p(t);break}case"End":{e.preventDefault();let t=m(l.length,-1);t!==-1&&p(t);break}case"Enter":{if(e.preventDefault(),r>=0&&r<l.length){let t=l[r];k.has(t.value)||I(t.value)}break}case" ":if(e.preventDefault(),r>=0&&r<l.length){let t=l[r];k.has(t.value)||I(t.value)}else g();break;case"Escape":e.preventDefault(),g();break;case"Tab":g();break}return}switch(e.key){case"ArrowDown":case"ArrowUp":e.preventDefault(),P();break;case"Enter":case" ":e.preventDefault(),P();break}}},[f,b,c,P,g,r,l,k,m,I]),De=h(e=>{switch(e.key){case"ArrowDown":{e.preventDefault();let t=m(r,1);t!==-1&&p(t);break}case"ArrowUp":{e.preventDefault();let t=m(r,-1);t!==-1&&p(t);break}case"Home":{e.preventDefault();let t=m(-1,1);t!==-1&&p(t);break}case"End":{e.preventDefault();let t=m(l.length,-1);t!==-1&&p(t);break}case"Enter":{if(e.preventDefault(),r>=0&&r<l.length){let t=l[r];k.has(t.value)||I(t.value)}break}case"Escape":e.preventDefault(),g();break;case"Tab":g();break}},[r,l,k,m,I,g]),Ce=h(e=>{let t=e.target.value;T(t),p(-1),(ne??G)(t)},[ne]);H(()=>{if(!c)return;let e=t=>{let a=t.target;v.current?.contains(a)||q.current?.contains(a)||g()};return document.addEventListener("mousedown",e),document.addEventListener("touchstart",e,{passive:!0}),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("touchstart",e)}},[c,g]),H(()=>{if(!c||!v.current){ce(null);return}let e=()=>{let t=v.current;if(!t)return;let a=t.getBoundingClientRect(),E=window.innerHeight-a.bottom,W=a.top,de=z+8,pe=E<de&&W>E?"top":"bottom";ce({top:pe==="bottom"?a.bottom+window.scrollY+4:a.top+window.scrollY-de,left:a.left+window.scrollX,width:a.width,placement:pe})};return e(),window.addEventListener("scroll",e,!0),window.addEventListener("resize",e),()=>{window.removeEventListener("scroll",e,!0),window.removeEventListener("resize",e)}},[c,z]);let $=c&&A!==null;H(()=>{$&&d&&se.current?.focus()},[$,d]),H(()=>{let e=q.current;if(!(!$||!e))return Re(e,()=>v.current)},[$]),H(()=>{if(r>=0){let e=le.current[r];e&&typeof e.scrollIntoView=="function"&&e.scrollIntoView({block:"nearest"})}},[r]);let X=N!==""&&N!==void 0,Se=Y&&X&&!f&&!b&&!D,ue=!f&&!b,Me=w("w-full flex items-center justify-between rounded-md transition-colors","text-gray-900 dark:text-gray-100",K[y].trigger,fe[V].trigger,!C&&ue&&fe[V].focus,C&&"border-red-500 dark:border-red-400 focus:ring-2 focus:ring-red-500 focus:border-red-500",f&&"opacity-50 cursor-not-allowed bg-gray-50 dark:bg-gray-900",b&&"cursor-default",!f&&!b&&"cursor-pointer",ve);return x("div",{className:w("flex flex-col gap-1",xe),children:[L?x("label",{id:_,htmlFor:oe,className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:[L,te?n("span",{className:"text-red-600 dark:text-red-400 ml-0.5","aria-hidden":"true",children:"*"}):null]}):null,J?n("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:J}):null,x("button",{ref:v,id:oe,type:"button",role:"combobox","aria-expanded":c,"aria-haspopup":"listbox","aria-controls":c?ae:void 0,"aria-labelledby":L?_:void 0,"aria-required":te||void 0,"aria-invalid":C?!0:void 0,"aria-activedescendant":c&&r>=0?`${M}-option-${r}`:void 0,disabled:f,className:Me,onClick:ue?Ne:void 0,onKeyDown:Ie,children:[x("span",{className:w("flex items-center gap-2 min-w-0 flex-1 truncate",!X&&"text-gray-600 dark:text-gray-300"),children:[B?.icon?n("span",{className:"flex shrink-0 items-center",children:B.icon}):null,n("span",{className:"truncate",children:X&&B?B.label:we})]}),x("span",{className:"flex items-center gap-1 shrink-0",children:[D?n("span",{className:"text-gray-500 dark:text-gray-400",children:$e}):null,Se?n("span",{role:"button",tabIndex:-1,"aria-label":be??S.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:Le,onMouseDown:e=>e.preventDefault(),children:Be}):null,n("span",{className:w("text-gray-500 dark:text-gray-400 transition-transform duration-200",c&&"rotate-180"),children:Ve})]})]}),C?n("p",{role:"alert",className:"text-xs text-red-600 dark:text-red-400",children:C}):ee?n("p",{className:"text-xs text-gray-500 dark:text-gray-400",children:ee}):null,re?n("input",{type:"hidden",name:re,value:N??""}):null,c&&A?Pe(x("div",{ref:q,role:"listbox",id:ae,"aria-labelledby":L?_:void 0,className:w("fixed z-50 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700","rounded-md shadow-lg overflow-hidden","animate-in fade-in-0 zoom-in-95",K[y].content,ke),style:{top:A.top,left:A.left,width:A.width,position:"absolute"},onKeyDown:De,children:[d?n("div",{className:"border-b border-gray-200 dark:border-gray-700",children:n("input",{ref:se,type:"text",role:"searchbox","aria-label":me??S.selectSearch,className:w(K[y].searchInput,"w-full outline-none bg-transparent text-gray-900 dark:text-gray-100","placeholder:text-gray-500 dark:placeholder:text-gray-400"),placeholder:he??S.selectSearchPlaceholder,value:Q,onChange:Ce})}):null,n("div",{className:"overflow-y-auto",style:{maxHeight:z},children:l.length===0?n("div",{className:w(K[y].option,"text-gray-500 dark:text-gray-400 text-center py-4"),children:ye}):l.map((e,t)=>n(Ye,{option:e,isSelected:e.value===N,isHighlighted:t===r,isDisabled:D||k.has(e.value),sizeKey:y,optionId:`${M}-option-${t}`,onClick:I,onMouseEnter:p,index:t,ref:a=>{le.current[t]=a}},e.value))})]}),document.body):null]})}export{Fe as Select};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";"use client";var T=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var ee=(t,r)=>{for(var a in r)T(t,a,{get:r[a],enumerable:!0})},te=(t,r,a,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of Z(r))!_.call(t,s)&&s!==a&&T(t,s,{get:()=>r[s],enumerable:!(n=K(r,s))||n.enumerable});return t};var re=t=>te(T({},"__esModule",{value:!0}),t);var ge={};ee(ge,{Sidebar:()=>se,SidebarContent:()=>de,SidebarFooter:()=>ce,SidebarGroup:()=>ue,SidebarHeader:()=>le,SidebarItem:()=>be,SidebarSubMenu:()=>pe,SidebarToggle:()=>fe,useSidebar:()=>ae});module.exports=re(ge);var o=require("react"),j=require("../../hooks/useDialogA11y.cjs"),i=require("../../lib/cn.cjs"),M=require("../../lib/i18n.cjs"),e=require("react/jsx-runtime"),E=(0,o.createContext)(null);function y(){let t=(0,o.useContext)(E);if(!t)throw new Error("Sidebar sub-components must be used within <Sidebar>");return t}function ae(){return y()}var oe=({className:t})=>(0,e.jsx)("svg",{className:(0,i.cn)("w-4 h-4",t),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{fillRule:"evenodd",d:"M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z",clipRule:"evenodd"})}),ne=({className:t})=>(0,e.jsx)("svg",{className:(0,i.cn)("w-4 h-4",t),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})}),ie=({className:t})=>(0,e.jsx)("svg",{className:(0,i.cn)("w-5 h-5",t),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{d:"M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"})});function B({text:t,position:r,children:a}){let[n,s]=(0,o.useState)(!1),[c,f]=(0,o.useState)({top:0,left:0}),u=(0,o.useRef)(null);return(0,e.jsxs)("div",{ref:u,onMouseEnter:()=>{if(u.current){let d=u.current.getBoundingClientRect();f({top:d.top+d.height/2,left:r==="left"?d.right+8:d.left-8})}s(!0)},onMouseLeave:()=>s(!1),className:"relative",children:[a,n&&(0,e.jsx)("div",{className:(0,i.cn)("fixed z-[9999] px-2.5 py-1.5 text-xs font-medium text-white bg-gray-900 dark:bg-gray-700 rounded-md shadow-lg whitespace-nowrap pointer-events-none",r==="right"&&"-translate-x-full"),style:{top:c.top,left:c.left,transform:`translateY(-50%)${r==="right"?" translateX(-100%)":""}`},role:"tooltip",children:t})]})}function se({collapsed:t,defaultCollapsed:r=!1,onCollapsedChange:a,expandedWidth:n=260,collapsedWidth:s=64,position:c="left",variant:f="default",mobileBreakpoint:u=768,mobileOpen:x,onMobileOpenChange:d,className:m,"aria-label":b,closeLabel:N,trapFocus:g=!0,initialFocus:S,returnFocus:k,lockScroll:C=!0,children:O}){let G=(0,M.useUILabels)(),D=(0,o.useRef)(null),F=(0,o.useRef)(null),[q,Q]=(0,o.useState)(r),[W,R]=(0,o.useState)(!1),[p,$]=(0,o.useState)(!1),L=t!==void 0,w=L?t:q,v=x!==void 0,h=v?x:W;(0,o.useEffect)(()=>{let l=window.matchMedia(`(max-width: ${u}px)`),I=A=>{$(A.matches),A.matches||(v||R(!1),d?.(!1))};return I(l),l.addEventListener("change",I),()=>l.removeEventListener("change",I)},[u,v,d]);let U=(0,o.useCallback)(()=>{if(p){let l=!h;v||R(l),d?.(l)}else{let l=!w;L||Q(l),a?.(l)}},[p,h,w,v,L,d,a]),P=(0,o.useCallback)(()=>{v||R(!1),d?.(!1)},[v,d]);(0,o.useEffect)(()=>{let l=F.current;l&&(p&&!h?(l.setAttribute("inert",""),l.setAttribute("aria-hidden","true")):(l.removeAttribute("inert"),l.removeAttribute("aria-hidden")))},[p,h]);let{dialogRef:X,dialogProps:Y}=(0,j.useDialogA11y)({open:p&&h,onClose:P,trapFocus:g,initialFocus:S,returnFocus:k,lockScroll:C,keepInteractive:[D]}),J={default:"bg-white dark:bg-gray-900",bordered:(0,i.cn)("bg-white dark:bg-gray-900",c==="left"?"border-r border-gray-200 dark:border-gray-700":"border-l border-gray-200 dark:border-gray-700"),floating:"bg-white dark:bg-gray-900 m-3 rounded-xl shadow-xl border border-gray-200 dark:border-gray-700"},H=w&&!p?s:n,V=(0,e.jsx)("aside",{className:(0,i.cn)("flex flex-col h-full overflow-hidden transition-[width] duration-200 ease-in-out",J[f],m),style:{width:p?n:H,minWidth:p?n:H},"data-testid":"sidebar","data-collapsed":w&&!p,"data-mobile":p,"data-position":c,children:O}),z={collapsed:w&&!p,isMobile:p,mobileOpen:h,position:c,variant:f,expandedWidth:n,collapsedWidth:s,toggle:U,closeMobile:P,closeLabel:N};return p?(0,e.jsxs)(E.Provider,{value:z,children:[h&&(0,e.jsx)("div",{ref:D,className:"fixed inset-0 z-40 bg-black/50 transition-opacity",onClick:P,"aria-hidden":"true","data-testid":"sidebar-overlay"}),(0,e.jsx)("div",{ref:l=>{F.current=l,X.current=l},...Y,"aria-label":b??G.sidebar,className:(0,i.cn)("fixed top-0 z-50 h-full transition-transform duration-200 ease-in-out focus:outline-none",c==="left"?"left-0":"right-0",h?"translate-x-0":c==="left"?"-translate-x-full":"translate-x-full"),children:V})]}):(0,e.jsx)(E.Provider,{value:z,children:V})}function le({className:t,children:r}){let a=y(),n=(0,M.useUILabels)();return(0,e.jsxs)("div",{className:(0,i.cn)("flex items-center shrink-0 px-4 h-14 overflow-hidden",a.collapsed&&"justify-center px-2",t),"data-testid":"sidebar-header",children:[r,a.isMobile&&a.mobileOpen&&(0,e.jsx)("button",{type:"button",onClick:a.closeMobile,className:"ml-auto p-1 rounded-md text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer","aria-label":a.closeLabel??n.closeSidebar,children:(0,e.jsx)(ie,{})})]})}function de({className:t,children:r}){return(0,e.jsx)("div",{className:(0,i.cn)("flex-1 overflow-y-auto overflow-x-hidden py-2",t),"data-testid":"sidebar-content",children:r})}function ce({className:t,children:r}){let a=y();return(0,e.jsx)("div",{className:(0,i.cn)("shrink-0 border-t border-gray-200 dark:border-gray-700 px-4 py-3 overflow-hidden",a.collapsed&&"px-2 flex justify-center",t),"data-testid":"sidebar-footer",children:r})}function ue({label:t,className:r,children:a}){let n=y();return(0,e.jsxs)("div",{className:(0,i.cn)("py-2",r),"data-testid":"sidebar-group",children:[t&&!n.collapsed&&(0,e.jsx)("div",{className:"px-4 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-gray-400 dark:text-gray-500",children:t}),t&&n.collapsed&&(0,e.jsx)("div",{className:"mx-auto my-1 w-6 border-t border-gray-200 dark:border-gray-700"}),(0,e.jsx)("div",{className:"space-y-0.5 px-2",children:a})]})}function be({icon:t,label:r,badge:a,badgeColor:n="bg-blue-600 text-white",active:s=!1,disabled:c=!1,href:f,onClick:u,tooltip:x,className:d}){let m=y(),b=m.collapsed,N=x??r,g=(0,e.jsxs)(e.Fragment,{children:[t&&(0,e.jsx)("span",{className:(0,i.cn)("shrink-0 w-5 h-5",b&&"w-5 h-5"),children:t}),!b&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"flex-1 truncate",children:r}),a!=null&&(0,e.jsx)("span",{className:(0,i.cn)("shrink-0 inline-flex items-center justify-center rounded-full text-[10px] font-semibold min-w-[18px] h-[18px] px-1",n),children:a})]}),b&&a!==void 0&&a!==null&&(0,e.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 rounded-full bg-blue-600"})]}),S=(0,i.cn)("relative flex items-center gap-3 rounded-md text-sm font-medium transition-colors w-full",b?"justify-center px-2 py-2.5":"px-3 py-2",s?"bg-blue-50 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400":"text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800",c&&"opacity-50 pointer-events-none",!c&&"cursor-pointer",d),k=()=>{c||(u?.(),m.isMobile&&m.closeMobile())},C=f?(0,e.jsx)("a",{href:c?void 0:f,className:S,onClick:k,"aria-current":s?"page":void 0,"data-testid":"sidebar-item",children:g}):(0,e.jsx)("button",{type:"button",className:S,onClick:k,disabled:c,"aria-current":s?"page":void 0,"data-testid":"sidebar-item",children:g});return b?(0,e.jsx)(B,{text:N,position:m.position,children:C}):C}function pe({icon:t,label:r,badge:a,defaultOpen:n=!1,className:s,children:c}){let f=y(),[u,x]=(0,o.useState)(n),d=(0,o.useRef)(null),[m,b]=(0,o.useState)(n?void 0:0),N=(0,o.useRef)(!0);return(0,o.useEffect)(()=>{if(N.current){N.current=!1,b(u?void 0:0);return}if(u){let g=d.current;if(g){b(g.scrollHeight);let S=setTimeout(()=>b(void 0),200);return()=>clearTimeout(S)}}else{let g=d.current;g&&(b(g.scrollHeight),requestAnimationFrame(()=>b(0)))}},[u]),f.collapsed?(0,e.jsx)(B,{text:r,position:f.position,children:(0,e.jsxs)("button",{type:"button",className:(0,i.cn)("relative flex items-center justify-center gap-3 rounded-md text-sm font-medium transition-colors w-full px-2 py-2.5","text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer",s),onClick:()=>{f.toggle(),x(!0)},"data-testid":"sidebar-submenu-trigger",children:[t&&(0,e.jsx)("span",{className:"shrink-0 w-5 h-5",children:t}),a!=null&&(0,e.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 rounded-full bg-blue-600"})]})}):(0,e.jsxs)("div",{className:s,"data-testid":"sidebar-submenu",children:[(0,e.jsxs)("button",{type:"button",className:(0,i.cn)("flex items-center gap-3 rounded-md text-sm font-medium transition-colors w-full px-3 py-2","text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer"),onClick:()=>x(!u),"aria-expanded":u,"data-testid":"sidebar-submenu-trigger",children:[t&&(0,e.jsx)("span",{className:"shrink-0 w-5 h-5",children:t}),(0,e.jsx)("span",{className:"flex-1 truncate text-left",children:r}),a!=null&&(0,e.jsx)("span",{className:"shrink-0 inline-flex items-center justify-center rounded-full text-[10px] font-semibold min-w-[18px] h-[18px] px-1 bg-blue-600 text-white",children:a}),(0,e.jsx)(ne,{className:(0,i.cn)("shrink-0 text-gray-400 transition-transform duration-200",u&&"rotate-180")})]}),(0,e.jsx)("div",{className:"overflow-hidden transition-[height] duration-200 ease-in-out",style:{height:m===void 0?"auto":m},children:(0,e.jsx)("div",{ref:d,className:"pl-4 py-0.5",children:c})})]})}function fe({className:t}){let r=y(),a=(0,M.useUILabels)(),n=r.isMobile?r.mobileOpen?r.closeLabel??a.closeSidebar:a.openSidebar:r.collapsed?a.expandSidebar:a.collapseSidebar;return(0,e.jsx)("button",{type:"button",onClick:r.toggle,className:(0,i.cn)("p-1.5 rounded-md text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors cursor-pointer",t),"aria-label":n,"data-testid":"sidebar-toggle",children:(0,e.jsx)(oe,{className:(0,i.cn)("transition-transform duration-200",r.collapsed&&"rotate-180",r.position==="right"&&!r.collapsed&&"rotate-180",r.position==="right"&&r.collapsed&&"rotate-0")})})}0&&(module.exports={Sidebar,SidebarContent,SidebarFooter,SidebarGroup,SidebarHeader,SidebarItem,SidebarSubMenu,SidebarToggle,useSidebar});
|
|
1
|
+
"use strict";"use client";var T=Object.defineProperty;var K=Object.getOwnPropertyDescriptor;var Z=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var ee=(t,r)=>{for(var a in r)T(t,a,{get:r[a],enumerable:!0})},te=(t,r,a,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let s of Z(r))!_.call(t,s)&&s!==a&&T(t,s,{get:()=>r[s],enumerable:!(n=K(r,s))||n.enumerable});return t};var re=t=>te(T({},"__esModule",{value:!0}),t);var ge={};ee(ge,{Sidebar:()=>se,SidebarContent:()=>de,SidebarFooter:()=>ce,SidebarGroup:()=>ue,SidebarHeader:()=>le,SidebarItem:()=>be,SidebarSubMenu:()=>pe,SidebarToggle:()=>fe,useSidebar:()=>ae});module.exports=re(ge);var o=require("react"),j=require("../../hooks/useDialogA11y.cjs"),i=require("../../lib/cn.cjs"),M=require("../../lib/i18n.cjs"),e=require("react/jsx-runtime"),E=(0,o.createContext)(null);function y(){let t=(0,o.useContext)(E);if(!t)throw new Error("Sidebar sub-components must be used within <Sidebar>");return t}function ae(){return y()}var oe=({className:t})=>(0,e.jsx)("svg",{className:(0,i.cn)("w-4 h-4",t),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{fillRule:"evenodd",d:"M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z",clipRule:"evenodd"})}),ne=({className:t})=>(0,e.jsx)("svg",{className:(0,i.cn)("w-4 h-4",t),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{fillRule:"evenodd",d:"M5.23 7.21a.75.75 0 011.06.02L10 11.168l3.71-3.938a.75.75 0 111.08 1.04l-4.25 4.5a.75.75 0 01-1.08 0l-4.25-4.5a.75.75 0 01.02-1.06z",clipRule:"evenodd"})}),ie=({className:t})=>(0,e.jsx)("svg",{className:(0,i.cn)("w-5 h-5",t),viewBox:"0 0 20 20",fill:"currentColor","aria-hidden":"true",children:(0,e.jsx)("path",{d:"M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"})});function B({text:t,position:r,children:a}){let[n,s]=(0,o.useState)(!1),[c,f]=(0,o.useState)({top:0,left:0}),u=(0,o.useRef)(null);return(0,e.jsxs)("div",{ref:u,onMouseEnter:()=>{if(u.current){let d=u.current.getBoundingClientRect();f({top:d.top+d.height/2,left:r==="left"?d.right+8:d.left-8})}s(!0)},onMouseLeave:()=>s(!1),className:"relative",children:[a,n&&(0,e.jsx)("div",{className:(0,i.cn)("fixed z-[9999] px-2.5 py-1.5 text-xs font-medium text-white bg-gray-900 dark:bg-gray-700 rounded-md shadow-lg whitespace-nowrap pointer-events-none",r==="right"&&"-translate-x-full"),style:{top:c.top,left:c.left,transform:`translateY(-50%)${r==="right"?" translateX(-100%)":""}`},role:"tooltip",children:t})]})}function se({collapsed:t,defaultCollapsed:r=!1,onCollapsedChange:a,expandedWidth:n=260,collapsedWidth:s=64,position:c="left",variant:f="default",mobileBreakpoint:u=768,mobileOpen:x,onMobileOpenChange:d,className:m,"aria-label":b,closeLabel:N,trapFocus:g=!0,initialFocus:S,returnFocus:w,lockScroll:C=!0,children:O}){let G=(0,M.useUILabels)(),D=(0,o.useRef)(null),F=(0,o.useRef)(null),[q,Q]=(0,o.useState)(r),[W,R]=(0,o.useState)(!1),[p,$]=(0,o.useState)(!1),L=t!==void 0,k=L?t:q,v=x!==void 0,h=v?x:W;(0,o.useEffect)(()=>{let l=window.matchMedia(`(max-width: ${u}px)`),I=A=>{$(A.matches),A.matches||(v||R(!1),d?.(!1))};return I(l),l.addEventListener("change",I),()=>l.removeEventListener("change",I)},[u,v,d]);let U=(0,o.useCallback)(()=>{if(p){let l=!h;v||R(l),d?.(l)}else{let l=!k;L||Q(l),a?.(l)}},[p,h,k,v,L,d,a]),P=(0,o.useCallback)(()=>{v||R(!1),d?.(!1)},[v,d]);(0,o.useEffect)(()=>{let l=F.current;l&&(p&&!h?(l.setAttribute("inert",""),l.setAttribute("aria-hidden","true")):(l.removeAttribute("inert"),l.removeAttribute("aria-hidden")))},[p,h]);let{dialogRef:X,dialogProps:Y}=(0,j.useDialogA11y)({open:p&&h,onClose:P,trapFocus:g,initialFocus:S,returnFocus:w,lockScroll:C,keepInteractive:[D]}),J={default:"bg-white dark:bg-gray-900",bordered:(0,i.cn)("bg-white dark:bg-gray-900",c==="left"?"border-r border-gray-200 dark:border-gray-700":"border-l border-gray-200 dark:border-gray-700"),floating:"bg-white dark:bg-gray-900 m-3 rounded-xl shadow-xl border border-gray-200 dark:border-gray-700"},H=k&&!p?s:n,V=(0,e.jsx)("aside",{className:(0,i.cn)("flex flex-col h-full overflow-hidden transition-[width] duration-200 ease-in-out",J[f],m),style:{width:p?n:H,minWidth:p?n:H},"data-testid":"sidebar","data-collapsed":k&&!p,"data-mobile":p,"data-position":c,children:O}),z={collapsed:k&&!p,isMobile:p,mobileOpen:h,position:c,variant:f,expandedWidth:n,collapsedWidth:s,toggle:U,closeMobile:P,closeLabel:N};return p?(0,e.jsxs)(E.Provider,{value:z,children:[h&&(0,e.jsx)("div",{ref:D,className:"fixed inset-0 z-40 bg-black/50 transition-opacity",onClick:P,"aria-hidden":"true","data-testid":"sidebar-overlay"}),(0,e.jsx)("div",{ref:l=>{F.current=l,X.current=l},...Y,"aria-label":b??G.sidebar,className:(0,i.cn)("fixed top-0 z-50 h-full transition-transform duration-200 ease-in-out focus:outline-none",c==="left"?"left-0":"right-0",h?"translate-x-0":c==="left"?"-translate-x-full":"translate-x-full"),children:V})]}):(0,e.jsx)(E.Provider,{value:z,children:V})}function le({className:t,children:r}){let a=y(),n=(0,M.useUILabels)();return(0,e.jsxs)("div",{className:(0,i.cn)("flex items-center shrink-0 px-4 h-14 overflow-hidden",a.collapsed&&"justify-center px-2",t),"data-testid":"sidebar-header",children:[r,a.isMobile&&a.mobileOpen&&(0,e.jsx)("button",{type:"button",onClick:a.closeMobile,className:"ml-auto p-1 rounded-md text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer","aria-label":a.closeLabel??n.closeSidebar,children:(0,e.jsx)(ie,{})})]})}function de({className:t,children:r}){return(0,e.jsx)("div",{className:(0,i.cn)("flex-1 overflow-y-auto overflow-x-hidden py-2",t),"data-testid":"sidebar-content",children:r})}function ce({className:t,children:r}){let a=y();return(0,e.jsx)("div",{className:(0,i.cn)("shrink-0 border-t border-gray-200 dark:border-gray-700 px-4 py-3 overflow-hidden",a.collapsed&&"px-2 flex justify-center",t),"data-testid":"sidebar-footer",children:r})}function ue({label:t,className:r,children:a}){let n=y();return(0,e.jsxs)("div",{className:(0,i.cn)("py-2",r),"data-testid":"sidebar-group",children:[t&&!n.collapsed&&(0,e.jsx)("div",{className:"px-4 py-1.5 text-[11px] font-semibold uppercase tracking-wider text-gray-500 dark:text-gray-400",children:t}),t&&n.collapsed&&(0,e.jsx)("div",{className:"mx-auto my-1 w-6 border-t border-gray-200 dark:border-gray-700"}),(0,e.jsx)("div",{className:"space-y-0.5 px-2",children:a})]})}function be({icon:t,label:r,badge:a,badgeColor:n="bg-blue-600 text-white",active:s=!1,disabled:c=!1,href:f,onClick:u,tooltip:x,className:d}){let m=y(),b=m.collapsed,N=x??r,g=(0,e.jsxs)(e.Fragment,{children:[t&&(0,e.jsx)("span",{className:(0,i.cn)("shrink-0 w-5 h-5",b&&"w-5 h-5"),children:t}),!b&&(0,e.jsxs)(e.Fragment,{children:[(0,e.jsx)("span",{className:"flex-1 truncate",children:r}),a!=null&&(0,e.jsx)("span",{className:(0,i.cn)("shrink-0 inline-flex items-center justify-center rounded-full text-[10px] font-semibold min-w-[18px] h-[18px] px-1",n),children:a})]}),b&&a!==void 0&&a!==null&&(0,e.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 rounded-full bg-blue-600"})]}),S=(0,i.cn)("relative flex items-center gap-3 rounded-md text-sm font-medium transition-colors w-full",b?"justify-center px-2 py-2.5":"px-3 py-2",s?"bg-blue-50 text-blue-700 dark:bg-blue-900/30 dark:text-blue-400":"text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800",c&&"opacity-50 pointer-events-none",!c&&"cursor-pointer",d),w=()=>{c||(u?.(),m.isMobile&&m.closeMobile())},C=f?(0,e.jsx)("a",{href:c?void 0:f,className:S,onClick:w,"aria-current":s?"page":void 0,"data-testid":"sidebar-item",children:g}):(0,e.jsx)("button",{type:"button",className:S,onClick:w,disabled:c,"aria-current":s?"page":void 0,"data-testid":"sidebar-item",children:g});return b?(0,e.jsx)(B,{text:N,position:m.position,children:C}):C}function pe({icon:t,label:r,badge:a,defaultOpen:n=!1,className:s,children:c}){let f=y(),[u,x]=(0,o.useState)(n),d=(0,o.useRef)(null),[m,b]=(0,o.useState)(n?void 0:0),N=(0,o.useRef)(!0);return(0,o.useEffect)(()=>{if(N.current){N.current=!1,b(u?void 0:0);return}if(u){let g=d.current;if(g){b(g.scrollHeight);let S=setTimeout(()=>b(void 0),200);return()=>clearTimeout(S)}}else{let g=d.current;g&&(b(g.scrollHeight),requestAnimationFrame(()=>b(0)))}},[u]),f.collapsed?(0,e.jsx)(B,{text:r,position:f.position,children:(0,e.jsxs)("button",{type:"button",className:(0,i.cn)("relative flex items-center justify-center gap-3 rounded-md text-sm font-medium transition-colors w-full px-2 py-2.5","text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer",s),onClick:()=>{f.toggle(),x(!0)},"data-testid":"sidebar-submenu-trigger",children:[t&&(0,e.jsx)("span",{className:"shrink-0 w-5 h-5",children:t}),a!=null&&(0,e.jsx)("span",{className:"absolute top-1 right-1 w-2 h-2 rounded-full bg-blue-600"})]})}):(0,e.jsxs)("div",{className:s,"data-testid":"sidebar-submenu",children:[(0,e.jsxs)("button",{type:"button",className:(0,i.cn)("flex items-center gap-3 rounded-md text-sm font-medium transition-colors w-full px-3 py-2","text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 cursor-pointer"),onClick:()=>x(!u),"aria-expanded":u,"data-testid":"sidebar-submenu-trigger",children:[t&&(0,e.jsx)("span",{className:"shrink-0 w-5 h-5",children:t}),(0,e.jsx)("span",{className:"flex-1 truncate text-left",children:r}),a!=null&&(0,e.jsx)("span",{className:"shrink-0 inline-flex items-center justify-center rounded-full text-[10px] font-semibold min-w-[18px] h-[18px] px-1 bg-blue-600 text-white",children:a}),(0,e.jsx)(ne,{className:(0,i.cn)("shrink-0 text-gray-500 dark:text-gray-400 transition-transform duration-200",u&&"rotate-180")})]}),(0,e.jsx)("div",{className:"overflow-hidden transition-[height] duration-200 ease-in-out",style:{height:m===void 0?"auto":m},children:(0,e.jsx)("div",{ref:d,className:"pl-4 py-0.5",children:c})})]})}function fe({className:t}){let r=y(),a=(0,M.useUILabels)(),n=r.isMobile?r.mobileOpen?r.closeLabel??a.closeSidebar:a.openSidebar:r.collapsed?a.expandSidebar:a.collapseSidebar;return(0,e.jsx)("button",{type:"button",onClick:r.toggle,className:(0,i.cn)("p-1.5 rounded-md text-gray-500 dark:text-gray-400 hover:text-gray-600 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors cursor-pointer",t),"aria-label":n,"data-testid":"sidebar-toggle",children:(0,e.jsx)(oe,{className:(0,i.cn)("transition-transform duration-200",r.collapsed&&"rotate-180",r.position==="right"&&!r.collapsed&&"rotate-180",r.position==="right"&&r.collapsed&&"rotate-0")})})}0&&(module.exports={Sidebar,SidebarContent,SidebarFooter,SidebarGroup,SidebarHeader,SidebarItem,SidebarSubMenu,SidebarToggle,useSidebar});
|