@notmrabhi/flowforge 0.1.11 → 0.1.12
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/{SchemaBuilderDrawer-Dm-_FFUn.js → SchemaBuilderDrawer-D14R1O1M.js} +1 -1
- package/dist/{SchemaBuilderDrawer-C2k4UQS8.js → SchemaBuilderDrawer-jbSe-O-O.js} +1 -1
- package/dist/canvas.cjs +1 -1
- package/dist/canvas.js +1 -1
- package/dist/form.cjs +1 -1
- package/dist/form.js +2 -2
- package/dist/{index-JLjbUe8S.js → index-BWAxupnf.js} +1 -1
- package/dist/{index-Eu7S28uq.js → index-C0Eu9PxA.js} +1 -1
- package/dist/{index-Gi4oFtA2.js → index-CxVqPygT.js} +422 -414
- package/dist/{index-DMphMrWA.js → index-DLSkW4rA.js} +1 -1
- package/dist/{index-z2pFjqNP.js → index-DNZlQp9z.js} +5 -5
- package/dist/{index-CHXtMyzN.js → index-DZOcYc5S.js} +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +3 -3
- package/dist/{templateSkeletons-DVVgtP0t.js → templateSkeletons-BEaJiDBN.js} +1 -1
- package/dist/{templateSkeletons-DDSeKvNP.js → templateSkeletons-Dks6kUHW.js} +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useMemo as P, useState as T, useRef as M, useEffect as de, useCallback as te } from "react";
|
|
2
2
|
import { useFormik as ke } from "formik";
|
|
3
|
-
import { k as pe, C as Ne, g as oe, a as ue, b as ie, v as se, E as ze, d as Te, V as we } from "./index-
|
|
3
|
+
import { k as pe, C as Ne, g as oe, a as ue, b as ie, v as se, E as ze, d as Te, V as we } from "./index-CxVqPygT.js";
|
|
4
4
|
import { jsxs as t, Fragment as q, jsx as e } from "react/jsx-runtime";
|
|
5
5
|
import { Box as n, Collapse as Ie, Tooltip as A, Dialog as he, Typography as S, IconButton as Y, Stepper as Fe, Step as Oe, StepLabel as Re, Drawer as Ee, Chip as We, Divider as Ae } from "@mui/material";
|
|
6
6
|
import { MdCheck as G, MdClose as _, MdAdd as J, MdArrowBack as fe, MdEdit as De, MdDeleteOutline as Pe, MdSettings as be, MdArrowForward as Me } from "react-icons/md";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const h=require("react"),re=require("formik"),N=require("./index-z2pFjqNP.js"),e=require("react/jsx-runtime"),o=require("@mui/material"),S=require("react-icons/md"),ie=require("react-icons/fa6");function ae({schema:l,initialValues:s,onSubmit:d,showErrorsImmediately:a=!1}){const r=l.fields??[],t=h.useMemo(()=>N.buildValidationSchema(r),[r]),p=h.useMemo(()=>{if(a)return r.reduce((u,v)=>{const g=N.resolveFieldKey(v);return g&&(u[g]=!0),u},{})},[r,a]),[i,c]=h.useState({}),[m,y]=h.useState({}),B=h.useRef(s);h.useEffect(()=>{B.current!==s&&(B.current=s,c({}),y({}))},[s]);const x=re.useFormik({initialValues:s,validationSchema:t,initialTouched:p,validateOnMount:a,validateOnChange:!0,validateOnBlur:!0,enableReinitialize:!0,onSubmit:async u=>{const v=N.buildEvaluationPayload({values:u,conditionConfig:m});await d(u,v)}}),n=h.useCallback(()=>{x.submitForm()},[x]),f=h.useCallback(u=>{x.resetForm(u?{values:u}:void 0),c({}),y({})},[x]);return{values:x.values,errors:x.errors,isValid:x.isValid,isDirty:x.dirty,isSubmitting:x.isSubmitting,formulaConfig:i,conditionConfig:m,submit:n,reset:f,setFieldValue:x.setFieldValue,_schema:l,_formik:x,_formulaConfig:i,_onFormulaConfigChange:c,_conditionConfig:m,_onConditionConfigChange:y}}const Z=N.FlowForgeRegistry.getTypeOptions(),j="form-control font-14",b="text-14 text-dark fw-medium mb-1 align-items-center d-flex gap-1",F={fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:.6,marginBottom:8,display:"block"},ce=[{value:"text",label:"Text"},{value:"number",label:"Number"},{value:"email",label:"Email"},{value:"url",label:"URL"},{value:"password",label:"Password"},{value:"select",label:"Select"},{value:"object",label:"Object (sub-fields)"},{value:"array",label:"Array (nested)"}],de=[{value:3,label:"1/4"},{value:4,label:"1/3"},{value:6,label:"1/2"},{value:8,label:"2/3"},{value:12,label:"Full"}];function xe({value:l,onChange:s}){const d=l??12;return e.jsxs(o.Box,{children:[e.jsx("span",{className:b,children:"Column width"}),e.jsx(o.Box,{sx:{display:"flex",gap:.5},children:de.map(a=>e.jsx(o.Tooltip,{title:`colSpan: ${a.value}`,placement:"top",children:e.jsx(o.Box,{component:"button",onClick:()=>s(a.value),sx:{flex:1,border:"1px solid",borderColor:d===a.value?"#6366f1":"#dee2e6",borderRadius:"6px",cursor:"pointer",bgcolor:d===a.value?"#eef2ff":"#fff",color:d===a.value?"#6366f1":"#6c757d",fontSize:11,fontWeight:600,py:.6,px:0,"&:hover":{borderColor:"#6366f1",bgcolor:"#f5f3ff"}},children:a.label})},a.value))}),e.jsx(o.Box,{sx:{display:"flex",gap:"3px",mt:.75},children:Array.from({length:12}).map((a,r)=>e.jsx(o.Box,{sx:{flex:1,height:4,borderRadius:"2px",bgcolor:r<d?"#6366f1":"#e2e8f0",transition:"background 0.12s"}},r))})]})}function Q({options:l=[],onChange:s}){function d(a,r,t){s(l.map((p,i)=>i===a?{...p,[r]:t}:p))}return e.jsxs(o.Box,{children:[e.jsxs("span",{className:b,children:["Options ",e.jsx("span",{style:{color:"#dc3545"},children:"*"})]}),e.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:.5,mb:.75},children:l.map((a,r)=>e.jsxs(o.Box,{sx:{display:"flex",gap:.5,alignItems:"center"},children:[e.jsx("input",{className:j,style:{flex:1},placeholder:"Label",value:a.label,onChange:t=>d(r,"label",t.target.value)}),e.jsx("input",{className:j,style:{flex:1},placeholder:"Value",value:a.value,onChange:t=>d(r,"value",t.target.value)}),e.jsx(o.Box,{component:"button",onClick:()=>s(l.filter((t,p)=>p!==r)),sx:{background:"none",border:"none",cursor:"pointer",color:"#94a3b8",display:"flex",p:.25,"&:hover":{color:"#dc2626"}},children:e.jsx(S.MdClose,{size:13})})]},r))}),e.jsxs(o.Box,{component:"button",onClick:()=>s([...l,{label:"",value:""}]),sx:{display:"flex",alignItems:"center",gap:.5,background:"none",border:"1px dashed #dee2e6",cursor:"pointer",fontSize:11,fontWeight:600,px:1,py:.5,borderRadius:"6px",color:"#6366f1",width:"100%","&:hover":{borderColor:"#6366f1",bgcolor:"#f5f3ff"}},children:[e.jsx(S.MdAdd,{size:13})," Add option"]})]})}const ee=[{value:"operator",label:"Operator (predefined)"},{value:"select",label:"Select"},{value:"text",label:"Text"}];function pe({col:l,onChange:s,onDelete:d}){const a=l.type==="select",r=l.type==="operator";return e.jsxs(o.Box,{sx:{border:"1px solid #e2e8f0",borderRadius:"7px",p:1.25,bgcolor:"#fff",display:"flex",flexDirection:"column",gap:1},children:[e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(o.Box,{sx:{fontSize:10,fontWeight:700,px:.75,py:.2,borderRadius:"4px",bgcolor:r?"#fef9c3":"#eef2ff",color:r?"#92400e":"#6366f1",flexShrink:0},children:r?"OPERATOR":l.type.toUpperCase()}),e.jsx(o.Box,{sx:{fontSize:12,fontWeight:600,color:"#0f172a",flex:1},children:l.label||l.id||"Unnamed"}),e.jsx(o.Box,{component:"button",onClick:d,sx:{background:"none",border:"none",cursor:"pointer",color:"#94a3b8",display:"flex",p:.25,"&:hover":{color:"#dc2626"}},children:e.jsx(S.MdClose,{size:13})})]}),e.jsxs(o.Box,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:1},children:[e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Column type"}),e.jsx("select",{value:l.type,onChange:t=>s({...l,type:t.target.value,options:void 0}),className:j,style:{cursor:"pointer"},children:ee.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))})]}),e.jsxs(o.Box,{children:[e.jsxs("label",{className:b,children:["Column key ",e.jsx("span",{style:{color:"#dc3545"},children:"*"})]}),e.jsx("input",{className:`${j} ${l.id?"":"border-danger"}`,value:l.id,onChange:t=>s({...l,id:t.target.value}),placeholder:"e.g. field, operator, value"}),!l.id&&e.jsx("span",{style:{fontSize:10,color:"#dc3545"},children:"Required — used as data key"})]})]}),!r&&e.jsxs(o.Box,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:1},children:[e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Label"}),e.jsx("input",{className:j,value:l.label??"",onChange:t=>s({...l,label:t.target.value||void 0}),placeholder:"Column label"})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Placeholder"}),e.jsx("input",{className:j,value:l.placeholder??"",onChange:t=>s({...l,placeholder:t.target.value||void 0}),placeholder:"Hint…"})]})]}),a&&e.jsx(Q,{options:l.options??[],onChange:t=>s({...l,options:t})}),r&&e.jsx(o.Box,{sx:{bgcolor:"#fefce8",border:"1px solid #fef08a",borderRadius:"6px",px:1.25,py:.75},children:e.jsx(o.Box,{sx:{fontSize:11,color:"#78350f"},children:"Predefined: equals, not equals, contains, starts with, ends with, is present, is not present, greater than, less than…"})}),!r&&e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx("input",{type:"checkbox",id:`formula-${l.id}`,checked:!!l.formula,onChange:t=>s({...l,formula:t.target.checked||void 0}),style:{cursor:"pointer",width:14,height:14}}),e.jsx("label",{htmlFor:`formula-${l.id}`,className:b,style:{margin:0,cursor:"pointer"},children:"Formula input (chip editor)"})]})]})}function ue({condition:l,onChange:s}){const d=!!l;function a(){s(d?void 0:{fields:[]})}function r(i){if(!l)return;const c=i==="operator"?"operator":l.fields.filter(m=>m.type!=="operator").length===0?"field":"value";s({...l,fields:[...l.fields,{id:c,type:i}]})}function t(i,c){if(!l)return;const m=[...l.fields];m[i]=c,s({...l,fields:m})}function p(i){l&&s({...l,fields:l.fields.filter((c,m)=>m!==i)})}return e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",pt:1.5},children:[e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:d?1.25:0},children:[e.jsx("input",{type:"checkbox",id:"enable-condition",checked:d,onChange:a,style:{cursor:"pointer",width:14,height:14}}),e.jsx("span",{style:{...F,margin:0,color:d?"#6366f1":"#94a3b8"},children:"Condition row"})]}),d&&l&&e.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[l.fields.map((i,c)=>e.jsx(pe,{col:i,onChange:m=>t(c,m),onDelete:()=>p(c)},c)),e.jsx(o.Box,{sx:{display:"flex",gap:.5},children:ee.map(i=>e.jsxs(o.Box,{component:"button",onClick:()=>r(i.value),sx:{flex:1,background:"none",border:"1px dashed #dee2e6",cursor:"pointer",fontSize:11,fontWeight:600,py:.5,borderRadius:"6px",color:i.value==="operator"?"#92400e":"#6366f1","&:hover":{borderColor:"#6366f1",bgcolor:"#f5f3ff"}},children:["+ ",i.value==="operator"?"Operator":i.label.split(" ")[0]]},i.value))}),e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:2,flexWrap:"wrap"},children:[e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx("input",{type:"checkbox",id:"allow-groups",checked:!!l.allowGroups,onChange:i=>s({...l,allowGroups:i.target.checked||void 0}),style:{cursor:"pointer",width:14,height:14}}),e.jsx("label",{htmlFor:"allow-groups",className:b,style:{margin:0,cursor:"pointer"},children:"Allow nested groups"})]}),l.allowGroups&&e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx("label",{className:b,style:{margin:0},children:"Max depth"}),e.jsx("input",{type:"number",min:1,max:5,className:j,style:{width:60,textAlign:"center"},value:l.maxGroupDepth??"",onChange:i=>s({...l,maxGroupDepth:i.target.value?Number(i.target.value):void 0}),placeholder:"∞"})]})]})]})]})}function E({id:l,label:s,checked:d,onChange:a}){return e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx("input",{type:"checkbox",id:l,checked:d,onChange:r=>a(r.target.checked),style:{cursor:"pointer",width:14,height:14,flexShrink:0}}),e.jsx("label",{htmlFor:l,className:b,style:{margin:0,cursor:"pointer"},children:s})]})}function he({views:l=[],onChange:s}){function d(r,t,p){s(l.map((i,c)=>c===r?{...i,[t]:p}:i))}function a(){const r=`tab${l.length+1}`;s([...l,{id:r,label:`Tab ${l.length+1}`}])}return e.jsxs(o.Box,{children:[e.jsx("span",{className:b,children:"Views"}),e.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:.5,mb:.75},children:l.map((r,t)=>e.jsxs(o.Box,{sx:{display:"flex",gap:.5,alignItems:"center"},children:[e.jsx("input",{className:j,style:{flex:1},placeholder:"Label",value:r.label,onChange:p=>d(t,"label",p.target.value)}),e.jsx("input",{className:j,style:{flex:1},placeholder:"ID (no spaces)",value:r.id,onChange:p=>d(t,"id",p.target.value.replace(/\s/g,"_"))}),e.jsx(o.Box,{component:"button",onClick:()=>s(l.filter((p,i)=>i!==t)),sx:{background:"none",border:"none",cursor:"pointer",color:"#94a3b8",display:"flex",p:.25,"&:hover":{color:"#dc2626"}},children:e.jsx(S.MdClose,{size:13})})]},t))}),e.jsxs(o.Box,{component:"button",onClick:a,sx:{display:"flex",alignItems:"center",gap:.5,background:"none",border:"1px dashed #dee2e6",cursor:"pointer",fontSize:11,fontWeight:600,px:1,py:.5,borderRadius:"6px",color:"#6366f1",width:"100%","&:hover":{borderColor:"#6366f1",bgcolor:"#f5f3ff"}},children:[e.jsx(S.MdAdd,{size:13})," Add view"]})]})}function _({label:l,value:s,options:d,onChange:a}){return e.jsxs(o.Box,{children:[e.jsx("span",{className:b,children:l}),e.jsx(o.Box,{sx:{display:"flex",border:"1px solid #dee2e6",borderRadius:"7px",overflow:"hidden"},children:d.map(r=>e.jsx(o.Box,{component:"button",onClick:()=>a(r.value),sx:{flex:1,border:"none",borderRight:"1px solid #dee2e6",cursor:"pointer",fontSize:12,fontWeight:600,py:.6,bgcolor:s===r.value?"#eef2ff":"#fff",color:s===r.value?"#6366f1":"#6c757d","&:last-child":{borderRight:"none"},"&:hover":{bgcolor:"#f5f3ff"}},children:r.label},r.value))})]})}function le({field:l,onChange:s,onSave:d,onCancel:a,noFooter:r}){const[t,p]=h.useState(!1),i=l.id??l.name??"",c=l,m=l.type==="select"||l.type==="descriptive-select"||l.type==="radio-group",y=N.FlowForgeRegistry.get(l.type),B=y==null?void 0:y.configSchema;function x(n,f){s({...l,[n]:f})}return e.jsxs(e.Fragment,{children:[e.jsxs(o.Box,{sx:{flex:1,overflowY:"auto",px:2.5,py:2,display:"flex",flexDirection:"column",gap:1.75},children:[e.jsxs(o.Box,{children:[e.jsx("span",{style:F,children:"Required"}),e.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Type"}),e.jsx("select",{value:l.type,onChange:n=>x("type",n.target.value),className:j,style:{cursor:"pointer"},children:Z.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))})]}),e.jsxs(o.Box,{sx:{display:"grid",gridTemplateColumns:l.type==="tabs"?"1fr":"1fr 1fr",gap:1},children:[e.jsxs(o.Box,{children:[e.jsxs("label",{className:b,children:["Field ID ",e.jsx("span",{style:{color:"#dc3545"},children:"*"})]}),e.jsx("input",{className:j,value:l.id??l.name??"",onChange:n=>x("id",n.target.value),placeholder:"e.g. email"})]}),l.type!=="tabs"&&e.jsxs(o.Box,{children:[e.jsxs("label",{className:b,children:["Label ",e.jsx("span",{style:{color:"#dc3545"},children:"*"})]}),e.jsx("input",{className:j,value:l.label??"",onChange:n=>x("label",n.target.value),placeholder:"Display label"})]})]}),l.type!=="tabs"&&e.jsx(xe,{value:l.colSpan,onChange:n=>x("colSpan",n===12?void 0:n)})]})]}),B&&e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",pt:1.5},children:[e.jsx("span",{style:F,children:"Specific Settings"}),e.jsx(N.FlowForm,{schema:{layout:"flat",compact:!0,fields:B.fields},initialValues:l,onValuesChange:n=>s({...l,...n}),onSubmit:()=>{}})]}),l.type==="tabs"&&e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",pt:1.5,display:"flex",flexDirection:"column",gap:1.5},children:[e.jsx("span",{style:F,children:"Content"}),e.jsx(he,{views:(c.tabs??[]).map(n=>({id:n.id,label:n.label})),onChange:n=>{const f=c.tabs??[],u=n.map(v=>{const g=f.find(w=>w.id===v.id);return g?{...g,...v}:{...v,fields:[]}});s({...l,tabs:u})}}),e.jsx("span",{style:{...F,marginTop:4},children:"Interaction"}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Disabled"}),e.jsx("input",{className:j,value:c.disabledExpr??"",onChange:n=>s({...l,disabledExpr:n.target.value||void 0}),placeholder:"false"})]}),e.jsx("span",{style:{...F,marginTop:4},children:"Appearance"}),e.jsx(_,{label:"Alignment",value:c.alignment??"left",options:[{value:"left",label:"|←"},{value:"center-left",label:"←|"},{value:"center",label:"|·|"},{value:"center-right",label:"|→"},{value:"right",label:"→|"}],onChange:n=>s({...l,alignment:n})}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Hidden"}),e.jsx("input",{className:j,value:c.hiddenExpr??"",onChange:n=>s({...l,hiddenExpr:n.target.value||void 0}),placeholder:"false"})]}),e.jsx(_,{label:"Variant",value:c.variant??"line",options:[{value:"pill",label:"Pill"},{value:"line",label:"Line"}],onChange:n=>s({...l,variant:n})}),e.jsxs(o.Box,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:1},children:[e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Active color"}),e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx("input",{type:"color",value:c.activeColor??"#6366f1",onChange:n=>s({...l,activeColor:n.target.value}),style:{width:28,height:28,border:"1px solid #dee2e6",borderRadius:6,cursor:"pointer",padding:2,background:"#fff"}}),e.jsx("input",{className:j,value:c.activeColor??"",onChange:n=>s({...l,activeColor:n.target.value||void 0}),placeholder:"#6366f1",style:{flex:1}})]})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Active text"}),e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx("input",{type:"color",value:c.activeTextColor??"#ffffff",onChange:n=>s({...l,activeTextColor:n.target.value}),style:{width:28,height:28,border:"1px solid #dee2e6",borderRadius:6,cursor:"pointer",padding:2,background:"#fff"}}),e.jsx("input",{className:j,value:c.activeTextColor??"",onChange:n=>s({...l,activeTextColor:n.target.value||void 0}),placeholder:"auto",style:{flex:1}})]})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Inactive text"}),e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx("input",{type:"color",value:c.inactiveTextColor??"#64748b",onChange:n=>s({...l,inactiveTextColor:n.target.value}),style:{width:28,height:28,border:"1px solid #dee2e6",borderRadius:6,cursor:"pointer",padding:2,background:"#fff"}}),e.jsx("input",{className:j,value:c.inactiveTextColor??"",onChange:n=>s({...l,inactiveTextColor:n.target.value||void 0}),placeholder:"#64748b",style:{flex:1}})]})]})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Styles"}),e.jsx("input",{className:j,value:c.styles??"",onChange:n=>s({...l,styles:n.target.value||void 0}),placeholder:"None"})]}),e.jsx("span",{style:{...F,marginTop:4},children:"Spacing"}),e.jsx(_,{label:"Height",value:c.height??"auto",options:[{value:"auto",label:"Auto"},{value:"fixed",label:"Fixed"}],onChange:n=>s({...l,height:n})}),e.jsx(_,{label:"Margin",value:c.margin??"normal",options:[{value:"normal",label:"Normal"},{value:"none",label:"None"}],onChange:n=>s({...l,margin:n})})]}),m&&e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",pt:1.5},children:[e.jsx("span",{style:F,children:"Options"}),e.jsx(Q,{options:c.options??[],onChange:n=>s({...l,options:n})})]}),l.type==="array"&&e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",pt:1.5,display:"flex",flexDirection:"column",gap:1},children:[e.jsx("span",{style:F,children:"Array settings"}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Item type"}),e.jsx("select",{className:j,style:{cursor:"pointer"},value:c.itemType??"text",onChange:n=>s({...l,itemType:n.target.value}),children:ce.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))})]}),e.jsxs(o.Box,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:1},children:[e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Item label"}),e.jsx("input",{className:j,value:c.itemLabel??"",onChange:n=>s({...l,itemLabel:n.target.value||void 0}),placeholder:'e.g. "Member"'})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Add button label"}),e.jsx("input",{className:j,value:c.addLabel??"",onChange:n=>s({...l,addLabel:n.target.value||void 0}),placeholder:"Add item"})]})]}),e.jsxs(o.Box,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:1},children:[e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Min items"}),e.jsx("input",{type:"number",min:0,className:j,value:c.minItems??"",onChange:n=>s({...l,minItems:n.target.value?Number(n.target.value):void 0}),placeholder:"0"})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Max items"}),e.jsx("input",{type:"number",min:1,className:j,value:c.maxItems??"",onChange:n=>s({...l,maxItems:n.target.value?Number(n.target.value):void 0}),placeholder:"∞"})]})]}),!["object","array","select"].includes(c.itemType??"text")&&e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Item placeholder"}),e.jsx("input",{className:j,value:c.itemPlaceholder??"",onChange:n=>s({...l,itemPlaceholder:n.target.value||void 0}),placeholder:"Enter value…"})]})]}),e.jsx(ue,{condition:l.condition,onChange:n=>s({...l,condition:n})}),e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",pt:1.5},children:[e.jsx(o.Box,{component:"button",onClick:()=>p(n=>!n),sx:{background:"none",border:"none",cursor:"pointer",display:"flex",alignItems:"center",gap:.5,p:0,mb:t?1.25:0},children:e.jsxs("span",{style:{...F,margin:0,color:t?"#6366f1":"#94a3b8"},children:[t?"▾":"▸"," Optional settings"]})}),e.jsx(o.Collapse,{in:t,children:e.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:[e.jsxs(o.Box,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:1},children:[e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Placeholder"}),e.jsx("input",{className:j,value:l.placeholder??"",onChange:n=>x("placeholder",n.target.value||void 0),placeholder:"Hint text…"})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Helper text"}),e.jsx("input",{className:j,value:l.helperText??"",onChange:n=>x("helperText",n.target.value||void 0),placeholder:"Description…"})]})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Info tooltip"}),e.jsx("input",{className:j,value:l.info??"",onChange:n=>x("info",n.target.value||void 0),placeholder:"Shown in ℹ tooltip"})]}),e.jsxs(o.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1.5},children:[e.jsx(E,{id:`${i}-req`,label:"Required",checked:!!l.required,onChange:n=>x("required",n||void 0)}),e.jsx(E,{id:`${i}-dis`,label:"Disabled",checked:!!l.disabled,onChange:n=>x("disabled",n||void 0)}),e.jsx(E,{id:`${i}-hid`,label:"Hidden",checked:!!l.hidden,onChange:n=>x("hidden",n||void 0)}),e.jsx(E,{id:`${i}-opt`,label:"Show optional",checked:!!l.showOptional,onChange:n=>x("showOptional",n||void 0)}),e.jsx(E,{id:`${i}-div`,label:"Divider after",checked:!!l.dividerAfter,onChange:n=>x("dividerAfter",n||void 0)}),e.jsx(E,{id:`${i}-frm`,label:"Formula input",checked:!!l.formula,onChange:n=>x("formula",n||void 0)})]})]})})]})]}),!r&&e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",px:2.5,py:1.5,display:"flex",gap:1,justifyContent:"flex-end",bgcolor:"#f8fafc",flexShrink:0},children:[e.jsx(o.Box,{component:"button",onClick:a,sx:{background:"none",border:"1px solid #dee2e6",cursor:"pointer",fontSize:13,fontWeight:500,px:2,py:.75,borderRadius:"7px",color:"#6c757d","&:hover":{bgcolor:"#f8f9fa"}},children:"Cancel"}),e.jsxs(o.Box,{component:"button",onClick:d,sx:{border:"none",cursor:"pointer",fontSize:13,fontWeight:600,px:2.5,py:.75,borderRadius:"7px",bgcolor:"#6366f1",color:"#fff",display:"flex",alignItems:"center",gap:.75,"&:hover":{bgcolor:"#4f46e5"}},children:[e.jsx(S.MdCheck,{size:15})," Save"]})]})]})}const L={text:"#0f172a",textMuted:"#64748b",borderInput:"rgba(0,0,0,0.23)",bg:"#ffffff"},fe={md:"6px"},oe={sm:11,md:13},G={width:"100%",fontSize:oe.md,fontFamily:"inherit",padding:"8px 12px",border:`1px solid ${L.borderInput}`,borderRadius:fe.md,outline:"none",background:L.bg,color:L.text,boxSizing:"border-box",transition:"border-color 0.15s, box-shadow 0.15s"};function X(){return{type:"text",id:"",label:"",colSpan:12}}function be(l){return l.type==="object"||l.type==="array"||l.type==="schema"}function me(l){if(l.type==="object")return"Child Fields";if(l.type==="schema")return"Schema Fields";const s=l.itemType??"text";return s==="object"?"Item Fields":s==="select"?"Item Options":"Item Config"}function ge({field:l,onChange:s}){var r;const d=l,a=d.itemType??"text";if(l.type==="object")return e.jsxs(o.Box,{sx:{p:2.5},children:[e.jsx(o.Typography,{sx:{fontSize:12,color:"#64748b",mb:2},children:"Define the fields nested inside this object. Each child field can itself be an object or array."}),e.jsx(W,{value:l.children??[],onChange:t=>s({...l,children:t}),label:"Child fields"})]});if(l.type==="schema")return e.jsxs(o.Box,{sx:{p:2.5},children:[e.jsx(o.Typography,{sx:{fontSize:12,color:"#64748b",mb:2},children:"Define the fields inside this schema. When the form is filled, their values are collected into a single object as this field's value."}),e.jsx(W,{value:l.children??[],onChange:t=>s({...l,children:t}),label:"Schema fields"})]});if(l.type==="array"){if(a==="object")return e.jsxs(o.Box,{sx:{p:2.5},children:[e.jsx(o.Typography,{sx:{fontSize:12,color:"#64748b",mb:2},children:"Define the fields for each item in the array. Each item will be an object with these fields."}),e.jsx(W,{value:d.itemFields??[],onChange:t=>s({...l,itemFields:t}),label:"Item fields"})]});if(a==="select"){const t=d.itemOptions??[];return e.jsxs(o.Box,{sx:{p:2.5},children:[e.jsx(o.Typography,{sx:{fontSize:12,color:"#64748b",mb:2},children:"Options available in each select item."}),e.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:.5,mb:.75},children:t.map((p,i)=>e.jsxs(o.Box,{sx:{display:"flex",gap:.5,alignItems:"center"},children:[e.jsx("input",{style:{...G,flex:1,padding:"6px 10px"},placeholder:"Label",value:p.label,onChange:c=>{const m=t.map((y,B)=>B===i?{...y,label:c.target.value}:y);s({...l,itemOptions:m})}}),e.jsx("input",{style:{...G,flex:1,padding:"6px 10px"},placeholder:"Value",value:p.value,onChange:c=>{const m=t.map((y,B)=>B===i?{...y,value:c.target.value}:y);s({...l,itemOptions:m})}}),e.jsx(o.Box,{component:"button",onClick:()=>s({...l,itemOptions:t.filter((c,m)=>m!==i)}),sx:{background:"none",border:"none",cursor:"pointer",color:"#94a3b8",display:"flex",p:.25,"&:hover":{color:"#dc2626"}},children:"✕"})]},i))}),e.jsx(o.Box,{component:"button",onClick:()=>s({...l,itemOptions:[...t,{label:"",value:""}]}),sx:{display:"flex",alignItems:"center",gap:.5,background:"none",border:"1px dashed #dee2e6",cursor:"pointer",fontSize:11,fontWeight:600,px:1,py:.5,borderRadius:"6px",color:"#6366f1",width:"100%",justifyContent:"center","&:hover":{borderColor:"#6366f1",bgcolor:"#f5f3ff"}},children:"+ Add option"})]})}if(a==="array"){const t=((r=d.itemSchema)==null?void 0:r.itemType)??"text",p=[{value:"text",label:"Text"},{value:"number",label:"Number"},{value:"email",label:"Email"},{value:"url",label:"URL"},{value:"password",label:"Password"},{value:"select",label:"Select"},{value:"object",label:"Object"}];return e.jsxs(o.Box,{sx:{p:2.5},children:[e.jsx(o.Typography,{sx:{fontSize:12,color:"#64748b",mb:2},children:"Each item is itself an array. Configure the type of items inside the nested array."}),e.jsx("label",{style:{fontSize:oe.sm,fontWeight:600,color:L.textMuted,display:"block",marginBottom:3},children:"Nested item type"}),e.jsx("select",{style:{...G,padding:"6px 10px",cursor:"pointer"},value:t,onChange:i=>s({...l,itemSchema:{...d.itemSchema??{},itemType:i.target.value}}),children:p.map(i=>e.jsx("option",{value:i.value,children:i.label},i.value))})]})}return e.jsx(o.Box,{sx:{p:2.5},children:e.jsxs(o.Box,{sx:{border:"1.5px dashed #e2e8f0",borderRadius:"8px",py:3,textAlign:"center"},children:[e.jsxs(o.Typography,{sx:{fontSize:13,color:"#94a3b8"},children:["No extra configuration needed for ",e.jsx("strong",{children:a})," items."]}),e.jsx(o.Typography,{sx:{fontSize:11,color:"#cbd5e1",mt:.5},children:"Item placeholder and labels are set in the previous step."})]})})}return null}function je({field:l}){var p;const[s,d]=h.useState({}),a=l.id??l.name??"preview",r=[{value:3,label:"1/4"},{value:4,label:"1/3"},{value:6,label:"1/2"},{value:8,label:"2/3"},{value:12,label:"Full"}],t=l.colSpan&&l.colSpan<12?((p=r.find(i=>i.value===l.colSpan))==null?void 0:p.label)??l.colSpan:"Full";return e.jsxs(o.Box,{sx:{p:2.5},children:[e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",mb:2,px:1.25,py:.75,bgcolor:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:"7px"},children:[e.jsx(o.Typography,{sx:{fontSize:11,color:"#15803d",fontWeight:500,flex:1},children:"Live preview — interact to test the field"}),e.jsxs(o.Typography,{sx:{fontSize:11,color:"#64748b"},children:["Width: ",t]})]}),e.jsx(N.FlowForm,{schema:{layout:"flat",fields:[l]},initialValues:{[a]:l.type==="array"?[]:l.type==="object"||l.type==="schema"?{}:""},onSubmit:()=>{},conditionConfig:s,onConditionConfigChange:d})]})}function J({open:l,initial:s,onSave:d,onClose:a,editMode:r=!1}){const[t,p]=h.useState(1),[i,c]=h.useState(()=>s??X());function m(){c(s??X()),p(1)}const y=be(i),B=y?3:2,x=y?["Configure",me(i),"Preview"]:["Configure","Preview"],n=!!(i.id||i.name)&&!!i.type;function f(){p(k=>Math.min(k+1,B))}function u(){p(k=>Math.max(k-1,1))}function v(){d(i),a()}const g=t-1,w=t===B,T=y&&t===3||!y&&t===2;return e.jsxs(o.Dialog,{open:l,onClose:a,TransitionProps:{onEnter:m},maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",overflow:"hidden",display:"flex",flexDirection:"column",maxHeight:"90vh"}},children:[e.jsxs(o.Box,{sx:{px:2.5,pt:1.75,pb:0,borderBottom:"1px solid #e2e8f0",flexShrink:0},children:[e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(o.Typography,{sx:{fontSize:14,fontWeight:700,color:"#0f172a",flex:1},children:r?"Edit Field":"Add Field"}),e.jsx(o.IconButton,{size:"small",onClick:a,sx:{color:"#94a3b8"},children:e.jsx(S.MdClose,{size:17})})]}),e.jsx(o.Stepper,{activeStep:g,sx:{pb:1.5},children:x.map((k,R)=>e.jsx(o.Step,{completed:g>R,children:e.jsx(o.StepLabel,{children:k})},k))})]}),e.jsxs(o.Box,{sx:{flex:1,overflowY:"auto"},children:[t===1&&e.jsx(le,{field:i,onChange:c,onSave:f,onCancel:a,noFooter:!0}),t===2&&y&&e.jsx(ge,{field:i,onChange:c}),T&&e.jsx(je,{field:i})]}),e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",px:2.5,py:1.5,display:"flex",alignItems:"center",gap:1,flexShrink:0,bgcolor:"#f8fafc"},children:[t>1&&e.jsxs(o.Box,{component:"button",onClick:u,sx:{display:"flex",alignItems:"center",gap:.5,background:"none",border:"none",cursor:"pointer",fontSize:13,fontWeight:500,color:"#6c757d",px:0,"&:hover":{color:"#0f172a"}},children:[e.jsx(S.MdArrowBack,{size:14})," Back"]}),e.jsx(o.Box,{sx:{flex:1}}),e.jsx(o.Box,{component:"button",onClick:a,sx:{background:"none",border:"1px solid #dee2e6",cursor:"pointer",fontSize:13,fontWeight:500,px:2,py:.75,borderRadius:"7px",color:"#6c757d","&:hover":{bgcolor:"#f8f9fa"}},children:"Cancel"}),w?e.jsxs(o.Box,{component:"button",onClick:v,sx:{border:"none",cursor:"pointer",fontSize:13,fontWeight:600,px:2.5,py:.75,borderRadius:"7px",bgcolor:"#6366f1",color:"#fff",display:"flex",alignItems:"center",gap:.75,"&:hover":{bgcolor:"#4f46e5"}},children:[e.jsx(S.MdCheck,{size:15})," ",r?"Save changes":"Add field"]}):e.jsx(o.Box,{component:"button",onClick:f,disabled:!n,sx:{border:"none",cursor:n?"pointer":"not-allowed",fontSize:13,fontWeight:600,px:2.5,py:.75,borderRadius:"7px",bgcolor:n?"#6366f1":"#c7d2fe",color:"#fff","&:hover":{bgcolor:n?"#4f46e5":"#c7d2fe"}},children:"Next →"})]})]})}function ye({field:l,index:s,total:d,onEdit:a,onDelete:r,onMoveUp:t,onMoveDown:p}){const i=l.label||l.id||l.name||"Untitled",c=l.id??l.name??"";return e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1,px:1.5,py:1,border:"1px solid #e2e8f0",borderRadius:"8px",bgcolor:"#fff"},children:[e.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:.25,color:"#cbd5e1"},children:[e.jsx(o.Box,{component:"button",onClick:t,disabled:s===0,sx:{background:"none",border:"none",p:0,cursor:s===0?"default":"pointer",color:s===0?"#e2e8f0":"#94a3b8",lineHeight:1,fontSize:10,"&:hover":{color:s===0?"#e2e8f0":"#475569"}},children:"▲"}),e.jsx(o.Box,{component:"button",onClick:p,disabled:s===d-1,sx:{background:"none",border:"none",p:0,cursor:s===d-1?"default":"pointer",color:s===d-1?"#e2e8f0":"#94a3b8",lineHeight:1,fontSize:10,"&:hover":{color:s===d-1?"#e2e8f0":"#475569"}},children:"▼"})]}),e.jsx(o.Box,{sx:{fontSize:10,fontWeight:700,px:.75,py:.2,borderRadius:"4px",bgcolor:"#eef2ff",color:"#6366f1",flexShrink:0},children:l.type}),e.jsxs(o.Box,{sx:{flex:1,minWidth:0},children:[e.jsxs(o.Typography,{sx:{fontSize:13,fontWeight:600,color:"#0f172a",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[i,l.required&&e.jsx(o.Box,{component:"span",sx:{color:"#dc3545",ml:.25},children:"*"})]}),e.jsx(o.Typography,{sx:{fontSize:11,color:"#94a3b8",fontFamily:"monospace"},children:c})]}),e.jsx(o.Tooltip,{title:"Edit field",placement:"top",children:e.jsx(o.Box,{component:"button",onClick:a,sx:{background:"none",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,borderRadius:"6px",p:0,color:"#94a3b8","&:hover":{bgcolor:"#f1f5f9",color:"#475569"}},children:e.jsx(S.MdEdit,{size:14})})}),e.jsx(o.Tooltip,{title:"Remove field",placement:"top",children:e.jsx(o.Box,{component:"button",onClick:r,sx:{background:"none",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,borderRadius:"6px",p:0,color:"#94a3b8","&:hover":{bgcolor:"#fee2e2",color:"#dc2626"}},children:e.jsx(S.MdDeleteOutline,{size:16})})})]})}function ve({open:l,value:s,onSave:d,onClose:a}){const[r,t]=h.useState(s),[p,i]=h.useState(null);function c(){t(s),i(null)}function m(f){t(u=>u.filter((v,g)=>g!==f))}function y(f,u){t(v=>{const g=[...v],w=f+u;return w<0||w>=g.length?v:([g[f],g[w]]=[g[w],g[f]],g)})}function B(f){p!==null&&(t(u=>{const v=[...u];return v[p]=f,v}),i(null))}function x(){d(r),a()}const n=JSON.stringify(r)!==JSON.stringify(s);return e.jsxs(e.Fragment,{children:[e.jsxs(o.Dialog,{open:l,onClose:a,TransitionProps:{onEnter:c},maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",overflow:"hidden",display:"flex",flexDirection:"column",maxHeight:"85vh"}},children:[e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",px:2.5,py:1.75,borderBottom:"1px solid #e2e8f0",flexShrink:0},children:[e.jsxs(o.Box,{sx:{flex:1},children:[e.jsx(o.Typography,{sx:{fontSize:14,fontWeight:700,color:"#0f172a"},children:"Edit Schema"}),e.jsxs(o.Typography,{sx:{fontSize:11,color:"#94a3b8"},children:[r.length," field",r.length!==1?"s":""," defined"]})]}),e.jsx(o.IconButton,{size:"small",onClick:a,sx:{color:"#94a3b8"},children:e.jsx(S.MdClose,{size:17})})]}),e.jsx(o.Box,{sx:{flex:1,overflowY:"auto",p:2.5},children:r.length===0?e.jsx(o.Box,{sx:{border:"1.5px dashed rgba(0,0,0,0.12)",borderRadius:"8px",py:4,textAlign:"center"},children:e.jsx(o.Typography,{sx:{fontSize:13,color:"#94a3b8"},children:"No fields defined yet"})}):e.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:r.map((f,u)=>e.jsx(ye,{field:f,index:u,total:r.length,onEdit:()=>i(u),onDelete:()=>m(u),onMoveUp:()=>y(u,-1),onMoveDown:()=>y(u,1)},`${f.id??f.name}-${u}`))})}),e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",px:2.5,py:1.5,display:"flex",alignItems:"center",gap:1,flexShrink:0,bgcolor:"#f8fafc"},children:[n?e.jsx(o.Typography,{sx:{fontSize:11,color:"#f59e0b",fontWeight:500,flex:1},children:"Unsaved changes"}):e.jsx(o.Box,{sx:{flex:1}}),e.jsx(o.Box,{component:"button",onClick:a,sx:{background:"none",border:"1px solid #dee2e6",cursor:"pointer",fontSize:13,fontWeight:500,px:2,py:.75,borderRadius:"7px",color:"#6c757d","&:hover":{bgcolor:"#f8f9fa"}},children:"Cancel"}),e.jsxs(o.Box,{component:"button",onClick:x,sx:{border:"none",cursor:"pointer",fontSize:13,fontWeight:600,px:2.5,py:.75,borderRadius:"7px",bgcolor:"#6366f1",color:"#fff",display:"flex",alignItems:"center",gap:.75,"&:hover":{bgcolor:"#4f46e5"}},children:[e.jsx(S.MdCheck,{size:15})," Done"]})]})]}),p!==null&&e.jsx(J,{open:p!==null,initial:r[p],onSave:B,onClose:()=>i(null),editMode:!0})]})}function se(l){const s={};for(const d of l){const a=d.id??d.name??"";a&&(d.type==="array"?s[a]=[]:d.type==="object"||d.type==="schema"?s[a]=se(d.children??[]):s[a]="")}return s}function W({value:l,onChange:s,suggestions:d,label:a="Fields",onPayload:r,validate:t=!0,onValidityChange:p,variableGroups:i,initialValues:c,initialFormulaConfig:m,initialConditionConfig:y}){const[B,x]=h.useState(!1),[n,f]=h.useState(!1),[u,v]=h.useState(null),[g,w]=h.useState(m??{}),[T,k]=h.useState(y??{}),R=h.useRef(c??{}),A=h.useMemo(()=>se(l),[l]),$=h.useMemo(()=>c&&Object.keys(c).length>0?{...A,...c}:A,[A,c]),M=h.useMemo(()=>t?N.buildValidationSchema(l):void 0,[t,l]);h.useEffect(()=>{r&&r({schema:l,formulaConfig:g,conditionConfig:T,conditionExpressions:N.serializeConditionExpressions(T),values:R.current,evaluationPayload:N.buildEvaluationPayload({values:R.current,conditionConfig:T})})},[T,g,l]);const V=h.useCallback(z=>{R.current=z,r&&r({schema:l,formulaConfig:g,conditionConfig:T,conditionExpressions:N.serializeConditionExpressions(T),values:z,evaluationPayload:N.buildEvaluationPayload({values:z,conditionConfig:T})})},[l,g,T,r]);function P(z){s([...l,z])}function q(z){if(!u)return;const{containerFieldId:D,tabId:H}=u,U=l.map(I=>{if((I.id??I.name)!==D)return I;const Y=I.tabs??[];return{...I,tabs:Y.map(O=>O.id===H?{...O,fields:[...O.fields??[],z]}:O)}});s(U),v(null)}function C(z,D,H){const U=l.map(I=>{if((I.id??I.name)!==z)return I;const Y=I.tabs??[];return{...I,tabs:Y.map(O=>O.id===D?{...O,fields:(O.fields??[]).filter((Be,te)=>te!==H)}:O)}});s(U)}const ne=h.useMemo(()=>({openAddFieldDialog:(z,D)=>v({containerFieldId:z,tabId:D}),removeFieldFromTab:C}),[l,s]),K=e.jsxs("div",{className:"schema-builder-root",children:[l.length>0&&e.jsx("div",{className:"schema-builder-header",children:e.jsxs("div",{className:"schema-builder-actions",children:[e.jsx(o.Tooltip,{title:"Edit schema",placement:"top",children:e.jsxs("button",{className:"sb-btn sb-btn-outline",onClick:()=>f(!0),children:[e.jsx(S.MdSettings,{size:13})," Edit Schema"]})}),e.jsx(o.Tooltip,{title:"Add a new field",placement:"top",children:e.jsxs("button",{className:"sb-btn sb-btn-primary",onClick:()=>x(!0),children:[e.jsx(S.MdAdd,{size:14})," Add Field"]})})]})}),l.length>0?e.jsx(N.TabsEditContext.Provider,{value:ne,children:e.jsx(N.FlowForm,{schema:{layout:"flat",fields:l},initialValues:$,onSubmit:()=>{},validationSchema:M,onValidityChange:p,onValuesChange:r?V:void 0,formulaConfig:g,onFormulaConfigChange:w,conditionConfig:T,onConditionConfigChange:k})}):e.jsxs("div",{className:"schema-builder-empty-state",children:[e.jsx(ie.FaWpforms,{size:40,className:"schema-builder-empty-icon"}),e.jsx("p",{className:"schema-builder-empty-title",children:"Tell us what fields should be in the list, and assign values to them."}),e.jsx("div",{className:"schema-builder-empty-actions",children:e.jsx("button",{className:"btn",onClick:()=>x(!0),children:"Add field"})})]}),e.jsx(J,{open:B,onSave:P,onClose:()=>x(!1)}),e.jsx(ve,{open:n,value:l,onSave:s,onClose:()=>f(!1)}),e.jsx(J,{open:!!u,onSave:q,onClose:()=>v(null)})]});return i?e.jsxs(N.VariablePickerProvider,{groups:i,children:[e.jsx(N.VariablePicker,{width:260,mode:"popover"}),K]}):K}function Ce({fields:l,onOpen:s}){return e.jsxs(o.Box,{sx:{border:"1px solid #e2e8f0",borderRadius:"8px",bgcolor:"#fff",overflow:"hidden"},children:[l.length>0?e.jsx(o.Box,{sx:{px:1.5,py:1.25,display:"flex",flexWrap:"wrap",gap:.5},children:l.map((d,a)=>{const r=d.id??d.name??"";return e.jsx(o.Tooltip,{title:`${d.type} · ${r}`,placement:"top",children:e.jsx(o.Chip,{label:d.label||r,size:"small",sx:{fontSize:11,fontWeight:500,height:22,bgcolor:"#f1f5f9",color:"#334155",border:"1px solid #e2e8f0","& .MuiChip-label":{px:1}}})},a)})}):e.jsx(o.Box,{sx:{px:1.5,py:1.5},children:e.jsx(o.Typography,{sx:{fontSize:12,color:"#94a3b8"},children:"No fields defined yet"})}),e.jsx(o.Divider,{sx:{borderColor:"#f1f5f9"}}),e.jsxs(o.Box,{onClick:s,sx:{display:"flex",alignItems:"center",gap:.75,px:1.5,py:1,cursor:"pointer","&:hover":{bgcolor:"#f8fafc"},transition:"background 0.12s"},children:[l.length===0?e.jsx(S.MdAdd,{size:14,color:"#6366f1"}):e.jsx(S.MdSettings,{size:13,color:"#6366f1"}),e.jsx(o.Typography,{sx:{fontSize:12,fontWeight:600,color:"#6366f1",flex:1},children:l.length===0?"Add fields":"Configure fields"}),e.jsx(S.MdArrowForward,{size:13,color:"#94a3b8"})]})]})}function Se({value:l,onChange:s,suggestions:d,onPayload:a,onDone:r,validate:t,onValidityChange:p,label:i="Fields",drawerTitle:c="Configure Fields",drawerWidth:m=580}){const[y,B]=h.useState(!1),[x,n]=h.useState({type:"list"}),[f,u]=h.useState(l),v=h.useRef(null),g=h.useRef(void 0),w=h.useRef(void 0),T=h.useRef(void 0),[k,R]=h.useState(null);function A(){u(l),n({type:"list"}),B(!0)}function $(){const C=v.current;C&&(g.current=C.values,w.current=C.formulaConfig,T.current=C.conditionConfig),s(f),B(!1),r==null||r(f,C)}function M(){const C=v.current;C&&(g.current=C.values,w.current=C.formulaConfig,T.current=C.conditionConfig),u(l),B(!1)}function V(){if(x.type!=="edit"||!k)return;const C=[...f];C[x.index]=k,u(C),n({type:"list"}),R(null)}function P(){n({type:"list"}),R(null)}const q=JSON.stringify(f)!==JSON.stringify(l);return x.type==="edit"&&f[x.index],e.jsxs(e.Fragment,{children:[e.jsxs(o.Box,{children:[e.jsx(o.Typography,{sx:{fontSize:12,fontWeight:700,color:"#64748b",textTransform:"uppercase",letterSpacing:.5,mb:.75},children:i}),e.jsx(Ce,{fields:l,onOpen:A})]}),e.jsxs(o.Drawer,{anchor:"right",open:y,onClose:M,PaperProps:{sx:{width:m,display:"flex",flexDirection:"column",boxShadow:"-4px 0 24px rgba(0,0,0,0.12)",overflow:"hidden"}},children:[e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",px:2,py:1.5,borderBottom:"1px solid #e2e8f0",flexShrink:0,gap:1},children:[x.type==="edit"&&e.jsx(o.Tooltip,{title:"Back to fields",placement:"bottom",children:e.jsx(o.IconButton,{size:"small",onClick:P,sx:{color:"#64748b"},children:e.jsx(S.MdArrowBack,{size:17})})}),e.jsxs(o.Box,{sx:{flex:1},children:[e.jsx(o.Typography,{sx:{fontSize:14,fontWeight:700,color:"#0f172a"},children:x.type==="edit"?(k==null?void 0:k.label)||(k==null?void 0:k.id)||"Edit field":c}),e.jsx(o.Typography,{sx:{fontSize:11,color:"#94a3b8"},children:x.type==="edit"?"Configure field properties":`${f.length} field${f.length!==1?"s":""} defined`})]}),x.type==="list"&&e.jsx(o.Tooltip,{title:"Close",placement:"bottom",children:e.jsx(o.IconButton,{size:"small",onClick:M,sx:{color:"#94a3b8"},children:e.jsx(S.MdClose,{size:17})})})]}),x.type==="list"&&e.jsxs(e.Fragment,{children:[e.jsx(o.Box,{sx:{flex:1,overflowY:"auto",p:2.5},children:e.jsx(W,{value:f,onChange:u,suggestions:d,onPayload:C=>{v.current=C,g.current=C.values,w.current=C.formulaConfig,T.current=C.conditionConfig,a==null||a(C)},validate:t,onValidityChange:p,label:i,initialValues:g.current,initialFormulaConfig:w.current,initialConditionConfig:T.current})}),e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",px:2.5,py:1.5,display:"flex",alignItems:"center",gap:1,flexShrink:0,bgcolor:"#f8fafc"},children:[q?e.jsx(o.Typography,{sx:{fontSize:11,color:"#f59e0b",fontWeight:500,flex:1},children:"Unsaved changes"}):e.jsx(o.Box,{sx:{flex:1}}),e.jsx(o.Box,{component:"button",onClick:M,sx:{background:"none",border:"1px solid #dee2e6",cursor:"pointer",fontSize:13,fontWeight:500,px:2,py:.75,borderRadius:"7px",color:"#6c757d","&:hover":{bgcolor:"#f8f9fa"}},children:"Cancel"}),e.jsxs(o.Box,{component:"button",onClick:$,sx:{border:"none",cursor:"pointer",fontSize:13,fontWeight:600,px:2.5,py:.75,borderRadius:"7px",bgcolor:"#6366f1",color:"#fff",display:"flex",alignItems:"center",gap:.75,"&:hover":{bgcolor:"#4f46e5"}},children:[e.jsx(S.MdCheck,{size:15})," Done"]})]})]}),x.type==="edit"&&k&&e.jsx(le,{field:k,onChange:R,onSave:V,onCancel:P})]})]})}exports.FIELD_TYPE_OPTIONS=Z;exports.SchemaBuilder=W;exports.SchemaBuilderDrawer=Se;exports.useFlowForm=ae;
|
|
1
|
+
"use strict";const h=require("react"),re=require("formik"),N=require("./index-DNZlQp9z.js"),e=require("react/jsx-runtime"),o=require("@mui/material"),S=require("react-icons/md"),ie=require("react-icons/fa6");function ae({schema:l,initialValues:s,onSubmit:d,showErrorsImmediately:a=!1}){const r=l.fields??[],t=h.useMemo(()=>N.buildValidationSchema(r),[r]),p=h.useMemo(()=>{if(a)return r.reduce((u,v)=>{const g=N.resolveFieldKey(v);return g&&(u[g]=!0),u},{})},[r,a]),[i,c]=h.useState({}),[m,y]=h.useState({}),B=h.useRef(s);h.useEffect(()=>{B.current!==s&&(B.current=s,c({}),y({}))},[s]);const x=re.useFormik({initialValues:s,validationSchema:t,initialTouched:p,validateOnMount:a,validateOnChange:!0,validateOnBlur:!0,enableReinitialize:!0,onSubmit:async u=>{const v=N.buildEvaluationPayload({values:u,conditionConfig:m});await d(u,v)}}),n=h.useCallback(()=>{x.submitForm()},[x]),f=h.useCallback(u=>{x.resetForm(u?{values:u}:void 0),c({}),y({})},[x]);return{values:x.values,errors:x.errors,isValid:x.isValid,isDirty:x.dirty,isSubmitting:x.isSubmitting,formulaConfig:i,conditionConfig:m,submit:n,reset:f,setFieldValue:x.setFieldValue,_schema:l,_formik:x,_formulaConfig:i,_onFormulaConfigChange:c,_conditionConfig:m,_onConditionConfigChange:y}}const Z=N.FlowForgeRegistry.getTypeOptions(),j="form-control font-14",b="text-14 text-dark fw-medium mb-1 align-items-center d-flex gap-1",F={fontSize:10,fontWeight:700,color:"#94a3b8",textTransform:"uppercase",letterSpacing:.6,marginBottom:8,display:"block"},ce=[{value:"text",label:"Text"},{value:"number",label:"Number"},{value:"email",label:"Email"},{value:"url",label:"URL"},{value:"password",label:"Password"},{value:"select",label:"Select"},{value:"object",label:"Object (sub-fields)"},{value:"array",label:"Array (nested)"}],de=[{value:3,label:"1/4"},{value:4,label:"1/3"},{value:6,label:"1/2"},{value:8,label:"2/3"},{value:12,label:"Full"}];function xe({value:l,onChange:s}){const d=l??12;return e.jsxs(o.Box,{children:[e.jsx("span",{className:b,children:"Column width"}),e.jsx(o.Box,{sx:{display:"flex",gap:.5},children:de.map(a=>e.jsx(o.Tooltip,{title:`colSpan: ${a.value}`,placement:"top",children:e.jsx(o.Box,{component:"button",onClick:()=>s(a.value),sx:{flex:1,border:"1px solid",borderColor:d===a.value?"#6366f1":"#dee2e6",borderRadius:"6px",cursor:"pointer",bgcolor:d===a.value?"#eef2ff":"#fff",color:d===a.value?"#6366f1":"#6c757d",fontSize:11,fontWeight:600,py:.6,px:0,"&:hover":{borderColor:"#6366f1",bgcolor:"#f5f3ff"}},children:a.label})},a.value))}),e.jsx(o.Box,{sx:{display:"flex",gap:"3px",mt:.75},children:Array.from({length:12}).map((a,r)=>e.jsx(o.Box,{sx:{flex:1,height:4,borderRadius:"2px",bgcolor:r<d?"#6366f1":"#e2e8f0",transition:"background 0.12s"}},r))})]})}function Q({options:l=[],onChange:s}){function d(a,r,t){s(l.map((p,i)=>i===a?{...p,[r]:t}:p))}return e.jsxs(o.Box,{children:[e.jsxs("span",{className:b,children:["Options ",e.jsx("span",{style:{color:"#dc3545"},children:"*"})]}),e.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:.5,mb:.75},children:l.map((a,r)=>e.jsxs(o.Box,{sx:{display:"flex",gap:.5,alignItems:"center"},children:[e.jsx("input",{className:j,style:{flex:1},placeholder:"Label",value:a.label,onChange:t=>d(r,"label",t.target.value)}),e.jsx("input",{className:j,style:{flex:1},placeholder:"Value",value:a.value,onChange:t=>d(r,"value",t.target.value)}),e.jsx(o.Box,{component:"button",onClick:()=>s(l.filter((t,p)=>p!==r)),sx:{background:"none",border:"none",cursor:"pointer",color:"#94a3b8",display:"flex",p:.25,"&:hover":{color:"#dc2626"}},children:e.jsx(S.MdClose,{size:13})})]},r))}),e.jsxs(o.Box,{component:"button",onClick:()=>s([...l,{label:"",value:""}]),sx:{display:"flex",alignItems:"center",gap:.5,background:"none",border:"1px dashed #dee2e6",cursor:"pointer",fontSize:11,fontWeight:600,px:1,py:.5,borderRadius:"6px",color:"#6366f1",width:"100%","&:hover":{borderColor:"#6366f1",bgcolor:"#f5f3ff"}},children:[e.jsx(S.MdAdd,{size:13})," Add option"]})]})}const ee=[{value:"operator",label:"Operator (predefined)"},{value:"select",label:"Select"},{value:"text",label:"Text"}];function pe({col:l,onChange:s,onDelete:d}){const a=l.type==="select",r=l.type==="operator";return e.jsxs(o.Box,{sx:{border:"1px solid #e2e8f0",borderRadius:"7px",p:1.25,bgcolor:"#fff",display:"flex",flexDirection:"column",gap:1},children:[e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx(o.Box,{sx:{fontSize:10,fontWeight:700,px:.75,py:.2,borderRadius:"4px",bgcolor:r?"#fef9c3":"#eef2ff",color:r?"#92400e":"#6366f1",flexShrink:0},children:r?"OPERATOR":l.type.toUpperCase()}),e.jsx(o.Box,{sx:{fontSize:12,fontWeight:600,color:"#0f172a",flex:1},children:l.label||l.id||"Unnamed"}),e.jsx(o.Box,{component:"button",onClick:d,sx:{background:"none",border:"none",cursor:"pointer",color:"#94a3b8",display:"flex",p:.25,"&:hover":{color:"#dc2626"}},children:e.jsx(S.MdClose,{size:13})})]}),e.jsxs(o.Box,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:1},children:[e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Column type"}),e.jsx("select",{value:l.type,onChange:t=>s({...l,type:t.target.value,options:void 0}),className:j,style:{cursor:"pointer"},children:ee.map(t=>e.jsx("option",{value:t.value,children:t.label},t.value))})]}),e.jsxs(o.Box,{children:[e.jsxs("label",{className:b,children:["Column key ",e.jsx("span",{style:{color:"#dc3545"},children:"*"})]}),e.jsx("input",{className:`${j} ${l.id?"":"border-danger"}`,value:l.id,onChange:t=>s({...l,id:t.target.value}),placeholder:"e.g. field, operator, value"}),!l.id&&e.jsx("span",{style:{fontSize:10,color:"#dc3545"},children:"Required — used as data key"})]})]}),!r&&e.jsxs(o.Box,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:1},children:[e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Label"}),e.jsx("input",{className:j,value:l.label??"",onChange:t=>s({...l,label:t.target.value||void 0}),placeholder:"Column label"})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Placeholder"}),e.jsx("input",{className:j,value:l.placeholder??"",onChange:t=>s({...l,placeholder:t.target.value||void 0}),placeholder:"Hint…"})]})]}),a&&e.jsx(Q,{options:l.options??[],onChange:t=>s({...l,options:t})}),r&&e.jsx(o.Box,{sx:{bgcolor:"#fefce8",border:"1px solid #fef08a",borderRadius:"6px",px:1.25,py:.75},children:e.jsx(o.Box,{sx:{fontSize:11,color:"#78350f"},children:"Predefined: equals, not equals, contains, starts with, ends with, is present, is not present, greater than, less than…"})}),!r&&e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx("input",{type:"checkbox",id:`formula-${l.id}`,checked:!!l.formula,onChange:t=>s({...l,formula:t.target.checked||void 0}),style:{cursor:"pointer",width:14,height:14}}),e.jsx("label",{htmlFor:`formula-${l.id}`,className:b,style:{margin:0,cursor:"pointer"},children:"Formula input (chip editor)"})]})]})}function ue({condition:l,onChange:s}){const d=!!l;function a(){s(d?void 0:{fields:[]})}function r(i){if(!l)return;const c=i==="operator"?"operator":l.fields.filter(m=>m.type!=="operator").length===0?"field":"value";s({...l,fields:[...l.fields,{id:c,type:i}]})}function t(i,c){if(!l)return;const m=[...l.fields];m[i]=c,s({...l,fields:m})}function p(i){l&&s({...l,fields:l.fields.filter((c,m)=>m!==i)})}return e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",pt:1.5},children:[e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75,mb:d?1.25:0},children:[e.jsx("input",{type:"checkbox",id:"enable-condition",checked:d,onChange:a,style:{cursor:"pointer",width:14,height:14}}),e.jsx("span",{style:{...F,margin:0,color:d?"#6366f1":"#94a3b8"},children:"Condition row"})]}),d&&l&&e.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[l.fields.map((i,c)=>e.jsx(pe,{col:i,onChange:m=>t(c,m),onDelete:()=>p(c)},c)),e.jsx(o.Box,{sx:{display:"flex",gap:.5},children:ee.map(i=>e.jsxs(o.Box,{component:"button",onClick:()=>r(i.value),sx:{flex:1,background:"none",border:"1px dashed #dee2e6",cursor:"pointer",fontSize:11,fontWeight:600,py:.5,borderRadius:"6px",color:i.value==="operator"?"#92400e":"#6366f1","&:hover":{borderColor:"#6366f1",bgcolor:"#f5f3ff"}},children:["+ ",i.value==="operator"?"Operator":i.label.split(" ")[0]]},i.value))}),e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:2,flexWrap:"wrap"},children:[e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx("input",{type:"checkbox",id:"allow-groups",checked:!!l.allowGroups,onChange:i=>s({...l,allowGroups:i.target.checked||void 0}),style:{cursor:"pointer",width:14,height:14}}),e.jsx("label",{htmlFor:"allow-groups",className:b,style:{margin:0,cursor:"pointer"},children:"Allow nested groups"})]}),l.allowGroups&&e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx("label",{className:b,style:{margin:0},children:"Max depth"}),e.jsx("input",{type:"number",min:1,max:5,className:j,style:{width:60,textAlign:"center"},value:l.maxGroupDepth??"",onChange:i=>s({...l,maxGroupDepth:i.target.value?Number(i.target.value):void 0}),placeholder:"∞"})]})]})]})]})}function E({id:l,label:s,checked:d,onChange:a}){return e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.75},children:[e.jsx("input",{type:"checkbox",id:l,checked:d,onChange:r=>a(r.target.checked),style:{cursor:"pointer",width:14,height:14,flexShrink:0}}),e.jsx("label",{htmlFor:l,className:b,style:{margin:0,cursor:"pointer"},children:s})]})}function he({views:l=[],onChange:s}){function d(r,t,p){s(l.map((i,c)=>c===r?{...i,[t]:p}:i))}function a(){const r=`tab${l.length+1}`;s([...l,{id:r,label:`Tab ${l.length+1}`}])}return e.jsxs(o.Box,{children:[e.jsx("span",{className:b,children:"Views"}),e.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:.5,mb:.75},children:l.map((r,t)=>e.jsxs(o.Box,{sx:{display:"flex",gap:.5,alignItems:"center"},children:[e.jsx("input",{className:j,style:{flex:1},placeholder:"Label",value:r.label,onChange:p=>d(t,"label",p.target.value)}),e.jsx("input",{className:j,style:{flex:1},placeholder:"ID (no spaces)",value:r.id,onChange:p=>d(t,"id",p.target.value.replace(/\s/g,"_"))}),e.jsx(o.Box,{component:"button",onClick:()=>s(l.filter((p,i)=>i!==t)),sx:{background:"none",border:"none",cursor:"pointer",color:"#94a3b8",display:"flex",p:.25,"&:hover":{color:"#dc2626"}},children:e.jsx(S.MdClose,{size:13})})]},t))}),e.jsxs(o.Box,{component:"button",onClick:a,sx:{display:"flex",alignItems:"center",gap:.5,background:"none",border:"1px dashed #dee2e6",cursor:"pointer",fontSize:11,fontWeight:600,px:1,py:.5,borderRadius:"6px",color:"#6366f1",width:"100%","&:hover":{borderColor:"#6366f1",bgcolor:"#f5f3ff"}},children:[e.jsx(S.MdAdd,{size:13})," Add view"]})]})}function _({label:l,value:s,options:d,onChange:a}){return e.jsxs(o.Box,{children:[e.jsx("span",{className:b,children:l}),e.jsx(o.Box,{sx:{display:"flex",border:"1px solid #dee2e6",borderRadius:"7px",overflow:"hidden"},children:d.map(r=>e.jsx(o.Box,{component:"button",onClick:()=>a(r.value),sx:{flex:1,border:"none",borderRight:"1px solid #dee2e6",cursor:"pointer",fontSize:12,fontWeight:600,py:.6,bgcolor:s===r.value?"#eef2ff":"#fff",color:s===r.value?"#6366f1":"#6c757d","&:last-child":{borderRight:"none"},"&:hover":{bgcolor:"#f5f3ff"}},children:r.label},r.value))})]})}function le({field:l,onChange:s,onSave:d,onCancel:a,noFooter:r}){const[t,p]=h.useState(!1),i=l.id??l.name??"",c=l,m=l.type==="select"||l.type==="descriptive-select"||l.type==="radio-group",y=N.FlowForgeRegistry.get(l.type),B=y==null?void 0:y.configSchema;function x(n,f){s({...l,[n]:f})}return e.jsxs(e.Fragment,{children:[e.jsxs(o.Box,{sx:{flex:1,overflowY:"auto",px:2.5,py:2,display:"flex",flexDirection:"column",gap:1.75},children:[e.jsxs(o.Box,{children:[e.jsx("span",{style:F,children:"Required"}),e.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1},children:[e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Type"}),e.jsx("select",{value:l.type,onChange:n=>x("type",n.target.value),className:j,style:{cursor:"pointer"},children:Z.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))})]}),e.jsxs(o.Box,{sx:{display:"grid",gridTemplateColumns:l.type==="tabs"?"1fr":"1fr 1fr",gap:1},children:[e.jsxs(o.Box,{children:[e.jsxs("label",{className:b,children:["Field ID ",e.jsx("span",{style:{color:"#dc3545"},children:"*"})]}),e.jsx("input",{className:j,value:l.id??l.name??"",onChange:n=>x("id",n.target.value),placeholder:"e.g. email"})]}),l.type!=="tabs"&&e.jsxs(o.Box,{children:[e.jsxs("label",{className:b,children:["Label ",e.jsx("span",{style:{color:"#dc3545"},children:"*"})]}),e.jsx("input",{className:j,value:l.label??"",onChange:n=>x("label",n.target.value),placeholder:"Display label"})]})]}),l.type!=="tabs"&&e.jsx(xe,{value:l.colSpan,onChange:n=>x("colSpan",n===12?void 0:n)})]})]}),B&&e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",pt:1.5},children:[e.jsx("span",{style:F,children:"Specific Settings"}),e.jsx(N.FlowForm,{schema:{layout:"flat",compact:!0,fields:B.fields},initialValues:l,onValuesChange:n=>s({...l,...n}),onSubmit:()=>{}})]}),l.type==="tabs"&&e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",pt:1.5,display:"flex",flexDirection:"column",gap:1.5},children:[e.jsx("span",{style:F,children:"Content"}),e.jsx(he,{views:(c.tabs??[]).map(n=>({id:n.id,label:n.label})),onChange:n=>{const f=c.tabs??[],u=n.map(v=>{const g=f.find(w=>w.id===v.id);return g?{...g,...v}:{...v,fields:[]}});s({...l,tabs:u})}}),e.jsx("span",{style:{...F,marginTop:4},children:"Interaction"}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Disabled"}),e.jsx("input",{className:j,value:c.disabledExpr??"",onChange:n=>s({...l,disabledExpr:n.target.value||void 0}),placeholder:"false"})]}),e.jsx("span",{style:{...F,marginTop:4},children:"Appearance"}),e.jsx(_,{label:"Alignment",value:c.alignment??"left",options:[{value:"left",label:"|←"},{value:"center-left",label:"←|"},{value:"center",label:"|·|"},{value:"center-right",label:"|→"},{value:"right",label:"→|"}],onChange:n=>s({...l,alignment:n})}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Hidden"}),e.jsx("input",{className:j,value:c.hiddenExpr??"",onChange:n=>s({...l,hiddenExpr:n.target.value||void 0}),placeholder:"false"})]}),e.jsx(_,{label:"Variant",value:c.variant??"line",options:[{value:"pill",label:"Pill"},{value:"line",label:"Line"}],onChange:n=>s({...l,variant:n})}),e.jsxs(o.Box,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr 1fr",gap:1},children:[e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Active color"}),e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx("input",{type:"color",value:c.activeColor??"#6366f1",onChange:n=>s({...l,activeColor:n.target.value}),style:{width:28,height:28,border:"1px solid #dee2e6",borderRadius:6,cursor:"pointer",padding:2,background:"#fff"}}),e.jsx("input",{className:j,value:c.activeColor??"",onChange:n=>s({...l,activeColor:n.target.value||void 0}),placeholder:"#6366f1",style:{flex:1}})]})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Active text"}),e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx("input",{type:"color",value:c.activeTextColor??"#ffffff",onChange:n=>s({...l,activeTextColor:n.target.value}),style:{width:28,height:28,border:"1px solid #dee2e6",borderRadius:6,cursor:"pointer",padding:2,background:"#fff"}}),e.jsx("input",{className:j,value:c.activeTextColor??"",onChange:n=>s({...l,activeTextColor:n.target.value||void 0}),placeholder:"auto",style:{flex:1}})]})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Inactive text"}),e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:.5},children:[e.jsx("input",{type:"color",value:c.inactiveTextColor??"#64748b",onChange:n=>s({...l,inactiveTextColor:n.target.value}),style:{width:28,height:28,border:"1px solid #dee2e6",borderRadius:6,cursor:"pointer",padding:2,background:"#fff"}}),e.jsx("input",{className:j,value:c.inactiveTextColor??"",onChange:n=>s({...l,inactiveTextColor:n.target.value||void 0}),placeholder:"#64748b",style:{flex:1}})]})]})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Styles"}),e.jsx("input",{className:j,value:c.styles??"",onChange:n=>s({...l,styles:n.target.value||void 0}),placeholder:"None"})]}),e.jsx("span",{style:{...F,marginTop:4},children:"Spacing"}),e.jsx(_,{label:"Height",value:c.height??"auto",options:[{value:"auto",label:"Auto"},{value:"fixed",label:"Fixed"}],onChange:n=>s({...l,height:n})}),e.jsx(_,{label:"Margin",value:c.margin??"normal",options:[{value:"normal",label:"Normal"},{value:"none",label:"None"}],onChange:n=>s({...l,margin:n})})]}),m&&e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",pt:1.5},children:[e.jsx("span",{style:F,children:"Options"}),e.jsx(Q,{options:c.options??[],onChange:n=>s({...l,options:n})})]}),l.type==="array"&&e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",pt:1.5,display:"flex",flexDirection:"column",gap:1},children:[e.jsx("span",{style:F,children:"Array settings"}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Item type"}),e.jsx("select",{className:j,style:{cursor:"pointer"},value:c.itemType??"text",onChange:n=>s({...l,itemType:n.target.value}),children:ce.map(n=>e.jsx("option",{value:n.value,children:n.label},n.value))})]}),e.jsxs(o.Box,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:1},children:[e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Item label"}),e.jsx("input",{className:j,value:c.itemLabel??"",onChange:n=>s({...l,itemLabel:n.target.value||void 0}),placeholder:'e.g. "Member"'})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Add button label"}),e.jsx("input",{className:j,value:c.addLabel??"",onChange:n=>s({...l,addLabel:n.target.value||void 0}),placeholder:"Add item"})]})]}),e.jsxs(o.Box,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:1},children:[e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Min items"}),e.jsx("input",{type:"number",min:0,className:j,value:c.minItems??"",onChange:n=>s({...l,minItems:n.target.value?Number(n.target.value):void 0}),placeholder:"0"})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Max items"}),e.jsx("input",{type:"number",min:1,className:j,value:c.maxItems??"",onChange:n=>s({...l,maxItems:n.target.value?Number(n.target.value):void 0}),placeholder:"∞"})]})]}),!["object","array","select"].includes(c.itemType??"text")&&e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Item placeholder"}),e.jsx("input",{className:j,value:c.itemPlaceholder??"",onChange:n=>s({...l,itemPlaceholder:n.target.value||void 0}),placeholder:"Enter value…"})]})]}),e.jsx(ue,{condition:l.condition,onChange:n=>s({...l,condition:n})}),e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",pt:1.5},children:[e.jsx(o.Box,{component:"button",onClick:()=>p(n=>!n),sx:{background:"none",border:"none",cursor:"pointer",display:"flex",alignItems:"center",gap:.5,p:0,mb:t?1.25:0},children:e.jsxs("span",{style:{...F,margin:0,color:t?"#6366f1":"#94a3b8"},children:[t?"▾":"▸"," Optional settings"]})}),e.jsx(o.Collapse,{in:t,children:e.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:1.25},children:[e.jsxs(o.Box,{sx:{display:"grid",gridTemplateColumns:"1fr 1fr",gap:1},children:[e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Placeholder"}),e.jsx("input",{className:j,value:l.placeholder??"",onChange:n=>x("placeholder",n.target.value||void 0),placeholder:"Hint text…"})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Helper text"}),e.jsx("input",{className:j,value:l.helperText??"",onChange:n=>x("helperText",n.target.value||void 0),placeholder:"Description…"})]})]}),e.jsxs(o.Box,{children:[e.jsx("label",{className:b,children:"Info tooltip"}),e.jsx("input",{className:j,value:l.info??"",onChange:n=>x("info",n.target.value||void 0),placeholder:"Shown in ℹ tooltip"})]}),e.jsxs(o.Box,{sx:{display:"flex",flexWrap:"wrap",gap:1.5},children:[e.jsx(E,{id:`${i}-req`,label:"Required",checked:!!l.required,onChange:n=>x("required",n||void 0)}),e.jsx(E,{id:`${i}-dis`,label:"Disabled",checked:!!l.disabled,onChange:n=>x("disabled",n||void 0)}),e.jsx(E,{id:`${i}-hid`,label:"Hidden",checked:!!l.hidden,onChange:n=>x("hidden",n||void 0)}),e.jsx(E,{id:`${i}-opt`,label:"Show optional",checked:!!l.showOptional,onChange:n=>x("showOptional",n||void 0)}),e.jsx(E,{id:`${i}-div`,label:"Divider after",checked:!!l.dividerAfter,onChange:n=>x("dividerAfter",n||void 0)}),e.jsx(E,{id:`${i}-frm`,label:"Formula input",checked:!!l.formula,onChange:n=>x("formula",n||void 0)})]})]})})]})]}),!r&&e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",px:2.5,py:1.5,display:"flex",gap:1,justifyContent:"flex-end",bgcolor:"#f8fafc",flexShrink:0},children:[e.jsx(o.Box,{component:"button",onClick:a,sx:{background:"none",border:"1px solid #dee2e6",cursor:"pointer",fontSize:13,fontWeight:500,px:2,py:.75,borderRadius:"7px",color:"#6c757d","&:hover":{bgcolor:"#f8f9fa"}},children:"Cancel"}),e.jsxs(o.Box,{component:"button",onClick:d,sx:{border:"none",cursor:"pointer",fontSize:13,fontWeight:600,px:2.5,py:.75,borderRadius:"7px",bgcolor:"#6366f1",color:"#fff",display:"flex",alignItems:"center",gap:.75,"&:hover":{bgcolor:"#4f46e5"}},children:[e.jsx(S.MdCheck,{size:15})," Save"]})]})]})}const L={text:"#0f172a",textMuted:"#64748b",borderInput:"rgba(0,0,0,0.23)",bg:"#ffffff"},fe={md:"6px"},oe={sm:11,md:13},G={width:"100%",fontSize:oe.md,fontFamily:"inherit",padding:"8px 12px",border:`1px solid ${L.borderInput}`,borderRadius:fe.md,outline:"none",background:L.bg,color:L.text,boxSizing:"border-box",transition:"border-color 0.15s, box-shadow 0.15s"};function X(){return{type:"text",id:"",label:"",colSpan:12}}function be(l){return l.type==="object"||l.type==="array"||l.type==="schema"}function me(l){if(l.type==="object")return"Child Fields";if(l.type==="schema")return"Schema Fields";const s=l.itemType??"text";return s==="object"?"Item Fields":s==="select"?"Item Options":"Item Config"}function ge({field:l,onChange:s}){var r;const d=l,a=d.itemType??"text";if(l.type==="object")return e.jsxs(o.Box,{sx:{p:2.5},children:[e.jsx(o.Typography,{sx:{fontSize:12,color:"#64748b",mb:2},children:"Define the fields nested inside this object. Each child field can itself be an object or array."}),e.jsx(W,{value:l.children??[],onChange:t=>s({...l,children:t}),label:"Child fields"})]});if(l.type==="schema")return e.jsxs(o.Box,{sx:{p:2.5},children:[e.jsx(o.Typography,{sx:{fontSize:12,color:"#64748b",mb:2},children:"Define the fields inside this schema. When the form is filled, their values are collected into a single object as this field's value."}),e.jsx(W,{value:l.children??[],onChange:t=>s({...l,children:t}),label:"Schema fields"})]});if(l.type==="array"){if(a==="object")return e.jsxs(o.Box,{sx:{p:2.5},children:[e.jsx(o.Typography,{sx:{fontSize:12,color:"#64748b",mb:2},children:"Define the fields for each item in the array. Each item will be an object with these fields."}),e.jsx(W,{value:d.itemFields??[],onChange:t=>s({...l,itemFields:t}),label:"Item fields"})]});if(a==="select"){const t=d.itemOptions??[];return e.jsxs(o.Box,{sx:{p:2.5},children:[e.jsx(o.Typography,{sx:{fontSize:12,color:"#64748b",mb:2},children:"Options available in each select item."}),e.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:.5,mb:.75},children:t.map((p,i)=>e.jsxs(o.Box,{sx:{display:"flex",gap:.5,alignItems:"center"},children:[e.jsx("input",{style:{...G,flex:1,padding:"6px 10px"},placeholder:"Label",value:p.label,onChange:c=>{const m=t.map((y,B)=>B===i?{...y,label:c.target.value}:y);s({...l,itemOptions:m})}}),e.jsx("input",{style:{...G,flex:1,padding:"6px 10px"},placeholder:"Value",value:p.value,onChange:c=>{const m=t.map((y,B)=>B===i?{...y,value:c.target.value}:y);s({...l,itemOptions:m})}}),e.jsx(o.Box,{component:"button",onClick:()=>s({...l,itemOptions:t.filter((c,m)=>m!==i)}),sx:{background:"none",border:"none",cursor:"pointer",color:"#94a3b8",display:"flex",p:.25,"&:hover":{color:"#dc2626"}},children:"✕"})]},i))}),e.jsx(o.Box,{component:"button",onClick:()=>s({...l,itemOptions:[...t,{label:"",value:""}]}),sx:{display:"flex",alignItems:"center",gap:.5,background:"none",border:"1px dashed #dee2e6",cursor:"pointer",fontSize:11,fontWeight:600,px:1,py:.5,borderRadius:"6px",color:"#6366f1",width:"100%",justifyContent:"center","&:hover":{borderColor:"#6366f1",bgcolor:"#f5f3ff"}},children:"+ Add option"})]})}if(a==="array"){const t=((r=d.itemSchema)==null?void 0:r.itemType)??"text",p=[{value:"text",label:"Text"},{value:"number",label:"Number"},{value:"email",label:"Email"},{value:"url",label:"URL"},{value:"password",label:"Password"},{value:"select",label:"Select"},{value:"object",label:"Object"}];return e.jsxs(o.Box,{sx:{p:2.5},children:[e.jsx(o.Typography,{sx:{fontSize:12,color:"#64748b",mb:2},children:"Each item is itself an array. Configure the type of items inside the nested array."}),e.jsx("label",{style:{fontSize:oe.sm,fontWeight:600,color:L.textMuted,display:"block",marginBottom:3},children:"Nested item type"}),e.jsx("select",{style:{...G,padding:"6px 10px",cursor:"pointer"},value:t,onChange:i=>s({...l,itemSchema:{...d.itemSchema??{},itemType:i.target.value}}),children:p.map(i=>e.jsx("option",{value:i.value,children:i.label},i.value))})]})}return e.jsx(o.Box,{sx:{p:2.5},children:e.jsxs(o.Box,{sx:{border:"1.5px dashed #e2e8f0",borderRadius:"8px",py:3,textAlign:"center"},children:[e.jsxs(o.Typography,{sx:{fontSize:13,color:"#94a3b8"},children:["No extra configuration needed for ",e.jsx("strong",{children:a})," items."]}),e.jsx(o.Typography,{sx:{fontSize:11,color:"#cbd5e1",mt:.5},children:"Item placeholder and labels are set in the previous step."})]})})}return null}function je({field:l}){var p;const[s,d]=h.useState({}),a=l.id??l.name??"preview",r=[{value:3,label:"1/4"},{value:4,label:"1/3"},{value:6,label:"1/2"},{value:8,label:"2/3"},{value:12,label:"Full"}],t=l.colSpan&&l.colSpan<12?((p=r.find(i=>i.value===l.colSpan))==null?void 0:p.label)??l.colSpan:"Full";return e.jsxs(o.Box,{sx:{p:2.5},children:[e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",mb:2,px:1.25,py:.75,bgcolor:"#f0fdf4",border:"1px solid #bbf7d0",borderRadius:"7px"},children:[e.jsx(o.Typography,{sx:{fontSize:11,color:"#15803d",fontWeight:500,flex:1},children:"Live preview — interact to test the field"}),e.jsxs(o.Typography,{sx:{fontSize:11,color:"#64748b"},children:["Width: ",t]})]}),e.jsx(N.FlowForm,{schema:{layout:"flat",fields:[l]},initialValues:{[a]:l.type==="array"?[]:l.type==="object"||l.type==="schema"?{}:""},onSubmit:()=>{},conditionConfig:s,onConditionConfigChange:d})]})}function J({open:l,initial:s,onSave:d,onClose:a,editMode:r=!1}){const[t,p]=h.useState(1),[i,c]=h.useState(()=>s??X());function m(){c(s??X()),p(1)}const y=be(i),B=y?3:2,x=y?["Configure",me(i),"Preview"]:["Configure","Preview"],n=!!(i.id||i.name)&&!!i.type;function f(){p(k=>Math.min(k+1,B))}function u(){p(k=>Math.max(k-1,1))}function v(){d(i),a()}const g=t-1,w=t===B,T=y&&t===3||!y&&t===2;return e.jsxs(o.Dialog,{open:l,onClose:a,TransitionProps:{onEnter:m},maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",overflow:"hidden",display:"flex",flexDirection:"column",maxHeight:"90vh"}},children:[e.jsxs(o.Box,{sx:{px:2.5,pt:1.75,pb:0,borderBottom:"1px solid #e2e8f0",flexShrink:0},children:[e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",mb:1.5},children:[e.jsx(o.Typography,{sx:{fontSize:14,fontWeight:700,color:"#0f172a",flex:1},children:r?"Edit Field":"Add Field"}),e.jsx(o.IconButton,{size:"small",onClick:a,sx:{color:"#94a3b8"},children:e.jsx(S.MdClose,{size:17})})]}),e.jsx(o.Stepper,{activeStep:g,sx:{pb:1.5},children:x.map((k,R)=>e.jsx(o.Step,{completed:g>R,children:e.jsx(o.StepLabel,{children:k})},k))})]}),e.jsxs(o.Box,{sx:{flex:1,overflowY:"auto"},children:[t===1&&e.jsx(le,{field:i,onChange:c,onSave:f,onCancel:a,noFooter:!0}),t===2&&y&&e.jsx(ge,{field:i,onChange:c}),T&&e.jsx(je,{field:i})]}),e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",px:2.5,py:1.5,display:"flex",alignItems:"center",gap:1,flexShrink:0,bgcolor:"#f8fafc"},children:[t>1&&e.jsxs(o.Box,{component:"button",onClick:u,sx:{display:"flex",alignItems:"center",gap:.5,background:"none",border:"none",cursor:"pointer",fontSize:13,fontWeight:500,color:"#6c757d",px:0,"&:hover":{color:"#0f172a"}},children:[e.jsx(S.MdArrowBack,{size:14})," Back"]}),e.jsx(o.Box,{sx:{flex:1}}),e.jsx(o.Box,{component:"button",onClick:a,sx:{background:"none",border:"1px solid #dee2e6",cursor:"pointer",fontSize:13,fontWeight:500,px:2,py:.75,borderRadius:"7px",color:"#6c757d","&:hover":{bgcolor:"#f8f9fa"}},children:"Cancel"}),w?e.jsxs(o.Box,{component:"button",onClick:v,sx:{border:"none",cursor:"pointer",fontSize:13,fontWeight:600,px:2.5,py:.75,borderRadius:"7px",bgcolor:"#6366f1",color:"#fff",display:"flex",alignItems:"center",gap:.75,"&:hover":{bgcolor:"#4f46e5"}},children:[e.jsx(S.MdCheck,{size:15})," ",r?"Save changes":"Add field"]}):e.jsx(o.Box,{component:"button",onClick:f,disabled:!n,sx:{border:"none",cursor:n?"pointer":"not-allowed",fontSize:13,fontWeight:600,px:2.5,py:.75,borderRadius:"7px",bgcolor:n?"#6366f1":"#c7d2fe",color:"#fff","&:hover":{bgcolor:n?"#4f46e5":"#c7d2fe"}},children:"Next →"})]})]})}function ye({field:l,index:s,total:d,onEdit:a,onDelete:r,onMoveUp:t,onMoveDown:p}){const i=l.label||l.id||l.name||"Untitled",c=l.id??l.name??"";return e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",gap:1,px:1.5,py:1,border:"1px solid #e2e8f0",borderRadius:"8px",bgcolor:"#fff"},children:[e.jsxs(o.Box,{sx:{display:"flex",flexDirection:"column",gap:.25,color:"#cbd5e1"},children:[e.jsx(o.Box,{component:"button",onClick:t,disabled:s===0,sx:{background:"none",border:"none",p:0,cursor:s===0?"default":"pointer",color:s===0?"#e2e8f0":"#94a3b8",lineHeight:1,fontSize:10,"&:hover":{color:s===0?"#e2e8f0":"#475569"}},children:"▲"}),e.jsx(o.Box,{component:"button",onClick:p,disabled:s===d-1,sx:{background:"none",border:"none",p:0,cursor:s===d-1?"default":"pointer",color:s===d-1?"#e2e8f0":"#94a3b8",lineHeight:1,fontSize:10,"&:hover":{color:s===d-1?"#e2e8f0":"#475569"}},children:"▼"})]}),e.jsx(o.Box,{sx:{fontSize:10,fontWeight:700,px:.75,py:.2,borderRadius:"4px",bgcolor:"#eef2ff",color:"#6366f1",flexShrink:0},children:l.type}),e.jsxs(o.Box,{sx:{flex:1,minWidth:0},children:[e.jsxs(o.Typography,{sx:{fontSize:13,fontWeight:600,color:"#0f172a",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:[i,l.required&&e.jsx(o.Box,{component:"span",sx:{color:"#dc3545",ml:.25},children:"*"})]}),e.jsx(o.Typography,{sx:{fontSize:11,color:"#94a3b8",fontFamily:"monospace"},children:c})]}),e.jsx(o.Tooltip,{title:"Edit field",placement:"top",children:e.jsx(o.Box,{component:"button",onClick:a,sx:{background:"none",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,borderRadius:"6px",p:0,color:"#94a3b8","&:hover":{bgcolor:"#f1f5f9",color:"#475569"}},children:e.jsx(S.MdEdit,{size:14})})}),e.jsx(o.Tooltip,{title:"Remove field",placement:"top",children:e.jsx(o.Box,{component:"button",onClick:r,sx:{background:"none",border:"none",cursor:"pointer",display:"flex",alignItems:"center",justifyContent:"center",width:28,height:28,borderRadius:"6px",p:0,color:"#94a3b8","&:hover":{bgcolor:"#fee2e2",color:"#dc2626"}},children:e.jsx(S.MdDeleteOutline,{size:16})})})]})}function ve({open:l,value:s,onSave:d,onClose:a}){const[r,t]=h.useState(s),[p,i]=h.useState(null);function c(){t(s),i(null)}function m(f){t(u=>u.filter((v,g)=>g!==f))}function y(f,u){t(v=>{const g=[...v],w=f+u;return w<0||w>=g.length?v:([g[f],g[w]]=[g[w],g[f]],g)})}function B(f){p!==null&&(t(u=>{const v=[...u];return v[p]=f,v}),i(null))}function x(){d(r),a()}const n=JSON.stringify(r)!==JSON.stringify(s);return e.jsxs(e.Fragment,{children:[e.jsxs(o.Dialog,{open:l,onClose:a,TransitionProps:{onEnter:c},maxWidth:"sm",fullWidth:!0,PaperProps:{sx:{borderRadius:"12px",overflow:"hidden",display:"flex",flexDirection:"column",maxHeight:"85vh"}},children:[e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",px:2.5,py:1.75,borderBottom:"1px solid #e2e8f0",flexShrink:0},children:[e.jsxs(o.Box,{sx:{flex:1},children:[e.jsx(o.Typography,{sx:{fontSize:14,fontWeight:700,color:"#0f172a"},children:"Edit Schema"}),e.jsxs(o.Typography,{sx:{fontSize:11,color:"#94a3b8"},children:[r.length," field",r.length!==1?"s":""," defined"]})]}),e.jsx(o.IconButton,{size:"small",onClick:a,sx:{color:"#94a3b8"},children:e.jsx(S.MdClose,{size:17})})]}),e.jsx(o.Box,{sx:{flex:1,overflowY:"auto",p:2.5},children:r.length===0?e.jsx(o.Box,{sx:{border:"1.5px dashed rgba(0,0,0,0.12)",borderRadius:"8px",py:4,textAlign:"center"},children:e.jsx(o.Typography,{sx:{fontSize:13,color:"#94a3b8"},children:"No fields defined yet"})}):e.jsx(o.Box,{sx:{display:"flex",flexDirection:"column",gap:.75},children:r.map((f,u)=>e.jsx(ye,{field:f,index:u,total:r.length,onEdit:()=>i(u),onDelete:()=>m(u),onMoveUp:()=>y(u,-1),onMoveDown:()=>y(u,1)},`${f.id??f.name}-${u}`))})}),e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",px:2.5,py:1.5,display:"flex",alignItems:"center",gap:1,flexShrink:0,bgcolor:"#f8fafc"},children:[n?e.jsx(o.Typography,{sx:{fontSize:11,color:"#f59e0b",fontWeight:500,flex:1},children:"Unsaved changes"}):e.jsx(o.Box,{sx:{flex:1}}),e.jsx(o.Box,{component:"button",onClick:a,sx:{background:"none",border:"1px solid #dee2e6",cursor:"pointer",fontSize:13,fontWeight:500,px:2,py:.75,borderRadius:"7px",color:"#6c757d","&:hover":{bgcolor:"#f8f9fa"}},children:"Cancel"}),e.jsxs(o.Box,{component:"button",onClick:x,sx:{border:"none",cursor:"pointer",fontSize:13,fontWeight:600,px:2.5,py:.75,borderRadius:"7px",bgcolor:"#6366f1",color:"#fff",display:"flex",alignItems:"center",gap:.75,"&:hover":{bgcolor:"#4f46e5"}},children:[e.jsx(S.MdCheck,{size:15})," Done"]})]})]}),p!==null&&e.jsx(J,{open:p!==null,initial:r[p],onSave:B,onClose:()=>i(null),editMode:!0})]})}function se(l){const s={};for(const d of l){const a=d.id??d.name??"";a&&(d.type==="array"?s[a]=[]:d.type==="object"||d.type==="schema"?s[a]=se(d.children??[]):s[a]="")}return s}function W({value:l,onChange:s,suggestions:d,label:a="Fields",onPayload:r,validate:t=!0,onValidityChange:p,variableGroups:i,initialValues:c,initialFormulaConfig:m,initialConditionConfig:y}){const[B,x]=h.useState(!1),[n,f]=h.useState(!1),[u,v]=h.useState(null),[g,w]=h.useState(m??{}),[T,k]=h.useState(y??{}),R=h.useRef(c??{}),A=h.useMemo(()=>se(l),[l]),$=h.useMemo(()=>c&&Object.keys(c).length>0?{...A,...c}:A,[A,c]),M=h.useMemo(()=>t?N.buildValidationSchema(l):void 0,[t,l]);h.useEffect(()=>{r&&r({schema:l,formulaConfig:g,conditionConfig:T,conditionExpressions:N.serializeConditionExpressions(T),values:R.current,evaluationPayload:N.buildEvaluationPayload({values:R.current,conditionConfig:T})})},[T,g,l]);const V=h.useCallback(z=>{R.current=z,r&&r({schema:l,formulaConfig:g,conditionConfig:T,conditionExpressions:N.serializeConditionExpressions(T),values:z,evaluationPayload:N.buildEvaluationPayload({values:z,conditionConfig:T})})},[l,g,T,r]);function P(z){s([...l,z])}function q(z){if(!u)return;const{containerFieldId:D,tabId:H}=u,U=l.map(I=>{if((I.id??I.name)!==D)return I;const Y=I.tabs??[];return{...I,tabs:Y.map(O=>O.id===H?{...O,fields:[...O.fields??[],z]}:O)}});s(U),v(null)}function C(z,D,H){const U=l.map(I=>{if((I.id??I.name)!==z)return I;const Y=I.tabs??[];return{...I,tabs:Y.map(O=>O.id===D?{...O,fields:(O.fields??[]).filter((Be,te)=>te!==H)}:O)}});s(U)}const ne=h.useMemo(()=>({openAddFieldDialog:(z,D)=>v({containerFieldId:z,tabId:D}),removeFieldFromTab:C}),[l,s]),K=e.jsxs("div",{className:"schema-builder-root",children:[l.length>0&&e.jsx("div",{className:"schema-builder-header",children:e.jsxs("div",{className:"schema-builder-actions",children:[e.jsx(o.Tooltip,{title:"Edit schema",placement:"top",children:e.jsxs("button",{className:"sb-btn sb-btn-outline",onClick:()=>f(!0),children:[e.jsx(S.MdSettings,{size:13})," Edit Schema"]})}),e.jsx(o.Tooltip,{title:"Add a new field",placement:"top",children:e.jsxs("button",{className:"sb-btn sb-btn-primary",onClick:()=>x(!0),children:[e.jsx(S.MdAdd,{size:14})," Add Field"]})})]})}),l.length>0?e.jsx(N.TabsEditContext.Provider,{value:ne,children:e.jsx(N.FlowForm,{schema:{layout:"flat",fields:l},initialValues:$,onSubmit:()=>{},validationSchema:M,onValidityChange:p,onValuesChange:r?V:void 0,formulaConfig:g,onFormulaConfigChange:w,conditionConfig:T,onConditionConfigChange:k})}):e.jsxs("div",{className:"schema-builder-empty-state",children:[e.jsx(ie.FaWpforms,{size:40,className:"schema-builder-empty-icon"}),e.jsx("p",{className:"schema-builder-empty-title",children:"Tell us what fields should be in the list, and assign values to them."}),e.jsx("div",{className:"schema-builder-empty-actions",children:e.jsx("button",{className:"btn",onClick:()=>x(!0),children:"Add field"})})]}),e.jsx(J,{open:B,onSave:P,onClose:()=>x(!1)}),e.jsx(ve,{open:n,value:l,onSave:s,onClose:()=>f(!1)}),e.jsx(J,{open:!!u,onSave:q,onClose:()=>v(null)})]});return i?e.jsxs(N.VariablePickerProvider,{groups:i,children:[e.jsx(N.VariablePicker,{width:260,mode:"popover"}),K]}):K}function Ce({fields:l,onOpen:s}){return e.jsxs(o.Box,{sx:{border:"1px solid #e2e8f0",borderRadius:"8px",bgcolor:"#fff",overflow:"hidden"},children:[l.length>0?e.jsx(o.Box,{sx:{px:1.5,py:1.25,display:"flex",flexWrap:"wrap",gap:.5},children:l.map((d,a)=>{const r=d.id??d.name??"";return e.jsx(o.Tooltip,{title:`${d.type} · ${r}`,placement:"top",children:e.jsx(o.Chip,{label:d.label||r,size:"small",sx:{fontSize:11,fontWeight:500,height:22,bgcolor:"#f1f5f9",color:"#334155",border:"1px solid #e2e8f0","& .MuiChip-label":{px:1}}})},a)})}):e.jsx(o.Box,{sx:{px:1.5,py:1.5},children:e.jsx(o.Typography,{sx:{fontSize:12,color:"#94a3b8"},children:"No fields defined yet"})}),e.jsx(o.Divider,{sx:{borderColor:"#f1f5f9"}}),e.jsxs(o.Box,{onClick:s,sx:{display:"flex",alignItems:"center",gap:.75,px:1.5,py:1,cursor:"pointer","&:hover":{bgcolor:"#f8fafc"},transition:"background 0.12s"},children:[l.length===0?e.jsx(S.MdAdd,{size:14,color:"#6366f1"}):e.jsx(S.MdSettings,{size:13,color:"#6366f1"}),e.jsx(o.Typography,{sx:{fontSize:12,fontWeight:600,color:"#6366f1",flex:1},children:l.length===0?"Add fields":"Configure fields"}),e.jsx(S.MdArrowForward,{size:13,color:"#94a3b8"})]})]})}function Se({value:l,onChange:s,suggestions:d,onPayload:a,onDone:r,validate:t,onValidityChange:p,label:i="Fields",drawerTitle:c="Configure Fields",drawerWidth:m=580}){const[y,B]=h.useState(!1),[x,n]=h.useState({type:"list"}),[f,u]=h.useState(l),v=h.useRef(null),g=h.useRef(void 0),w=h.useRef(void 0),T=h.useRef(void 0),[k,R]=h.useState(null);function A(){u(l),n({type:"list"}),B(!0)}function $(){const C=v.current;C&&(g.current=C.values,w.current=C.formulaConfig,T.current=C.conditionConfig),s(f),B(!1),r==null||r(f,C)}function M(){const C=v.current;C&&(g.current=C.values,w.current=C.formulaConfig,T.current=C.conditionConfig),u(l),B(!1)}function V(){if(x.type!=="edit"||!k)return;const C=[...f];C[x.index]=k,u(C),n({type:"list"}),R(null)}function P(){n({type:"list"}),R(null)}const q=JSON.stringify(f)!==JSON.stringify(l);return x.type==="edit"&&f[x.index],e.jsxs(e.Fragment,{children:[e.jsxs(o.Box,{children:[e.jsx(o.Typography,{sx:{fontSize:12,fontWeight:700,color:"#64748b",textTransform:"uppercase",letterSpacing:.5,mb:.75},children:i}),e.jsx(Ce,{fields:l,onOpen:A})]}),e.jsxs(o.Drawer,{anchor:"right",open:y,onClose:M,PaperProps:{sx:{width:m,display:"flex",flexDirection:"column",boxShadow:"-4px 0 24px rgba(0,0,0,0.12)",overflow:"hidden"}},children:[e.jsxs(o.Box,{sx:{display:"flex",alignItems:"center",px:2,py:1.5,borderBottom:"1px solid #e2e8f0",flexShrink:0,gap:1},children:[x.type==="edit"&&e.jsx(o.Tooltip,{title:"Back to fields",placement:"bottom",children:e.jsx(o.IconButton,{size:"small",onClick:P,sx:{color:"#64748b"},children:e.jsx(S.MdArrowBack,{size:17})})}),e.jsxs(o.Box,{sx:{flex:1},children:[e.jsx(o.Typography,{sx:{fontSize:14,fontWeight:700,color:"#0f172a"},children:x.type==="edit"?(k==null?void 0:k.label)||(k==null?void 0:k.id)||"Edit field":c}),e.jsx(o.Typography,{sx:{fontSize:11,color:"#94a3b8"},children:x.type==="edit"?"Configure field properties":`${f.length} field${f.length!==1?"s":""} defined`})]}),x.type==="list"&&e.jsx(o.Tooltip,{title:"Close",placement:"bottom",children:e.jsx(o.IconButton,{size:"small",onClick:M,sx:{color:"#94a3b8"},children:e.jsx(S.MdClose,{size:17})})})]}),x.type==="list"&&e.jsxs(e.Fragment,{children:[e.jsx(o.Box,{sx:{flex:1,overflowY:"auto",p:2.5},children:e.jsx(W,{value:f,onChange:u,suggestions:d,onPayload:C=>{v.current=C,g.current=C.values,w.current=C.formulaConfig,T.current=C.conditionConfig,a==null||a(C)},validate:t,onValidityChange:p,label:i,initialValues:g.current,initialFormulaConfig:w.current,initialConditionConfig:T.current})}),e.jsxs(o.Box,{sx:{borderTop:"1px solid #e2e8f0",px:2.5,py:1.5,display:"flex",alignItems:"center",gap:1,flexShrink:0,bgcolor:"#f8fafc"},children:[q?e.jsx(o.Typography,{sx:{fontSize:11,color:"#f59e0b",fontWeight:500,flex:1},children:"Unsaved changes"}):e.jsx(o.Box,{sx:{flex:1}}),e.jsx(o.Box,{component:"button",onClick:M,sx:{background:"none",border:"1px solid #dee2e6",cursor:"pointer",fontSize:13,fontWeight:500,px:2,py:.75,borderRadius:"7px",color:"#6c757d","&:hover":{bgcolor:"#f8f9fa"}},children:"Cancel"}),e.jsxs(o.Box,{component:"button",onClick:$,sx:{border:"none",cursor:"pointer",fontSize:13,fontWeight:600,px:2.5,py:.75,borderRadius:"7px",bgcolor:"#6366f1",color:"#fff",display:"flex",alignItems:"center",gap:.75,"&:hover":{bgcolor:"#4f46e5"}},children:[e.jsx(S.MdCheck,{size:15})," Done"]})]})]}),x.type==="edit"&&k&&e.jsx(le,{field:k,onChange:R,onSave:V,onCancel:P})]})]})}exports.FIELD_TYPE_OPTIONS=Z;exports.SchemaBuilder=W;exports.SchemaBuilderDrawer=Se;exports.useFlowForm=ae;
|
package/dist/canvas.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./templateSkeletons-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("./templateSkeletons-Dks6kUHW.js"),t=require("./messages-O9Tw_XXR.js"),r=require("./bpmn-CcuE2X_Q.js"),e=require("./GatewayBranchEdge-D7QXHlOQ.js");exports.FlowForgeCanvas=o.FlowForgeCanvas;exports.SubWorkflowPreviewDrawer=o.SubWorkflowPreviewDrawer;exports.WorkflowCanvas=o.FlowForgeCanvas;exports.WorkflowExecutionHistory=o.WorkflowExecutionHistory;exports.WorkflowTemplateLibrary=o.WorkflowTemplateLibrary;exports.accessRequestSkeleton=o.accessRequestSkeleton;exports.offboardingSkeleton=o.offboardingSkeleton;exports.userOnboardingSkeleton=o.userOnboardingSkeleton;exports.webhookIntegrationSkeleton=o.webhookIntegrationSkeleton;exports.defaultFlowForgeMessages=t.defaultFlowForgeMessages;exports.loadWorkflowFromBpmn=r.loadWorkflowFromBpmn;exports.saveWorkflowToBpmn=r.saveWorkflowToBpmn;exports.ActionNode=e.ActionNode;exports.ApprovalNode=e.ApprovalNode;exports.EdgeWithPlusLabel=e.EdgeWithPlusLabel;exports.EndNode=e.EndNode;exports.FilterNode=e.FilterNode;exports.RestApiNode=e.RestApiNode;exports.StartNode=e.StartNode;exports.TriggerNode=e.TriggerNode;exports.WebhookTriggerNode=e.WebhookTriggerNode;exports.builtInNodeTypes=e.builtInNodeTypes;
|
package/dist/canvas.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as a, S as s, F as r, W as t, a as l, b as n, o as d, u as i, w as f } from "./templateSkeletons-
|
|
1
|
+
import { F as a, S as s, F as r, W as t, a as l, b as n, o as d, u as i, w as f } from "./templateSkeletons-BEaJiDBN.js";
|
|
2
2
|
import { d as w } from "./messages-CO299wPN.js";
|
|
3
3
|
import { l as p, s as b } from "./bpmn-CtfWDaOY.js";
|
|
4
4
|
import { A as F, b as N, E as m, c as u, F as S, R as T, S as c, T as v, W as x, e as A } from "./GatewayBranchEdge-BudlH-Ea.js";
|
package/dist/form.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-DNZlQp9z.js"),r=require("./SchemaBuilderDrawer-jbSe-O-O.js");require("react/jsx-runtime");require("react");require("@mui/material");require("react-icons/md");exports.DynamicFormRenderer=e.DynamicFormRenderer;exports.FF=e.FF;exports.FlowForgeRegistry=e.FlowForgeRegistry;exports.FlowForm=e.FlowForm;exports.FormulaInput=e.FormulaInput;exports.InfiniteSelectField=e.InfiniteSelectField;exports.TablePickerField=e.TablePickerField;exports.VariablePicker=e.VariablePicker;exports.VariablePickerProvider=e.VariablePickerProvider;exports.astHasRefs=e.astHasRefs;exports.astToTokens=e.astToTokens;exports.buildEvaluationPayload=e.buildEvaluationPayload;exports.buildFieldConfig=e.buildFieldConfig;exports.buildFormulaPath=e.buildFormulaPath;exports.buildSelectStyles=e.buildSelectStyles;exports.buildValidationSchema=e.buildValidationSchema;exports.errorTextStyle=e.errorTextStyle;exports.extractLabel=e.extractLabel;exports.fieldRegistry=e.fieldRegistry;exports.hasFormulaTokens=e.hasFormulaTokens;exports.helperTextStyle=e.helperTextStyle;exports.inputStyle=e.inputStyle;exports.isFormula=e.isFormula;exports.parseToAST=e.parseToAST;exports.serializeAST=e.serializeAST;exports.serializeASTAsConfig=e.serializeASTAsConfig;exports.serializeConditionExpressions=e.serializeConditionExpressions;exports.stripFormulaTokens=e.stripFormulaTokens;exports.tokenize=e.tokenize;exports.unwrapFormula=e.unwrapFormula;exports.useVariablePickerContext=e.useVariablePickerContext;exports.wrapFormula=e.wrapFormula;exports.FIELD_TYPE_OPTIONS=r.FIELD_TYPE_OPTIONS;exports.SchemaBuilder=r.SchemaBuilder;exports.SchemaBuilderDrawer=r.SchemaBuilderDrawer;exports.useFlowForm=r.useFlowForm;
|
package/dist/form.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as o, F as t, a as u, b as F, c as m, I as n, T as d, V as p, d as S, e as T, f as c, g as b, h as k, i as y, j as P, k as f, l as x, m as h, n as w, o as g, p as z, q as A, r as I, s as V, t as C, u as D, v as E, w as R, x as v, y as B, z as L, A as O } from "./index-
|
|
2
|
-
import { F as j, S as q, a as H, u as N } from "./SchemaBuilderDrawer-
|
|
1
|
+
import { D as o, F as t, a as u, b as F, c as m, I as n, T as d, V as p, d as S, e as T, f as c, g as b, h as k, i as y, j as P, k as f, l as x, m as h, n as w, o as g, p as z, q as A, r as I, s as V, t as C, u as D, v as E, w as R, x as v, y as B, z as L, A as O } from "./index-CxVqPygT.js";
|
|
2
|
+
import { F as j, S as q, a as H, u as N } from "./SchemaBuilderDrawer-D14R1O1M.js";
|
|
3
3
|
import "react/jsx-runtime";
|
|
4
4
|
import "react";
|
|
5
5
|
import "@mui/material";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const je=require("./index-z2pFjqNP.js"),b=require("react"),l=require("./index-B31-Y5uO.js"),ce=require("./index-CkjEllpd.js"),Sn=require("react/jsx-runtime"),kn=t=>{let{state:e}=t,r=e.doc.lineAt(e.selection.main.from),n=Ue(t.state,r.from);return n.line?xn(t):n.block?bn(t):!1};function He(t,e){return({state:r,dispatch:n})=>{if(r.readOnly)return!1;let i=t(e,r);return i?(n(r.update(i)),!0):!1}}const xn=He(Mn,0),Cn=He(yt,0),bn=He((t,e)=>yt(t,e,En(e)),0);function Ue(t,e){let r=t.languageDataAt("commentTokens",e,1);return r.length?r[0]:{}}const te=50;function vn(t,{open:e,close:r},n,i){let o=t.sliceDoc(n-te,n),s=t.sliceDoc(i,i+te),a=/\s*$/.exec(o)[0].length,c=/^\s*/.exec(s)[0].length,h=o.length-a;if(o.slice(h-e.length,h)==e&&s.slice(c,c+r.length)==r)return{open:{pos:n-a,margin:a&&1},close:{pos:i+c,margin:c&&1}};let u,f;i-n<=2*te?u=f=t.sliceDoc(n,i):(u=t.sliceDoc(n,n+te),f=t.sliceDoc(i-te,i));let d=/^\s*/.exec(u)[0].length,m=/\s*$/.exec(f)[0].length,g=f.length-m-r.length;return u.slice(d,d+e.length)==e&&f.slice(g,g+r.length)==r?{open:{pos:n+d+e.length,margin:/\s/.test(u.charAt(d+e.length))?1:0},close:{pos:i-m-r.length,margin:/\s/.test(f.charAt(g-1))?1:0}}:null}function En(t){let e=[];for(let r of t.selection.ranges){let n=t.doc.lineAt(r.from),i=r.to<=n.to?n:t.doc.lineAt(r.to);i.from>n.from&&i.from==r.to&&(i=r.to==n.to+1?n:t.doc.lineAt(r.to-1));let o=e.length-1;o>=0&&e[o].to>n.from?e[o].to=i.to:e.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:i.to})}return e}function yt(t,e,r=e.selection.ranges){let n=r.map(o=>Ue(e,o.from).block);if(!n.every(o=>o))return null;let i=r.map((o,s)=>vn(e,n[s],o.from,o.to));if(t!=2&&!i.every(o=>o))return{changes:e.changes(r.map((o,s)=>i[s]?[]:[{from:o.from,insert:n[s].open+" "},{from:o.to,insert:" "+n[s].close}]))};if(t!=1&&i.some(o=>o)){let o=[];for(let s=0,a;s<i.length;s++)if(a=i[s]){let c=n[s],{open:h,close:u}=a;o.push({from:h.pos-c.open.length,to:h.pos+h.margin},{from:u.pos-u.margin,to:u.pos+c.close.length})}return{changes:o}}return null}function Mn(t,e,r=e.selection.ranges){let n=[],i=-1;e:for(let{from:o,to:s}of r){let a=n.length,c=1e9,h;for(let u=o;u<=s;){let f=e.doc.lineAt(u);if(h==null&&(h=Ue(e,f.from).line,!h))continue e;if(f.from>i&&(o==s||s>f.from)){i=f.from;let d=/^\s*/.exec(f.text)[0].length,m=d==f.length,g=f.text.slice(d,d+h.length)==h?d:-1;d<f.text.length&&d<c&&(c=d),n.push({line:f,comment:g,token:h,indent:d,empty:m,single:!1})}u=f.to+1}if(c<1e9)for(let u=a;u<n.length;u++)n[u].indent<n[u].line.text.length&&(n[u].indent=c);n.length==a+1&&(n[a].single=!0)}if(t!=2&&n.some(o=>o.comment<0&&(!o.empty||o.single))){let o=[];for(let{line:a,token:c,indent:h,empty:u,single:f}of n)(f||!u)&&o.push({from:a.from+h,insert:c+" "});let s=e.changes(o);return{changes:s,selection:e.selection.map(s,1)}}else if(t!=1&&n.some(o=>o.comment>=0)){let o=[];for(let{line:s,comment:a,token:c}of n)if(a>=0){let h=s.from+a,u=h+c.length;s.text[u-s.from]==" "&&u++,o.push({from:h,to:u})}return{changes:o}}return null}const Pe=l.Annotation.define(),An=l.Annotation.define(),Dn=l.Facet.define(),St=l.Facet.define({combine(t){return l.combineConfig(t,{minDepth:100,newGroupDelay:500,joinToEvent:(e,r)=>r},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,r)=>(n,i)=>e(n,i)||r(n,i)})}}),kt=l.StateField.define({create(){return R.empty},update(t,e){let r=e.state.facet(St),n=e.annotation(Pe);if(n){let c=v.fromTransaction(e,n.selection),h=n.side,u=h==0?t.undone:t.done;return c?u=ge(u,u.length,r.minDepth,c):u=bt(u,e.startState.selection),new R(h==0?n.rest:u,h==0?u:n.rest)}let i=e.annotation(An);if((i=="full"||i=="before")&&(t=t.isolate()),e.annotation(l.Transaction.addToHistory)===!1)return e.changes.empty?t:t.addMapping(e.changes.desc);let o=v.fromTransaction(e),s=e.annotation(l.Transaction.time),a=e.annotation(l.Transaction.userEvent);return o?t=t.addChanges(o,s,a,r,e):e.selection&&(t=t.addSelection(e.startState.selection,s,a,r.newGroupDelay)),(i=="full"||i=="after")&&(t=t.isolate()),t},toJSON(t){return{done:t.done.map(e=>e.toJSON()),undone:t.undone.map(e=>e.toJSON())}},fromJSON(t){return new R(t.done.map(v.fromJSON),t.undone.map(v.fromJSON))}});function Bn(t={}){return[kt,St.of(t),l.EditorView.domEventHandlers({beforeinput(e,r){let n=e.inputType=="historyUndo"?xt:e.inputType=="historyRedo"?Ie:null;return n?(e.preventDefault(),n(r)):!1}})]}function Ce(t,e){return function({state:r,dispatch:n}){if(!e&&r.readOnly)return!1;let i=r.field(kt,!1);if(!i)return!1;let o=i.pop(t,r,e);return o?(n(o),!0):!1}}const xt=Ce(0,!1),Ie=Ce(1,!1),Ln=Ce(0,!0),wn=Ce(1,!0);class v{constructor(e,r,n,i,o){this.changes=e,this.effects=r,this.mapped=n,this.startSelection=i,this.selectionsAfter=o}setSelAfter(e){return new v(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,r,n;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(r=this.mapped)===null||r===void 0?void 0:r.toJSON(),startSelection:(n=this.startSelection)===null||n===void 0?void 0:n.toJSON(),selectionsAfter:this.selectionsAfter.map(i=>i.toJSON())}}static fromJSON(e){return new v(e.changes&&l.ChangeSet.fromJSON(e.changes),[],e.mapped&&l.ChangeDesc.fromJSON(e.mapped),e.startSelection&&l.EditorSelection.fromJSON(e.startSelection),e.selectionsAfter.map(l.EditorSelection.fromJSON))}static fromTransaction(e,r){let n=D;for(let i of e.startState.facet(Dn)){let o=i(e);o.length&&(n=n.concat(o))}return!n.length&&e.changes.empty?null:new v(e.changes.invert(e.startState.doc),n,void 0,r||e.startState.selection,D)}static selection(e){return new v(void 0,D,void 0,void 0,e)}}function ge(t,e,r,n){let i=e+1>r+20?e-r-1:0,o=t.slice(i,e);return o.push(n),o}function Tn(t,e){let r=[],n=!1;return t.iterChangedRanges((i,o)=>r.push(i,o)),e.iterChangedRanges((i,o,s,a)=>{for(let c=0;c<r.length;){let h=r[c++],u=r[c++];a>=h&&s<=u&&(n=!0)}}),n}function Rn(t,e){return t.ranges.length==e.ranges.length&&t.ranges.filter((r,n)=>r.empty!=e.ranges[n].empty).length===0}function Ct(t,e){return t.length?e.length?t.concat(e):t:e}const D=[],Pn=200;function bt(t,e){if(t.length){let r=t[t.length-1],n=r.selectionsAfter.slice(Math.max(0,r.selectionsAfter.length-Pn));return n.length&&n[n.length-1].eq(e)?t:(n.push(e),ge(t,t.length-1,1e9,r.setSelAfter(n)))}else return[v.selection([e])]}function In(t){let e=t[t.length-1],r=t.slice();return r[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),r}function Be(t,e){if(!t.length)return t;let r=t.length,n=D;for(;r;){let i=On(t[r-1],e,n);if(i.changes&&!i.changes.empty||i.effects.length){let o=t.slice(0,r);return o[r-1]=i,o}else e=i.mapped,r--,n=i.selectionsAfter}return n.length?[v.selection(n)]:D}function On(t,e,r){let n=Ct(t.selectionsAfter.length?t.selectionsAfter.map(a=>a.map(e)):D,r);if(!t.changes)return v.selection(n);let i=t.changes.map(e),o=e.mapDesc(t.changes,!0),s=t.mapped?t.mapped.composeDesc(o):o;return new v(i,l.StateEffect.mapEffects(t.effects,e),s,t.startSelection.map(o),n)}const Wn=/^(input\.type|delete)($|\.)/;class R{constructor(e,r,n=0,i=void 0){this.done=e,this.undone=r,this.prevTime=n,this.prevUserEvent=i}isolate(){return this.prevTime?new R(this.done,this.undone):this}addChanges(e,r,n,i,o){let s=this.done,a=s[s.length-1];return a&&a.changes&&!a.changes.empty&&e.changes&&(!n||Wn.test(n))&&(!a.selectionsAfter.length&&r-this.prevTime<i.newGroupDelay&&i.joinToEvent(o,Tn(a.changes,e.changes))||n=="input.type.compose")?s=ge(s,s.length-1,i.minDepth,new v(e.changes.compose(a.changes),Ct(l.StateEffect.mapEffects(e.effects,a.changes),a.effects),a.mapped,a.startSelection,D)):s=ge(s,s.length,i.minDepth,e),new R(s,D,r,n)}addSelection(e,r,n,i){let o=this.done.length?this.done[this.done.length-1].selectionsAfter:D;return o.length>0&&r-this.prevTime<i&&n==this.prevUserEvent&&n&&/^select($|\.)/.test(n)&&Rn(o[o.length-1],e)?this:new R(bt(this.done,e),this.undone,r,n)}addMapping(e){return new R(Be(this.done,e),Be(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,r,n){let i=e==0?this.done:this.undone;if(i.length==0)return null;let o=i[i.length-1],s=o.selectionsAfter[0]||(o.startSelection?o.startSelection.map(o.changes.invertedDesc,1):r.selection);if(n&&o.selectionsAfter.length)return r.update({selection:o.selectionsAfter[o.selectionsAfter.length-1],annotations:Pe.of({side:e,rest:In(i),selection:s}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(o.changes){let a=i.length==1?D:i.slice(0,i.length-1);return o.mapped&&(a=Be(a,o.mapped)),r.update({changes:o.changes,selection:o.startSelection,effects:o.effects,annotations:Pe.of({side:e,rest:a,selection:s}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}R.empty=new R(D,D);const Vn=[{key:"Mod-z",run:xt,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Ie,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Ie,preventDefault:!0},{key:"Mod-u",run:Ln,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:wn,preventDefault:!0}];function Y(t,e){return l.EditorSelection.create(t.ranges.map(e),t.mainIndex)}function L(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function w({state:t,dispatch:e},r){let n=Y(t.selection,r);return n.eq(t.selection,!0)?!1:(e(L(t,n)),!0)}function be(t,e){return l.EditorSelection.cursor(e?t.to:t.from)}function vt(t,e){return w(t,r=>r.empty?t.moveByChar(r,e):be(r,e))}function x(t){return t.textDirectionAt(t.state.selection.main.head)==l.Direction.LTR}const Et=t=>vt(t,!x(t)),Mt=t=>vt(t,x(t));function At(t,e){return w(t,r=>r.empty?t.moveByGroup(r,e):be(r,e))}const Fn=t=>At(t,!x(t)),Nn=t=>At(t,x(t));function qn(t,e,r){if(e.type.prop(r))return!0;let n=e.to-e.from;return n&&(n>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function ve(t,e,r){let n=l.syntaxTree(t).resolveInner(e.head),i=r?l.NodeProp.closedBy:l.NodeProp.openedBy;for(let c=e.head;;){let h=r?n.childAfter(c):n.childBefore(c);if(!h)break;qn(t,h,i)?n=h:c=r?h.to:h.from}let o=n.type.prop(i),s,a;return o&&(s=r?l.matchBrackets(t,n.from,1):l.matchBrackets(t,n.to,-1))&&s.matched?a=r?s.end.to:s.end.from:a=r?n.to:n.from,l.EditorSelection.cursor(a,r?-1:1)}const Hn=t=>w(t,e=>ve(t.state,e,!x(t))),Un=t=>w(t,e=>ve(t.state,e,x(t)));function Dt(t,e){return w(t,r=>{if(!r.empty)return be(r,e);let n=t.moveVertically(r,e);return n.head!=r.head?n:t.moveToLineBoundary(r,e)})}const Bt=t=>Dt(t,!1),Lt=t=>Dt(t,!0);function wt(t){let e=t.scrollDOM.clientHeight<t.scrollDOM.scrollHeight-2,r=0,n=0,i;if(e){for(let o of t.state.facet(l.EditorView.scrollMargins)){let s=o(t);s!=null&&s.top&&(r=Math.max(s==null?void 0:s.top,r)),s!=null&&s.bottom&&(n=Math.max(s==null?void 0:s.bottom,n))}i=t.scrollDOM.clientHeight-r-n}else i=(t.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:r,marginBottom:n,selfScroll:e,height:Math.max(t.defaultLineHeight,i-5)}}function Tt(t,e){let r=wt(t),{state:n}=t,i=Y(n.selection,s=>s.empty?t.moveVertically(s,e,r.height):be(s,e));if(i.eq(n.selection))return!1;let o;if(r.selfScroll){let s=t.coordsAtPos(n.selection.main.head),a=t.scrollDOM.getBoundingClientRect(),c=a.top+r.marginTop,h=a.bottom-r.marginBottom;s&&s.top>c&&s.bottom<h&&(o=l.EditorView.scrollIntoView(i.main.head,{y:"start",yMargin:s.top-c}))}return t.dispatch(L(n,i),{effects:o}),!0}const Qe=t=>Tt(t,!1),Oe=t=>Tt(t,!0);function V(t,e,r){let n=t.lineBlockAt(e.head),i=t.moveToLineBoundary(e,r);if(i.head==e.head&&i.head!=(r?n.to:n.from)&&(i=t.moveToLineBoundary(e,r,!1)),!r&&i.head==n.from&&n.length){let o=/^\s*/.exec(t.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;o&&e.head!=n.from+o&&(i=l.EditorSelection.cursor(n.from+o))}return i}const zn=t=>w(t,e=>V(t,e,!0)),Gn=t=>w(t,e=>V(t,e,!1)),Kn=t=>w(t,e=>V(t,e,!x(t))),$n=t=>w(t,e=>V(t,e,x(t))),Jn=t=>w(t,e=>l.EditorSelection.cursor(t.lineBlockAt(e.head).from,1)),_n=t=>w(t,e=>l.EditorSelection.cursor(t.lineBlockAt(e.head).to,-1));function jn(t,e,r){let n=!1,i=Y(t.selection,o=>{let s=l.matchBrackets(t,o.head,-1)||l.matchBrackets(t,o.head,1)||o.head>0&&l.matchBrackets(t,o.head-1,1)||o.head<t.doc.length&&l.matchBrackets(t,o.head+1,-1);if(!s||!s.end)return o;n=!0;let a=s.start.from==o.head?s.end.to:s.end.from;return l.EditorSelection.cursor(a)});return n?(e(L(t,i)),!0):!1}const Qn=({state:t,dispatch:e})=>jn(t,e);function B(t,e){let r=Y(t.state.selection,n=>{let i=e(n);return l.EditorSelection.range(n.anchor,i.head,i.goalColumn,i.bidiLevel||void 0,i.assoc)});return r.eq(t.state.selection)?!1:(t.dispatch(L(t.state,r)),!0)}function Rt(t,e){return B(t,r=>t.moveByChar(r,e))}const Pt=t=>Rt(t,!x(t)),It=t=>Rt(t,x(t));function Ot(t,e){return B(t,r=>t.moveByGroup(r,e))}const Yn=t=>Ot(t,!x(t)),Zn=t=>Ot(t,x(t)),Xn=t=>B(t,e=>ve(t.state,e,!x(t))),er=t=>B(t,e=>ve(t.state,e,x(t)));function Wt(t,e){return B(t,r=>t.moveVertically(r,e))}const Vt=t=>Wt(t,!1),Ft=t=>Wt(t,!0);function Nt(t,e){return B(t,r=>t.moveVertically(r,e,wt(t).height))}const Ye=t=>Nt(t,!1),Ze=t=>Nt(t,!0),tr=t=>B(t,e=>V(t,e,!0)),nr=t=>B(t,e=>V(t,e,!1)),rr=t=>B(t,e=>V(t,e,!x(t))),ir=t=>B(t,e=>V(t,e,x(t))),or=t=>B(t,e=>l.EditorSelection.cursor(t.lineBlockAt(e.head).from)),lr=t=>B(t,e=>l.EditorSelection.cursor(t.lineBlockAt(e.head).to)),Xe=({state:t,dispatch:e})=>(e(L(t,{anchor:0})),!0),et=({state:t,dispatch:e})=>(e(L(t,{anchor:t.doc.length})),!0),tt=({state:t,dispatch:e})=>(e(L(t,{anchor:t.selection.main.anchor,head:0})),!0),nt=({state:t,dispatch:e})=>(e(L(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0),sr=({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0),ar=({state:t,dispatch:e})=>{let r=Ee(t).map(({from:n,to:i})=>l.EditorSelection.range(n,Math.min(i+1,t.doc.length)));return e(t.update({selection:l.EditorSelection.create(r),userEvent:"select"})),!0},cr=({state:t,dispatch:e})=>{let r=Y(t.selection,n=>{let i=l.syntaxTree(t),o=i.resolveStack(n.from,1);if(n.empty){let s=i.resolveStack(n.from,-1);s.node.from>=o.node.from&&s.node.to<=o.node.to&&(o=s)}for(let s=o;s;s=s.next){let{node:a}=s;if((a.from<n.from&&a.to>=n.to||a.to>n.to&&a.from<=n.from)&&s.next)return l.EditorSelection.range(a.to,a.from)}return n});return r.eq(t.selection)?!1:(e(L(t,r)),!0)};function qt(t,e){let{state:r}=t,n=r.selection,i=r.selection.ranges.slice();for(let o of r.selection.ranges){let s=r.doc.lineAt(o.head);if(e?s.to<t.state.doc.length:s.from>0)for(let a=o;;){let c=t.moveVertically(a,e);if(c.head<s.from||c.head>s.to){i.some(h=>h.head==c.head)||i.push(c);break}else{if(c.head==a.head)break;a=c}}}return i.length==n.ranges.length?!1:(t.dispatch(L(r,l.EditorSelection.create(i,i.length-1))),!0)}const hr=t=>qt(t,!1),ur=t=>qt(t,!0),fr=({state:t,dispatch:e})=>{let r=t.selection,n=null;return r.ranges.length>1?n=l.EditorSelection.create([r.main]):r.main.empty||(n=l.EditorSelection.create([l.EditorSelection.cursor(r.main.head)])),n?(e(L(t,n)),!0):!1};function oe(t,e){if(t.state.readOnly)return!1;let r="delete.selection",{state:n}=t,i=n.changeByRange(o=>{let{from:s,to:a}=o;if(s==a){let c=e(o);c<s?(r="delete.backward",c=he(t,c,!1)):c>s&&(r="delete.forward",c=he(t,c,!0)),s=Math.min(s,c),a=Math.max(a,c)}else s=he(t,s,!1),a=he(t,a,!0);return s==a?{range:o}:{changes:{from:s,to:a},range:l.EditorSelection.cursor(s,s<o.head?-1:1)}});return i.changes.empty?!1:(t.dispatch(n.update(i,{scrollIntoView:!0,userEvent:r,effects:r=="delete.selection"?l.EditorView.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function he(t,e,r){if(t instanceof l.EditorView)for(let n of t.state.facet(l.EditorView.atomicRanges).map(i=>i(t)))n.between(e,e,(i,o)=>{i<e&&o>e&&(e=r?o:i)});return e}const Ht=(t,e,r)=>oe(t,n=>{let i=n.from,{state:o}=t,s=o.doc.lineAt(i),a,c;if(r&&!e&&i>s.from&&i<s.from+200&&!/[^ \t]/.test(a=s.text.slice(0,i-s.from))){if(a[a.length-1]==" ")return i-1;let h=l.countColumn(a,o.tabSize),u=h%l.getIndentUnit(o)||l.getIndentUnit(o);for(let f=0;f<u&&a[a.length-1-f]==" ";f++)i--;c=i}else c=l.findClusterBreak(s.text,i-s.from,e,e)+s.from,c==i&&s.number!=(e?o.doc.lines:1)?c+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(s.text.slice(c-s.from,i-s.from))&&(c=l.findClusterBreak(s.text,c-s.from,!1,!1)+s.from);return c}),We=t=>Ht(t,!1,!0),Ut=t=>Ht(t,!0,!1),zt=(t,e)=>oe(t,r=>{let n=r.head,{state:i}=t,o=i.doc.lineAt(n),s=i.charCategorizer(n);for(let a=null;;){if(n==(e?o.to:o.from)){n==r.head&&o.number!=(e?i.doc.lines:1)&&(n+=e?1:-1);break}let c=l.findClusterBreak(o.text,n-o.from,e)+o.from,h=o.text.slice(Math.min(n,c)-o.from,Math.max(n,c)-o.from),u=s(h);if(a!=null&&u!=a)break;(h!=" "||n!=r.head)&&(a=u),n=c}return n}),Gt=t=>zt(t,!1),dr=t=>zt(t,!0),mr=t=>oe(t,e=>{let r=t.lineBlockAt(e.head).to;return e.head<r?r:Math.min(t.state.doc.length,e.head+1)}),gr=t=>oe(t,e=>{let r=t.moveToLineBoundary(e,!1).head;return e.head>r?r:Math.max(0,e.head-1)}),pr=t=>oe(t,e=>{let r=t.moveToLineBoundary(e,!0).head;return e.head<r?r:Math.min(t.state.doc.length,e.head+1)}),yr=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:l.Text.of(["",""])},range:l.EditorSelection.cursor(n.from)}));return e(t.update(r,{scrollIntoView:!0,userEvent:"input"})),!0},Sr=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{if(!n.empty||n.from==0||n.from==t.doc.length)return{range:n};let i=n.from,o=t.doc.lineAt(i),s=i==o.from?i-1:l.findClusterBreak(o.text,i-o.from,!1)+o.from,a=i==o.to?i+1:l.findClusterBreak(o.text,i-o.from,!0)+o.from;return{changes:{from:s,to:a,insert:t.doc.slice(i,a).append(t.doc.slice(s,i))},range:l.EditorSelection.cursor(a)}});return r.changes.empty?!1:(e(t.update(r,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Ee(t){let e=[],r=-1;for(let n of t.selection.ranges){let i=t.doc.lineAt(n.from),o=t.doc.lineAt(n.to);if(!n.empty&&n.to==o.from&&(o=t.doc.lineAt(n.to-1)),r>=i.number){let s=e[e.length-1];s.to=o.to,s.ranges.push(n)}else e.push({from:i.from,to:o.to,ranges:[n]});r=o.number+1}return e}function Kt(t,e,r){if(t.readOnly)return!1;let n=[],i=[];for(let o of Ee(t)){if(r?o.to==t.doc.length:o.from==0)continue;let s=t.doc.lineAt(r?o.to+1:o.from-1),a=s.length+1;if(r){n.push({from:o.to,to:s.to},{from:o.from,insert:s.text+t.lineBreak});for(let c of o.ranges)i.push(l.EditorSelection.range(Math.min(t.doc.length,c.anchor+a),Math.min(t.doc.length,c.head+a)))}else{n.push({from:s.from,to:o.from},{from:o.to,insert:t.lineBreak+s.text});for(let c of o.ranges)i.push(l.EditorSelection.range(c.anchor-a,c.head-a))}}return n.length?(e(t.update({changes:n,scrollIntoView:!0,selection:l.EditorSelection.create(i,t.selection.mainIndex),userEvent:"move.line"})),!0):!1}const kr=({state:t,dispatch:e})=>Kt(t,e,!1),xr=({state:t,dispatch:e})=>Kt(t,e,!0);function $t(t,e,r){if(t.readOnly)return!1;let n=[];for(let o of Ee(t))r?n.push({from:o.from,insert:t.doc.slice(o.from,o.to)+t.lineBreak}):n.push({from:o.to,insert:t.lineBreak+t.doc.slice(o.from,o.to)});let i=t.changes(n);return e(t.update({changes:i,selection:t.selection.map(i,r?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Cr=({state:t,dispatch:e})=>$t(t,e,!1),br=({state:t,dispatch:e})=>$t(t,e,!0),vr=t=>{if(t.state.readOnly)return!1;let{state:e}=t,r=e.changes(Ee(e).map(({from:i,to:o})=>(i>0?i--:o<e.doc.length&&o++,{from:i,to:o}))),n=Y(e.selection,i=>{let o;if(t.lineWrapping){let s=t.lineBlockAt(i.head),a=t.coordsAtPos(i.head,i.assoc||1);a&&(o=s.bottom+t.documentTop-a.bottom+t.defaultLineHeight/2)}return t.moveVertically(i,!0,o)}).map(r);return t.dispatch({changes:r,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Er(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let r=l.syntaxTree(t).resolveInner(e),n=r.childBefore(e),i=r.childAfter(e),o;return n&&i&&n.to<=e&&i.from>=e&&(o=n.type.prop(l.NodeProp.closedBy))&&o.indexOf(i.name)>-1&&t.doc.lineAt(n.to).from==t.doc.lineAt(i.from).from&&!/\S/.test(t.sliceDoc(n.to,i.from))?{from:n.to,to:i.from}:null}const rt=Jt(!1),Mr=Jt(!0);function Jt(t){return({state:e,dispatch:r})=>{if(e.readOnly)return!1;let n=e.changeByRange(i=>{let{from:o,to:s}=i,a=e.doc.lineAt(o),c=!t&&o==s&&Er(e,o);t&&(o=s=(s<=a.to?a:e.doc.lineAt(s)).to);let h=new l.IndentContext(e,{simulateBreak:o,simulateDoubleBreak:!!c}),u=l.getIndentation(h,o);for(u==null&&(u=l.countColumn(/^\s*/.exec(e.doc.lineAt(o).text)[0],e.tabSize));s<a.to&&/\s/.test(a.text[s-a.from]);)s++;c?{from:o,to:s}=c:o>a.from&&o<a.from+100&&!/\S/.test(a.text.slice(0,o))&&(o=a.from);let f=["",l.indentString(e,u)];return c&&f.push(l.indentString(e,h.lineIndent(a.from,-1))),{changes:{from:o,to:s,insert:l.Text.of(f)},range:l.EditorSelection.cursor(o+1+f[1].length)}});return r(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0}}function ze(t,e){let r=-1;return t.changeByRange(n=>{let i=[];for(let s=n.from;s<=n.to;){let a=t.doc.lineAt(s);a.number>r&&(n.empty||n.to>a.from)&&(e(a,i,n),r=a.number),s=a.to+1}let o=t.changes(i);return{changes:i,range:l.EditorSelection.range(o.mapPos(n.anchor,1),o.mapPos(n.head,1))}})}const Ar=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let r=Object.create(null),n=new l.IndentContext(t,{overrideIndentation:o=>{let s=r[o];return s??-1}}),i=ze(t,(o,s,a)=>{let c=l.getIndentation(n,o.from);if(c==null)return;/\S/.test(o.text)||(c=0);let h=/^\s*/.exec(o.text)[0],u=l.indentString(t,c);(h!=u||a.from<o.from+h.length)&&(r[o.from]=c,s.push({from:o.from,to:o.from+h.length,insert:u}))});return i.changes.empty||e(t.update(i,{userEvent:"indent"})),!0},_t=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(ze(t,(r,n)=>{n.push({from:r.from,insert:t.facet(l.indentUnit)})}),{userEvent:"input.indent"})),!0),jt=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(ze(t,(r,n)=>{let i=/^\s*/.exec(r.text)[0];if(!i)return;let o=l.countColumn(i,t.tabSize),s=0,a=l.indentString(t,Math.max(0,o-l.getIndentUnit(t)));for(;s<i.length&&s<a.length&&i.charCodeAt(s)==a.charCodeAt(s);)s++;n.push({from:r.from+s,to:r.from+i.length,insert:a.slice(s)})}),{userEvent:"delete.dedent"})),!0),Dr=t=>(t.setTabFocusMode(),!0),Br=[{key:"Ctrl-b",run:Et,shift:Pt,preventDefault:!0},{key:"Ctrl-f",run:Mt,shift:It},{key:"Ctrl-p",run:Bt,shift:Vt},{key:"Ctrl-n",run:Lt,shift:Ft},{key:"Ctrl-a",run:Jn,shift:or},{key:"Ctrl-e",run:_n,shift:lr},{key:"Ctrl-d",run:Ut},{key:"Ctrl-h",run:We},{key:"Ctrl-k",run:mr},{key:"Ctrl-Alt-h",run:Gt},{key:"Ctrl-o",run:yr},{key:"Ctrl-t",run:Sr},{key:"Ctrl-v",run:Oe}],Lr=[{key:"ArrowLeft",run:Et,shift:Pt,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Fn,shift:Yn,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Kn,shift:rr,preventDefault:!0},{key:"ArrowRight",run:Mt,shift:It,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Nn,shift:Zn,preventDefault:!0},{mac:"Cmd-ArrowRight",run:$n,shift:ir,preventDefault:!0},{key:"ArrowUp",run:Bt,shift:Vt,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Xe,shift:tt},{mac:"Ctrl-ArrowUp",run:Qe,shift:Ye},{key:"ArrowDown",run:Lt,shift:Ft,preventDefault:!0},{mac:"Cmd-ArrowDown",run:et,shift:nt},{mac:"Ctrl-ArrowDown",run:Oe,shift:Ze},{key:"PageUp",run:Qe,shift:Ye},{key:"PageDown",run:Oe,shift:Ze},{key:"Home",run:Gn,shift:nr,preventDefault:!0},{key:"Mod-Home",run:Xe,shift:tt},{key:"End",run:zn,shift:tr,preventDefault:!0},{key:"Mod-End",run:et,shift:nt},{key:"Enter",run:rt,shift:rt},{key:"Mod-a",run:sr},{key:"Backspace",run:We,shift:We,preventDefault:!0},{key:"Delete",run:Ut,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Gt,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:dr,preventDefault:!0},{mac:"Mod-Backspace",run:gr,preventDefault:!0},{mac:"Mod-Delete",run:pr,preventDefault:!0}].concat(Br.map(t=>({mac:t.key,run:t.run,shift:t.shift}))),wr=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Hn,shift:Xn},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Un,shift:er},{key:"Alt-ArrowUp",run:kr},{key:"Shift-Alt-ArrowUp",run:Cr},{key:"Alt-ArrowDown",run:xr},{key:"Shift-Alt-ArrowDown",run:br},{key:"Mod-Alt-ArrowUp",run:hr},{key:"Mod-Alt-ArrowDown",run:ur},{key:"Escape",run:fr},{key:"Mod-Enter",run:Mr},{key:"Alt-l",mac:"Ctrl-l",run:ar},{key:"Mod-i",run:cr,preventDefault:!0},{key:"Mod-[",run:jt},{key:"Mod-]",run:_t},{key:"Mod-Alt-\\",run:Ar},{key:"Shift-Mod-k",run:vr},{key:"Shift-Mod-\\",run:Qn},{key:"Mod-/",run:kn},{key:"Alt-A",run:Cn},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Dr}].concat(Lr),Tr={key:"Tab",run:_t,shift:jt},it=typeof String.prototype.normalize=="function"?t=>t.normalize("NFKD"):t=>t;class Q{constructor(e,r,n=0,i=e.length,o,s){this.test=s,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(n,i),this.bufferStart=n,this.normalize=o?a=>o(it(a)):it,this.query=this.normalize(r)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return l.codePointAt(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let r=l.fromCodePoint(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=l.codePointSize(e);let i=this.normalize(r);if(i.length)for(let o=0,s=n,a=!0;;o++){let c=i.charCodeAt(o),h=this.match(c,s,a,this.bufferPos+this.bufferStart,o==i.length-1);if(h)return this.value=h,this;if(o==i.length-1)break;a&&o<r.length&&r.charCodeAt(o)==c?s++:a=!1}}}match(e,r,n,i,o){let s=null;for(let a=0;a<this.matches.length;){let c=this.matches[a],h=!1;this.query.charCodeAt(c.index)==e&&(c.index==this.query.length-1?s={from:c.from,to:i,precise:o&&c.precise}:(c.index++,h=!0)),h?a++:this.matches.splice(a,1)}return this.query.charCodeAt(0)==e&&(this.query.length==1?s={from:r,to:i,precise:n&&o}:this.matches.push({from:r,index:1,precise:n})),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(Q.prototype[Symbol.iterator]=function(){return this});const Qt={from:-1,to:-1,match:/.*/.exec(""),precise:!0},Ge="gm"+(/x/.unicode==null?"":"u");class Yt{constructor(e,r,n,i=0,o=e.length){if(this.text=e,this.to=o,this.curLine="",this.done=!1,this.value=Qt,/\\[sWDnr]|\n|\r|\[\^/.test(r))return new Zt(e,r,n,i,o);this.re=new RegExp(r,Ge+(n!=null&&n.ignoreCase?"i":"")),this.test=n==null?void 0:n.test,this.iter=e.iter();let s=e.lineAt(i);this.curLineStart=s.from,this.matchPos=pe(e,i),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let r=this.matchPos<=this.to&&this.re.exec(this.curLine);if(r){let n=this.curLineStart+r.index,i=n+r[0].length;if(this.matchPos=pe(this.text,i+(n==i?1:0)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<i||n>this.value.to)&&(!this.test||this.test(n,i,r)))return this.value={from:n,to:i,precise:!0,match:r},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const Le=new WeakMap;class j{constructor(e,r){this.from=e,this.text=r}get to(){return this.from+this.text.length}static get(e,r,n){let i=Le.get(e);if(!i||i.from>=n||i.to<=r){let a=new j(r,e.sliceString(r,n));return Le.set(e,a),a}if(i.from==r&&i.to==n)return i;let{text:o,from:s}=i;return s>r&&(o=e.sliceString(r,s)+o,s=r),i.to<n&&(o+=e.sliceString(i.to,n)),Le.set(e,new j(s,o)),new j(r,o.slice(r-s,n-s))}}class Zt{constructor(e,r,n,i,o){this.text=e,this.to=o,this.done=!1,this.value=Qt,this.matchPos=pe(e,i),this.re=new RegExp(r,Ge+(n!=null&&n.ignoreCase?"i":"")),this.test=n==null?void 0:n.test,this.flat=j.get(e,i,this.chunkEnd(i+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,r=this.re.exec(this.flat.text);if(r&&!r[0]&&r.index==e&&(this.re.lastIndex=e+1,r=this.re.exec(this.flat.text)),r){let n=this.flat.from+r.index,i=n+r[0].length;if((this.flat.to>=this.to||r.index+r[0].length<=this.flat.text.length-10)&&(!this.test||this.test(n,i,r)))return this.value={from:n,to:i,precise:!0,match:r},this.matchPos=pe(this.text,i+(n==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=j.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(Yt.prototype[Symbol.iterator]=Zt.prototype[Symbol.iterator]=function(){return this});function Rr(t){try{return new RegExp(t,Ge),!0}catch{return!1}}function pe(t,e){if(e>=t.length)return e;let r=t.lineAt(e),n;for(;e<r.to&&(n=r.text.charCodeAt(e-r.from))>=56320&&n<57344;)e++;return e}const Pr=t=>{let{state:e}=t,r=String(e.doc.lineAt(t.state.selection.main.head).number),{close:n,result:i}=l.showDialog(t,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:r},focus:!0,submitLabel:e.phrase("go")});return i.then(o=>{let s=o&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(o.elements.line.value);if(!s){t.dispatch({effects:n});return}let a=e.doc.lineAt(e.selection.main.head),[,c,h,u,f]=s,d=u?+u.slice(1):0,m=h?+h:a.number;if(h&&f){let y=m/100;c&&(y=y*(c=="-"?-1:1)+a.number/e.doc.lines),m=Math.round(e.doc.lines*y)}else h&&c&&(m=m*(c=="-"?-1:1)+a.number);let g=e.doc.line(Math.max(1,Math.min(e.doc.lines,m))),S=l.EditorSelection.cursor(g.from+Math.max(0,Math.min(d,g.length)));t.dispatch({effects:[n,l.EditorView.scrollIntoView(S.from,{y:"center"})],selection:S})}),!0},Ir={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Or=l.Facet.define({combine(t){return l.combineConfig(t,Ir,{highlightWordAroundCursor:(e,r)=>e||r,minSelectionLength:Math.min,maxMatches:Math.min})}});function Wr(t){return[Hr,qr]}const Vr=l.Decoration.mark({class:"cm-selectionMatch"}),Fr=l.Decoration.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function ot(t,e,r,n){return(r==0||t(e.sliceDoc(r-1,r))!=l.CharCategory.Word)&&(n==e.doc.length||t(e.sliceDoc(n,n+1))!=l.CharCategory.Word)}function Nr(t,e,r,n){return t(e.sliceDoc(r,r+1))==l.CharCategory.Word&&t(e.sliceDoc(n-1,n))==l.CharCategory.Word}const qr=l.ViewPlugin.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(Or),{state:r}=t,n=r.selection;if(n.ranges.length>1)return l.Decoration.none;let i=n.main,o,s=null;if(i.empty){if(!e.highlightWordAroundCursor)return l.Decoration.none;let c=r.wordAt(i.head);if(!c)return l.Decoration.none;s=r.charCategorizer(i.head),o=r.sliceDoc(c.from,c.to)}else{let c=i.to-i.from;if(c<e.minSelectionLength||c>200)return l.Decoration.none;if(e.wholeWords){if(o=r.sliceDoc(i.from,i.to),s=r.charCategorizer(i.head),!(ot(s,r,i.from,i.to)&&Nr(s,r,i.from,i.to)))return l.Decoration.none}else if(o=r.sliceDoc(i.from,i.to),!o)return l.Decoration.none}let a=[];for(let c of t.visibleRanges){let h=new Q(r.doc,o,c.from,c.to);for(;!h.next().done;){let{from:u,to:f}=h.value;if((!s||ot(s,r,u,f))&&(i.empty&&u<=i.from&&f>=i.to?a.push(Fr.range(u,f)):(u>=i.to||f<=i.from)&&a.push(Vr.range(u,f)),a.length>e.maxMatches))return l.Decoration.none}}return l.Decoration.set(a)}},{decorations:t=>t.decorations}),Hr=l.EditorView.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),Ur=({state:t,dispatch:e})=>{let{selection:r}=t,n=l.EditorSelection.create(r.ranges.map(i=>t.wordAt(i.head)||l.EditorSelection.cursor(i.head)),r.mainIndex);return n.eq(r)?!1:(e(t.update({selection:n})),!0)};function zr(t,e){let{main:r,ranges:n}=t.selection,i=t.wordAt(r.head),o=i&&i.from==r.from&&i.to==r.to;for(let s=!1,a=new Q(t.doc,e,n[n.length-1].to);;)if(a.next(),a.done){if(s)return null;a=new Q(t.doc,e,0,Math.max(0,n[n.length-1].from-1)),s=!0}else{if(s&&n.some(c=>c.from==a.value.from))continue;if(o){let c=t.wordAt(a.value.from);if(!c||c.from!=a.value.from||c.to!=a.value.to)continue}return a.value}}const Gr=({state:t,dispatch:e})=>{let{ranges:r}=t.selection;if(r.some(o=>o.from===o.to))return Ur({state:t,dispatch:e});let n=t.sliceDoc(r[0].from,r[0].to);if(t.selection.ranges.some(o=>t.sliceDoc(o.from,o.to)!=n))return!1;let i=zr(t,n);return i?(e(t.update({selection:t.selection.addRange(l.EditorSelection.range(i.from,i.to),!1),effects:l.EditorView.scrollIntoView(i.to)})),!0):!1},Z=l.Facet.define({combine(t){return l.combineConfig(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new ii(e),scrollToMatch:e=>l.EditorView.scrollIntoView(e)})}});class Xt{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||Rr(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(r,n)=>n=="n"?`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const je=require("./index-DNZlQp9z.js"),b=require("react"),l=require("./index-B31-Y5uO.js"),ce=require("./index-CkjEllpd.js"),Sn=require("react/jsx-runtime"),kn=t=>{let{state:e}=t,r=e.doc.lineAt(e.selection.main.from),n=Ue(t.state,r.from);return n.line?xn(t):n.block?bn(t):!1};function He(t,e){return({state:r,dispatch:n})=>{if(r.readOnly)return!1;let i=t(e,r);return i?(n(r.update(i)),!0):!1}}const xn=He(Mn,0),Cn=He(yt,0),bn=He((t,e)=>yt(t,e,En(e)),0);function Ue(t,e){let r=t.languageDataAt("commentTokens",e,1);return r.length?r[0]:{}}const te=50;function vn(t,{open:e,close:r},n,i){let o=t.sliceDoc(n-te,n),s=t.sliceDoc(i,i+te),a=/\s*$/.exec(o)[0].length,c=/^\s*/.exec(s)[0].length,h=o.length-a;if(o.slice(h-e.length,h)==e&&s.slice(c,c+r.length)==r)return{open:{pos:n-a,margin:a&&1},close:{pos:i+c,margin:c&&1}};let u,f;i-n<=2*te?u=f=t.sliceDoc(n,i):(u=t.sliceDoc(n,n+te),f=t.sliceDoc(i-te,i));let d=/^\s*/.exec(u)[0].length,m=/\s*$/.exec(f)[0].length,g=f.length-m-r.length;return u.slice(d,d+e.length)==e&&f.slice(g,g+r.length)==r?{open:{pos:n+d+e.length,margin:/\s/.test(u.charAt(d+e.length))?1:0},close:{pos:i-m-r.length,margin:/\s/.test(f.charAt(g-1))?1:0}}:null}function En(t){let e=[];for(let r of t.selection.ranges){let n=t.doc.lineAt(r.from),i=r.to<=n.to?n:t.doc.lineAt(r.to);i.from>n.from&&i.from==r.to&&(i=r.to==n.to+1?n:t.doc.lineAt(r.to-1));let o=e.length-1;o>=0&&e[o].to>n.from?e[o].to=i.to:e.push({from:n.from+/^\s*/.exec(n.text)[0].length,to:i.to})}return e}function yt(t,e,r=e.selection.ranges){let n=r.map(o=>Ue(e,o.from).block);if(!n.every(o=>o))return null;let i=r.map((o,s)=>vn(e,n[s],o.from,o.to));if(t!=2&&!i.every(o=>o))return{changes:e.changes(r.map((o,s)=>i[s]?[]:[{from:o.from,insert:n[s].open+" "},{from:o.to,insert:" "+n[s].close}]))};if(t!=1&&i.some(o=>o)){let o=[];for(let s=0,a;s<i.length;s++)if(a=i[s]){let c=n[s],{open:h,close:u}=a;o.push({from:h.pos-c.open.length,to:h.pos+h.margin},{from:u.pos-u.margin,to:u.pos+c.close.length})}return{changes:o}}return null}function Mn(t,e,r=e.selection.ranges){let n=[],i=-1;e:for(let{from:o,to:s}of r){let a=n.length,c=1e9,h;for(let u=o;u<=s;){let f=e.doc.lineAt(u);if(h==null&&(h=Ue(e,f.from).line,!h))continue e;if(f.from>i&&(o==s||s>f.from)){i=f.from;let d=/^\s*/.exec(f.text)[0].length,m=d==f.length,g=f.text.slice(d,d+h.length)==h?d:-1;d<f.text.length&&d<c&&(c=d),n.push({line:f,comment:g,token:h,indent:d,empty:m,single:!1})}u=f.to+1}if(c<1e9)for(let u=a;u<n.length;u++)n[u].indent<n[u].line.text.length&&(n[u].indent=c);n.length==a+1&&(n[a].single=!0)}if(t!=2&&n.some(o=>o.comment<0&&(!o.empty||o.single))){let o=[];for(let{line:a,token:c,indent:h,empty:u,single:f}of n)(f||!u)&&o.push({from:a.from+h,insert:c+" "});let s=e.changes(o);return{changes:s,selection:e.selection.map(s,1)}}else if(t!=1&&n.some(o=>o.comment>=0)){let o=[];for(let{line:s,comment:a,token:c}of n)if(a>=0){let h=s.from+a,u=h+c.length;s.text[u-s.from]==" "&&u++,o.push({from:h,to:u})}return{changes:o}}return null}const Pe=l.Annotation.define(),An=l.Annotation.define(),Dn=l.Facet.define(),St=l.Facet.define({combine(t){return l.combineConfig(t,{minDepth:100,newGroupDelay:500,joinToEvent:(e,r)=>r},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,r)=>(n,i)=>e(n,i)||r(n,i)})}}),kt=l.StateField.define({create(){return R.empty},update(t,e){let r=e.state.facet(St),n=e.annotation(Pe);if(n){let c=v.fromTransaction(e,n.selection),h=n.side,u=h==0?t.undone:t.done;return c?u=ge(u,u.length,r.minDepth,c):u=bt(u,e.startState.selection),new R(h==0?n.rest:u,h==0?u:n.rest)}let i=e.annotation(An);if((i=="full"||i=="before")&&(t=t.isolate()),e.annotation(l.Transaction.addToHistory)===!1)return e.changes.empty?t:t.addMapping(e.changes.desc);let o=v.fromTransaction(e),s=e.annotation(l.Transaction.time),a=e.annotation(l.Transaction.userEvent);return o?t=t.addChanges(o,s,a,r,e):e.selection&&(t=t.addSelection(e.startState.selection,s,a,r.newGroupDelay)),(i=="full"||i=="after")&&(t=t.isolate()),t},toJSON(t){return{done:t.done.map(e=>e.toJSON()),undone:t.undone.map(e=>e.toJSON())}},fromJSON(t){return new R(t.done.map(v.fromJSON),t.undone.map(v.fromJSON))}});function Bn(t={}){return[kt,St.of(t),l.EditorView.domEventHandlers({beforeinput(e,r){let n=e.inputType=="historyUndo"?xt:e.inputType=="historyRedo"?Ie:null;return n?(e.preventDefault(),n(r)):!1}})]}function Ce(t,e){return function({state:r,dispatch:n}){if(!e&&r.readOnly)return!1;let i=r.field(kt,!1);if(!i)return!1;let o=i.pop(t,r,e);return o?(n(o),!0):!1}}const xt=Ce(0,!1),Ie=Ce(1,!1),Ln=Ce(0,!0),wn=Ce(1,!0);class v{constructor(e,r,n,i,o){this.changes=e,this.effects=r,this.mapped=n,this.startSelection=i,this.selectionsAfter=o}setSelAfter(e){return new v(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,r,n;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(r=this.mapped)===null||r===void 0?void 0:r.toJSON(),startSelection:(n=this.startSelection)===null||n===void 0?void 0:n.toJSON(),selectionsAfter:this.selectionsAfter.map(i=>i.toJSON())}}static fromJSON(e){return new v(e.changes&&l.ChangeSet.fromJSON(e.changes),[],e.mapped&&l.ChangeDesc.fromJSON(e.mapped),e.startSelection&&l.EditorSelection.fromJSON(e.startSelection),e.selectionsAfter.map(l.EditorSelection.fromJSON))}static fromTransaction(e,r){let n=D;for(let i of e.startState.facet(Dn)){let o=i(e);o.length&&(n=n.concat(o))}return!n.length&&e.changes.empty?null:new v(e.changes.invert(e.startState.doc),n,void 0,r||e.startState.selection,D)}static selection(e){return new v(void 0,D,void 0,void 0,e)}}function ge(t,e,r,n){let i=e+1>r+20?e-r-1:0,o=t.slice(i,e);return o.push(n),o}function Tn(t,e){let r=[],n=!1;return t.iterChangedRanges((i,o)=>r.push(i,o)),e.iterChangedRanges((i,o,s,a)=>{for(let c=0;c<r.length;){let h=r[c++],u=r[c++];a>=h&&s<=u&&(n=!0)}}),n}function Rn(t,e){return t.ranges.length==e.ranges.length&&t.ranges.filter((r,n)=>r.empty!=e.ranges[n].empty).length===0}function Ct(t,e){return t.length?e.length?t.concat(e):t:e}const D=[],Pn=200;function bt(t,e){if(t.length){let r=t[t.length-1],n=r.selectionsAfter.slice(Math.max(0,r.selectionsAfter.length-Pn));return n.length&&n[n.length-1].eq(e)?t:(n.push(e),ge(t,t.length-1,1e9,r.setSelAfter(n)))}else return[v.selection([e])]}function In(t){let e=t[t.length-1],r=t.slice();return r[t.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),r}function Be(t,e){if(!t.length)return t;let r=t.length,n=D;for(;r;){let i=On(t[r-1],e,n);if(i.changes&&!i.changes.empty||i.effects.length){let o=t.slice(0,r);return o[r-1]=i,o}else e=i.mapped,r--,n=i.selectionsAfter}return n.length?[v.selection(n)]:D}function On(t,e,r){let n=Ct(t.selectionsAfter.length?t.selectionsAfter.map(a=>a.map(e)):D,r);if(!t.changes)return v.selection(n);let i=t.changes.map(e),o=e.mapDesc(t.changes,!0),s=t.mapped?t.mapped.composeDesc(o):o;return new v(i,l.StateEffect.mapEffects(t.effects,e),s,t.startSelection.map(o),n)}const Wn=/^(input\.type|delete)($|\.)/;class R{constructor(e,r,n=0,i=void 0){this.done=e,this.undone=r,this.prevTime=n,this.prevUserEvent=i}isolate(){return this.prevTime?new R(this.done,this.undone):this}addChanges(e,r,n,i,o){let s=this.done,a=s[s.length-1];return a&&a.changes&&!a.changes.empty&&e.changes&&(!n||Wn.test(n))&&(!a.selectionsAfter.length&&r-this.prevTime<i.newGroupDelay&&i.joinToEvent(o,Tn(a.changes,e.changes))||n=="input.type.compose")?s=ge(s,s.length-1,i.minDepth,new v(e.changes.compose(a.changes),Ct(l.StateEffect.mapEffects(e.effects,a.changes),a.effects),a.mapped,a.startSelection,D)):s=ge(s,s.length,i.minDepth,e),new R(s,D,r,n)}addSelection(e,r,n,i){let o=this.done.length?this.done[this.done.length-1].selectionsAfter:D;return o.length>0&&r-this.prevTime<i&&n==this.prevUserEvent&&n&&/^select($|\.)/.test(n)&&Rn(o[o.length-1],e)?this:new R(bt(this.done,e),this.undone,r,n)}addMapping(e){return new R(Be(this.done,e),Be(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,r,n){let i=e==0?this.done:this.undone;if(i.length==0)return null;let o=i[i.length-1],s=o.selectionsAfter[0]||(o.startSelection?o.startSelection.map(o.changes.invertedDesc,1):r.selection);if(n&&o.selectionsAfter.length)return r.update({selection:o.selectionsAfter[o.selectionsAfter.length-1],annotations:Pe.of({side:e,rest:In(i),selection:s}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(o.changes){let a=i.length==1?D:i.slice(0,i.length-1);return o.mapped&&(a=Be(a,o.mapped)),r.update({changes:o.changes,selection:o.startSelection,effects:o.effects,annotations:Pe.of({side:e,rest:a,selection:s}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}R.empty=new R(D,D);const Vn=[{key:"Mod-z",run:xt,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:Ie,preventDefault:!0},{linux:"Ctrl-Shift-z",run:Ie,preventDefault:!0},{key:"Mod-u",run:Ln,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:wn,preventDefault:!0}];function Y(t,e){return l.EditorSelection.create(t.ranges.map(e),t.mainIndex)}function L(t,e){return t.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function w({state:t,dispatch:e},r){let n=Y(t.selection,r);return n.eq(t.selection,!0)?!1:(e(L(t,n)),!0)}function be(t,e){return l.EditorSelection.cursor(e?t.to:t.from)}function vt(t,e){return w(t,r=>r.empty?t.moveByChar(r,e):be(r,e))}function x(t){return t.textDirectionAt(t.state.selection.main.head)==l.Direction.LTR}const Et=t=>vt(t,!x(t)),Mt=t=>vt(t,x(t));function At(t,e){return w(t,r=>r.empty?t.moveByGroup(r,e):be(r,e))}const Fn=t=>At(t,!x(t)),Nn=t=>At(t,x(t));function qn(t,e,r){if(e.type.prop(r))return!0;let n=e.to-e.from;return n&&(n>2||/[^\s,.;:]/.test(t.sliceDoc(e.from,e.to)))||e.firstChild}function ve(t,e,r){let n=l.syntaxTree(t).resolveInner(e.head),i=r?l.NodeProp.closedBy:l.NodeProp.openedBy;for(let c=e.head;;){let h=r?n.childAfter(c):n.childBefore(c);if(!h)break;qn(t,h,i)?n=h:c=r?h.to:h.from}let o=n.type.prop(i),s,a;return o&&(s=r?l.matchBrackets(t,n.from,1):l.matchBrackets(t,n.to,-1))&&s.matched?a=r?s.end.to:s.end.from:a=r?n.to:n.from,l.EditorSelection.cursor(a,r?-1:1)}const Hn=t=>w(t,e=>ve(t.state,e,!x(t))),Un=t=>w(t,e=>ve(t.state,e,x(t)));function Dt(t,e){return w(t,r=>{if(!r.empty)return be(r,e);let n=t.moveVertically(r,e);return n.head!=r.head?n:t.moveToLineBoundary(r,e)})}const Bt=t=>Dt(t,!1),Lt=t=>Dt(t,!0);function wt(t){let e=t.scrollDOM.clientHeight<t.scrollDOM.scrollHeight-2,r=0,n=0,i;if(e){for(let o of t.state.facet(l.EditorView.scrollMargins)){let s=o(t);s!=null&&s.top&&(r=Math.max(s==null?void 0:s.top,r)),s!=null&&s.bottom&&(n=Math.max(s==null?void 0:s.bottom,n))}i=t.scrollDOM.clientHeight-r-n}else i=(t.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:r,marginBottom:n,selfScroll:e,height:Math.max(t.defaultLineHeight,i-5)}}function Tt(t,e){let r=wt(t),{state:n}=t,i=Y(n.selection,s=>s.empty?t.moveVertically(s,e,r.height):be(s,e));if(i.eq(n.selection))return!1;let o;if(r.selfScroll){let s=t.coordsAtPos(n.selection.main.head),a=t.scrollDOM.getBoundingClientRect(),c=a.top+r.marginTop,h=a.bottom-r.marginBottom;s&&s.top>c&&s.bottom<h&&(o=l.EditorView.scrollIntoView(i.main.head,{y:"start",yMargin:s.top-c}))}return t.dispatch(L(n,i),{effects:o}),!0}const Qe=t=>Tt(t,!1),Oe=t=>Tt(t,!0);function V(t,e,r){let n=t.lineBlockAt(e.head),i=t.moveToLineBoundary(e,r);if(i.head==e.head&&i.head!=(r?n.to:n.from)&&(i=t.moveToLineBoundary(e,r,!1)),!r&&i.head==n.from&&n.length){let o=/^\s*/.exec(t.state.sliceDoc(n.from,Math.min(n.from+100,n.to)))[0].length;o&&e.head!=n.from+o&&(i=l.EditorSelection.cursor(n.from+o))}return i}const zn=t=>w(t,e=>V(t,e,!0)),Gn=t=>w(t,e=>V(t,e,!1)),Kn=t=>w(t,e=>V(t,e,!x(t))),$n=t=>w(t,e=>V(t,e,x(t))),Jn=t=>w(t,e=>l.EditorSelection.cursor(t.lineBlockAt(e.head).from,1)),_n=t=>w(t,e=>l.EditorSelection.cursor(t.lineBlockAt(e.head).to,-1));function jn(t,e,r){let n=!1,i=Y(t.selection,o=>{let s=l.matchBrackets(t,o.head,-1)||l.matchBrackets(t,o.head,1)||o.head>0&&l.matchBrackets(t,o.head-1,1)||o.head<t.doc.length&&l.matchBrackets(t,o.head+1,-1);if(!s||!s.end)return o;n=!0;let a=s.start.from==o.head?s.end.to:s.end.from;return l.EditorSelection.cursor(a)});return n?(e(L(t,i)),!0):!1}const Qn=({state:t,dispatch:e})=>jn(t,e);function B(t,e){let r=Y(t.state.selection,n=>{let i=e(n);return l.EditorSelection.range(n.anchor,i.head,i.goalColumn,i.bidiLevel||void 0,i.assoc)});return r.eq(t.state.selection)?!1:(t.dispatch(L(t.state,r)),!0)}function Rt(t,e){return B(t,r=>t.moveByChar(r,e))}const Pt=t=>Rt(t,!x(t)),It=t=>Rt(t,x(t));function Ot(t,e){return B(t,r=>t.moveByGroup(r,e))}const Yn=t=>Ot(t,!x(t)),Zn=t=>Ot(t,x(t)),Xn=t=>B(t,e=>ve(t.state,e,!x(t))),er=t=>B(t,e=>ve(t.state,e,x(t)));function Wt(t,e){return B(t,r=>t.moveVertically(r,e))}const Vt=t=>Wt(t,!1),Ft=t=>Wt(t,!0);function Nt(t,e){return B(t,r=>t.moveVertically(r,e,wt(t).height))}const Ye=t=>Nt(t,!1),Ze=t=>Nt(t,!0),tr=t=>B(t,e=>V(t,e,!0)),nr=t=>B(t,e=>V(t,e,!1)),rr=t=>B(t,e=>V(t,e,!x(t))),ir=t=>B(t,e=>V(t,e,x(t))),or=t=>B(t,e=>l.EditorSelection.cursor(t.lineBlockAt(e.head).from)),lr=t=>B(t,e=>l.EditorSelection.cursor(t.lineBlockAt(e.head).to)),Xe=({state:t,dispatch:e})=>(e(L(t,{anchor:0})),!0),et=({state:t,dispatch:e})=>(e(L(t,{anchor:t.doc.length})),!0),tt=({state:t,dispatch:e})=>(e(L(t,{anchor:t.selection.main.anchor,head:0})),!0),nt=({state:t,dispatch:e})=>(e(L(t,{anchor:t.selection.main.anchor,head:t.doc.length})),!0),sr=({state:t,dispatch:e})=>(e(t.update({selection:{anchor:0,head:t.doc.length},userEvent:"select"})),!0),ar=({state:t,dispatch:e})=>{let r=Ee(t).map(({from:n,to:i})=>l.EditorSelection.range(n,Math.min(i+1,t.doc.length)));return e(t.update({selection:l.EditorSelection.create(r),userEvent:"select"})),!0},cr=({state:t,dispatch:e})=>{let r=Y(t.selection,n=>{let i=l.syntaxTree(t),o=i.resolveStack(n.from,1);if(n.empty){let s=i.resolveStack(n.from,-1);s.node.from>=o.node.from&&s.node.to<=o.node.to&&(o=s)}for(let s=o;s;s=s.next){let{node:a}=s;if((a.from<n.from&&a.to>=n.to||a.to>n.to&&a.from<=n.from)&&s.next)return l.EditorSelection.range(a.to,a.from)}return n});return r.eq(t.selection)?!1:(e(L(t,r)),!0)};function qt(t,e){let{state:r}=t,n=r.selection,i=r.selection.ranges.slice();for(let o of r.selection.ranges){let s=r.doc.lineAt(o.head);if(e?s.to<t.state.doc.length:s.from>0)for(let a=o;;){let c=t.moveVertically(a,e);if(c.head<s.from||c.head>s.to){i.some(h=>h.head==c.head)||i.push(c);break}else{if(c.head==a.head)break;a=c}}}return i.length==n.ranges.length?!1:(t.dispatch(L(r,l.EditorSelection.create(i,i.length-1))),!0)}const hr=t=>qt(t,!1),ur=t=>qt(t,!0),fr=({state:t,dispatch:e})=>{let r=t.selection,n=null;return r.ranges.length>1?n=l.EditorSelection.create([r.main]):r.main.empty||(n=l.EditorSelection.create([l.EditorSelection.cursor(r.main.head)])),n?(e(L(t,n)),!0):!1};function oe(t,e){if(t.state.readOnly)return!1;let r="delete.selection",{state:n}=t,i=n.changeByRange(o=>{let{from:s,to:a}=o;if(s==a){let c=e(o);c<s?(r="delete.backward",c=he(t,c,!1)):c>s&&(r="delete.forward",c=he(t,c,!0)),s=Math.min(s,c),a=Math.max(a,c)}else s=he(t,s,!1),a=he(t,a,!0);return s==a?{range:o}:{changes:{from:s,to:a},range:l.EditorSelection.cursor(s,s<o.head?-1:1)}});return i.changes.empty?!1:(t.dispatch(n.update(i,{scrollIntoView:!0,userEvent:r,effects:r=="delete.selection"?l.EditorView.announce.of(n.phrase("Selection deleted")):void 0})),!0)}function he(t,e,r){if(t instanceof l.EditorView)for(let n of t.state.facet(l.EditorView.atomicRanges).map(i=>i(t)))n.between(e,e,(i,o)=>{i<e&&o>e&&(e=r?o:i)});return e}const Ht=(t,e,r)=>oe(t,n=>{let i=n.from,{state:o}=t,s=o.doc.lineAt(i),a,c;if(r&&!e&&i>s.from&&i<s.from+200&&!/[^ \t]/.test(a=s.text.slice(0,i-s.from))){if(a[a.length-1]==" ")return i-1;let h=l.countColumn(a,o.tabSize),u=h%l.getIndentUnit(o)||l.getIndentUnit(o);for(let f=0;f<u&&a[a.length-1-f]==" ";f++)i--;c=i}else c=l.findClusterBreak(s.text,i-s.from,e,e)+s.from,c==i&&s.number!=(e?o.doc.lines:1)?c+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(s.text.slice(c-s.from,i-s.from))&&(c=l.findClusterBreak(s.text,c-s.from,!1,!1)+s.from);return c}),We=t=>Ht(t,!1,!0),Ut=t=>Ht(t,!0,!1),zt=(t,e)=>oe(t,r=>{let n=r.head,{state:i}=t,o=i.doc.lineAt(n),s=i.charCategorizer(n);for(let a=null;;){if(n==(e?o.to:o.from)){n==r.head&&o.number!=(e?i.doc.lines:1)&&(n+=e?1:-1);break}let c=l.findClusterBreak(o.text,n-o.from,e)+o.from,h=o.text.slice(Math.min(n,c)-o.from,Math.max(n,c)-o.from),u=s(h);if(a!=null&&u!=a)break;(h!=" "||n!=r.head)&&(a=u),n=c}return n}),Gt=t=>zt(t,!1),dr=t=>zt(t,!0),mr=t=>oe(t,e=>{let r=t.lineBlockAt(e.head).to;return e.head<r?r:Math.min(t.state.doc.length,e.head+1)}),gr=t=>oe(t,e=>{let r=t.moveToLineBoundary(e,!1).head;return e.head>r?r:Math.max(0,e.head-1)}),pr=t=>oe(t,e=>{let r=t.moveToLineBoundary(e,!0).head;return e.head<r?r:Math.min(t.state.doc.length,e.head+1)}),yr=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>({changes:{from:n.from,to:n.to,insert:l.Text.of(["",""])},range:l.EditorSelection.cursor(n.from)}));return e(t.update(r,{scrollIntoView:!0,userEvent:"input"})),!0},Sr=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let r=t.changeByRange(n=>{if(!n.empty||n.from==0||n.from==t.doc.length)return{range:n};let i=n.from,o=t.doc.lineAt(i),s=i==o.from?i-1:l.findClusterBreak(o.text,i-o.from,!1)+o.from,a=i==o.to?i+1:l.findClusterBreak(o.text,i-o.from,!0)+o.from;return{changes:{from:s,to:a,insert:t.doc.slice(i,a).append(t.doc.slice(s,i))},range:l.EditorSelection.cursor(a)}});return r.changes.empty?!1:(e(t.update(r,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Ee(t){let e=[],r=-1;for(let n of t.selection.ranges){let i=t.doc.lineAt(n.from),o=t.doc.lineAt(n.to);if(!n.empty&&n.to==o.from&&(o=t.doc.lineAt(n.to-1)),r>=i.number){let s=e[e.length-1];s.to=o.to,s.ranges.push(n)}else e.push({from:i.from,to:o.to,ranges:[n]});r=o.number+1}return e}function Kt(t,e,r){if(t.readOnly)return!1;let n=[],i=[];for(let o of Ee(t)){if(r?o.to==t.doc.length:o.from==0)continue;let s=t.doc.lineAt(r?o.to+1:o.from-1),a=s.length+1;if(r){n.push({from:o.to,to:s.to},{from:o.from,insert:s.text+t.lineBreak});for(let c of o.ranges)i.push(l.EditorSelection.range(Math.min(t.doc.length,c.anchor+a),Math.min(t.doc.length,c.head+a)))}else{n.push({from:s.from,to:o.from},{from:o.to,insert:t.lineBreak+s.text});for(let c of o.ranges)i.push(l.EditorSelection.range(c.anchor-a,c.head-a))}}return n.length?(e(t.update({changes:n,scrollIntoView:!0,selection:l.EditorSelection.create(i,t.selection.mainIndex),userEvent:"move.line"})),!0):!1}const kr=({state:t,dispatch:e})=>Kt(t,e,!1),xr=({state:t,dispatch:e})=>Kt(t,e,!0);function $t(t,e,r){if(t.readOnly)return!1;let n=[];for(let o of Ee(t))r?n.push({from:o.from,insert:t.doc.slice(o.from,o.to)+t.lineBreak}):n.push({from:o.to,insert:t.lineBreak+t.doc.slice(o.from,o.to)});let i=t.changes(n);return e(t.update({changes:i,selection:t.selection.map(i,r?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Cr=({state:t,dispatch:e})=>$t(t,e,!1),br=({state:t,dispatch:e})=>$t(t,e,!0),vr=t=>{if(t.state.readOnly)return!1;let{state:e}=t,r=e.changes(Ee(e).map(({from:i,to:o})=>(i>0?i--:o<e.doc.length&&o++,{from:i,to:o}))),n=Y(e.selection,i=>{let o;if(t.lineWrapping){let s=t.lineBlockAt(i.head),a=t.coordsAtPos(i.head,i.assoc||1);a&&(o=s.bottom+t.documentTop-a.bottom+t.defaultLineHeight/2)}return t.moveVertically(i,!0,o)}).map(r);return t.dispatch({changes:r,selection:n,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Er(t,e){if(/\(\)|\[\]|\{\}/.test(t.sliceDoc(e-1,e+1)))return{from:e,to:e};let r=l.syntaxTree(t).resolveInner(e),n=r.childBefore(e),i=r.childAfter(e),o;return n&&i&&n.to<=e&&i.from>=e&&(o=n.type.prop(l.NodeProp.closedBy))&&o.indexOf(i.name)>-1&&t.doc.lineAt(n.to).from==t.doc.lineAt(i.from).from&&!/\S/.test(t.sliceDoc(n.to,i.from))?{from:n.to,to:i.from}:null}const rt=Jt(!1),Mr=Jt(!0);function Jt(t){return({state:e,dispatch:r})=>{if(e.readOnly)return!1;let n=e.changeByRange(i=>{let{from:o,to:s}=i,a=e.doc.lineAt(o),c=!t&&o==s&&Er(e,o);t&&(o=s=(s<=a.to?a:e.doc.lineAt(s)).to);let h=new l.IndentContext(e,{simulateBreak:o,simulateDoubleBreak:!!c}),u=l.getIndentation(h,o);for(u==null&&(u=l.countColumn(/^\s*/.exec(e.doc.lineAt(o).text)[0],e.tabSize));s<a.to&&/\s/.test(a.text[s-a.from]);)s++;c?{from:o,to:s}=c:o>a.from&&o<a.from+100&&!/\S/.test(a.text.slice(0,o))&&(o=a.from);let f=["",l.indentString(e,u)];return c&&f.push(l.indentString(e,h.lineIndent(a.from,-1))),{changes:{from:o,to:s,insert:l.Text.of(f)},range:l.EditorSelection.cursor(o+1+f[1].length)}});return r(e.update(n,{scrollIntoView:!0,userEvent:"input"})),!0}}function ze(t,e){let r=-1;return t.changeByRange(n=>{let i=[];for(let s=n.from;s<=n.to;){let a=t.doc.lineAt(s);a.number>r&&(n.empty||n.to>a.from)&&(e(a,i,n),r=a.number),s=a.to+1}let o=t.changes(i);return{changes:i,range:l.EditorSelection.range(o.mapPos(n.anchor,1),o.mapPos(n.head,1))}})}const Ar=({state:t,dispatch:e})=>{if(t.readOnly)return!1;let r=Object.create(null),n=new l.IndentContext(t,{overrideIndentation:o=>{let s=r[o];return s??-1}}),i=ze(t,(o,s,a)=>{let c=l.getIndentation(n,o.from);if(c==null)return;/\S/.test(o.text)||(c=0);let h=/^\s*/.exec(o.text)[0],u=l.indentString(t,c);(h!=u||a.from<o.from+h.length)&&(r[o.from]=c,s.push({from:o.from,to:o.from+h.length,insert:u}))});return i.changes.empty||e(t.update(i,{userEvent:"indent"})),!0},_t=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(ze(t,(r,n)=>{n.push({from:r.from,insert:t.facet(l.indentUnit)})}),{userEvent:"input.indent"})),!0),jt=({state:t,dispatch:e})=>t.readOnly?!1:(e(t.update(ze(t,(r,n)=>{let i=/^\s*/.exec(r.text)[0];if(!i)return;let o=l.countColumn(i,t.tabSize),s=0,a=l.indentString(t,Math.max(0,o-l.getIndentUnit(t)));for(;s<i.length&&s<a.length&&i.charCodeAt(s)==a.charCodeAt(s);)s++;n.push({from:r.from+s,to:r.from+i.length,insert:a.slice(s)})}),{userEvent:"delete.dedent"})),!0),Dr=t=>(t.setTabFocusMode(),!0),Br=[{key:"Ctrl-b",run:Et,shift:Pt,preventDefault:!0},{key:"Ctrl-f",run:Mt,shift:It},{key:"Ctrl-p",run:Bt,shift:Vt},{key:"Ctrl-n",run:Lt,shift:Ft},{key:"Ctrl-a",run:Jn,shift:or},{key:"Ctrl-e",run:_n,shift:lr},{key:"Ctrl-d",run:Ut},{key:"Ctrl-h",run:We},{key:"Ctrl-k",run:mr},{key:"Ctrl-Alt-h",run:Gt},{key:"Ctrl-o",run:yr},{key:"Ctrl-t",run:Sr},{key:"Ctrl-v",run:Oe}],Lr=[{key:"ArrowLeft",run:Et,shift:Pt,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:Fn,shift:Yn,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:Kn,shift:rr,preventDefault:!0},{key:"ArrowRight",run:Mt,shift:It,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:Nn,shift:Zn,preventDefault:!0},{mac:"Cmd-ArrowRight",run:$n,shift:ir,preventDefault:!0},{key:"ArrowUp",run:Bt,shift:Vt,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Xe,shift:tt},{mac:"Ctrl-ArrowUp",run:Qe,shift:Ye},{key:"ArrowDown",run:Lt,shift:Ft,preventDefault:!0},{mac:"Cmd-ArrowDown",run:et,shift:nt},{mac:"Ctrl-ArrowDown",run:Oe,shift:Ze},{key:"PageUp",run:Qe,shift:Ye},{key:"PageDown",run:Oe,shift:Ze},{key:"Home",run:Gn,shift:nr,preventDefault:!0},{key:"Mod-Home",run:Xe,shift:tt},{key:"End",run:zn,shift:tr,preventDefault:!0},{key:"Mod-End",run:et,shift:nt},{key:"Enter",run:rt,shift:rt},{key:"Mod-a",run:sr},{key:"Backspace",run:We,shift:We,preventDefault:!0},{key:"Delete",run:Ut,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Gt,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:dr,preventDefault:!0},{mac:"Mod-Backspace",run:gr,preventDefault:!0},{mac:"Mod-Delete",run:pr,preventDefault:!0}].concat(Br.map(t=>({mac:t.key,run:t.run,shift:t.shift}))),wr=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:Hn,shift:Xn},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Un,shift:er},{key:"Alt-ArrowUp",run:kr},{key:"Shift-Alt-ArrowUp",run:Cr},{key:"Alt-ArrowDown",run:xr},{key:"Shift-Alt-ArrowDown",run:br},{key:"Mod-Alt-ArrowUp",run:hr},{key:"Mod-Alt-ArrowDown",run:ur},{key:"Escape",run:fr},{key:"Mod-Enter",run:Mr},{key:"Alt-l",mac:"Ctrl-l",run:ar},{key:"Mod-i",run:cr,preventDefault:!0},{key:"Mod-[",run:jt},{key:"Mod-]",run:_t},{key:"Mod-Alt-\\",run:Ar},{key:"Shift-Mod-k",run:vr},{key:"Shift-Mod-\\",run:Qn},{key:"Mod-/",run:kn},{key:"Alt-A",run:Cn},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Dr}].concat(Lr),Tr={key:"Tab",run:_t,shift:jt},it=typeof String.prototype.normalize=="function"?t=>t.normalize("NFKD"):t=>t;class Q{constructor(e,r,n=0,i=e.length,o,s){this.test=s,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(n,i),this.bufferStart=n,this.normalize=o?a=>o(it(a)):it,this.query=this.normalize(r)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return l.codePointAt(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let r=l.fromCodePoint(e),n=this.bufferStart+this.bufferPos;this.bufferPos+=l.codePointSize(e);let i=this.normalize(r);if(i.length)for(let o=0,s=n,a=!0;;o++){let c=i.charCodeAt(o),h=this.match(c,s,a,this.bufferPos+this.bufferStart,o==i.length-1);if(h)return this.value=h,this;if(o==i.length-1)break;a&&o<r.length&&r.charCodeAt(o)==c?s++:a=!1}}}match(e,r,n,i,o){let s=null;for(let a=0;a<this.matches.length;){let c=this.matches[a],h=!1;this.query.charCodeAt(c.index)==e&&(c.index==this.query.length-1?s={from:c.from,to:i,precise:o&&c.precise}:(c.index++,h=!0)),h?a++:this.matches.splice(a,1)}return this.query.charCodeAt(0)==e&&(this.query.length==1?s={from:r,to:i,precise:n&&o}:this.matches.push({from:r,index:1,precise:n})),s&&this.test&&!this.test(s.from,s.to,this.buffer,this.bufferStart)&&(s=null),s}}typeof Symbol<"u"&&(Q.prototype[Symbol.iterator]=function(){return this});const Qt={from:-1,to:-1,match:/.*/.exec(""),precise:!0},Ge="gm"+(/x/.unicode==null?"":"u");class Yt{constructor(e,r,n,i=0,o=e.length){if(this.text=e,this.to=o,this.curLine="",this.done=!1,this.value=Qt,/\\[sWDnr]|\n|\r|\[\^/.test(r))return new Zt(e,r,n,i,o);this.re=new RegExp(r,Ge+(n!=null&&n.ignoreCase?"i":"")),this.test=n==null?void 0:n.test,this.iter=e.iter();let s=e.lineAt(i);this.curLineStart=s.from,this.matchPos=pe(e,i),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let r=this.matchPos<=this.to&&this.re.exec(this.curLine);if(r){let n=this.curLineStart+r.index,i=n+r[0].length;if(this.matchPos=pe(this.text,i+(n==i?1:0)),n==this.curLineStart+this.curLine.length&&this.nextLine(),(n<i||n>this.value.to)&&(!this.test||this.test(n,i,r)))return this.value={from:n,to:i,precise:!0,match:r},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const Le=new WeakMap;class j{constructor(e,r){this.from=e,this.text=r}get to(){return this.from+this.text.length}static get(e,r,n){let i=Le.get(e);if(!i||i.from>=n||i.to<=r){let a=new j(r,e.sliceString(r,n));return Le.set(e,a),a}if(i.from==r&&i.to==n)return i;let{text:o,from:s}=i;return s>r&&(o=e.sliceString(r,s)+o,s=r),i.to<n&&(o+=e.sliceString(i.to,n)),Le.set(e,new j(s,o)),new j(r,o.slice(r-s,n-s))}}class Zt{constructor(e,r,n,i,o){this.text=e,this.to=o,this.done=!1,this.value=Qt,this.matchPos=pe(e,i),this.re=new RegExp(r,Ge+(n!=null&&n.ignoreCase?"i":"")),this.test=n==null?void 0:n.test,this.flat=j.get(e,i,this.chunkEnd(i+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,r=this.re.exec(this.flat.text);if(r&&!r[0]&&r.index==e&&(this.re.lastIndex=e+1,r=this.re.exec(this.flat.text)),r){let n=this.flat.from+r.index,i=n+r[0].length;if((this.flat.to>=this.to||r.index+r[0].length<=this.flat.text.length-10)&&(!this.test||this.test(n,i,r)))return this.value={from:n,to:i,precise:!0,match:r},this.matchPos=pe(this.text,i+(n==i?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=j.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(Yt.prototype[Symbol.iterator]=Zt.prototype[Symbol.iterator]=function(){return this});function Rr(t){try{return new RegExp(t,Ge),!0}catch{return!1}}function pe(t,e){if(e>=t.length)return e;let r=t.lineAt(e),n;for(;e<r.to&&(n=r.text.charCodeAt(e-r.from))>=56320&&n<57344;)e++;return e}const Pr=t=>{let{state:e}=t,r=String(e.doc.lineAt(t.state.selection.main.head).number),{close:n,result:i}=l.showDialog(t,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:r},focus:!0,submitLabel:e.phrase("go")});return i.then(o=>{let s=o&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(o.elements.line.value);if(!s){t.dispatch({effects:n});return}let a=e.doc.lineAt(e.selection.main.head),[,c,h,u,f]=s,d=u?+u.slice(1):0,m=h?+h:a.number;if(h&&f){let y=m/100;c&&(y=y*(c=="-"?-1:1)+a.number/e.doc.lines),m=Math.round(e.doc.lines*y)}else h&&c&&(m=m*(c=="-"?-1:1)+a.number);let g=e.doc.line(Math.max(1,Math.min(e.doc.lines,m))),S=l.EditorSelection.cursor(g.from+Math.max(0,Math.min(d,g.length)));t.dispatch({effects:[n,l.EditorView.scrollIntoView(S.from,{y:"center"})],selection:S})}),!0},Ir={highlightWordAroundCursor:!1,minSelectionLength:1,maxMatches:100,wholeWords:!1},Or=l.Facet.define({combine(t){return l.combineConfig(t,Ir,{highlightWordAroundCursor:(e,r)=>e||r,minSelectionLength:Math.min,maxMatches:Math.min})}});function Wr(t){return[Hr,qr]}const Vr=l.Decoration.mark({class:"cm-selectionMatch"}),Fr=l.Decoration.mark({class:"cm-selectionMatch cm-selectionMatch-main"});function ot(t,e,r,n){return(r==0||t(e.sliceDoc(r-1,r))!=l.CharCategory.Word)&&(n==e.doc.length||t(e.sliceDoc(n,n+1))!=l.CharCategory.Word)}function Nr(t,e,r,n){return t(e.sliceDoc(r,r+1))==l.CharCategory.Word&&t(e.sliceDoc(n-1,n))==l.CharCategory.Word}const qr=l.ViewPlugin.fromClass(class{constructor(t){this.decorations=this.getDeco(t)}update(t){(t.selectionSet||t.docChanged||t.viewportChanged)&&(this.decorations=this.getDeco(t.view))}getDeco(t){let e=t.state.facet(Or),{state:r}=t,n=r.selection;if(n.ranges.length>1)return l.Decoration.none;let i=n.main,o,s=null;if(i.empty){if(!e.highlightWordAroundCursor)return l.Decoration.none;let c=r.wordAt(i.head);if(!c)return l.Decoration.none;s=r.charCategorizer(i.head),o=r.sliceDoc(c.from,c.to)}else{let c=i.to-i.from;if(c<e.minSelectionLength||c>200)return l.Decoration.none;if(e.wholeWords){if(o=r.sliceDoc(i.from,i.to),s=r.charCategorizer(i.head),!(ot(s,r,i.from,i.to)&&Nr(s,r,i.from,i.to)))return l.Decoration.none}else if(o=r.sliceDoc(i.from,i.to),!o)return l.Decoration.none}let a=[];for(let c of t.visibleRanges){let h=new Q(r.doc,o,c.from,c.to);for(;!h.next().done;){let{from:u,to:f}=h.value;if((!s||ot(s,r,u,f))&&(i.empty&&u<=i.from&&f>=i.to?a.push(Fr.range(u,f)):(u>=i.to||f<=i.from)&&a.push(Vr.range(u,f)),a.length>e.maxMatches))return l.Decoration.none}}return l.Decoration.set(a)}},{decorations:t=>t.decorations}),Hr=l.EditorView.baseTheme({".cm-selectionMatch":{backgroundColor:"#99ff7780"},".cm-searchMatch .cm-selectionMatch":{backgroundColor:"transparent"}}),Ur=({state:t,dispatch:e})=>{let{selection:r}=t,n=l.EditorSelection.create(r.ranges.map(i=>t.wordAt(i.head)||l.EditorSelection.cursor(i.head)),r.mainIndex);return n.eq(r)?!1:(e(t.update({selection:n})),!0)};function zr(t,e){let{main:r,ranges:n}=t.selection,i=t.wordAt(r.head),o=i&&i.from==r.from&&i.to==r.to;for(let s=!1,a=new Q(t.doc,e,n[n.length-1].to);;)if(a.next(),a.done){if(s)return null;a=new Q(t.doc,e,0,Math.max(0,n[n.length-1].from-1)),s=!0}else{if(s&&n.some(c=>c.from==a.value.from))continue;if(o){let c=t.wordAt(a.value.from);if(!c||c.from!=a.value.from||c.to!=a.value.to)continue}return a.value}}const Gr=({state:t,dispatch:e})=>{let{ranges:r}=t.selection;if(r.some(o=>o.from===o.to))return Ur({state:t,dispatch:e});let n=t.sliceDoc(r[0].from,r[0].to);if(t.selection.ranges.some(o=>t.sliceDoc(o.from,o.to)!=n))return!1;let i=zr(t,n);return i?(e(t.update({selection:t.selection.addRange(l.EditorSelection.range(i.from,i.to),!1),effects:l.EditorView.scrollIntoView(i.to)})),!0):!1},Z=l.Facet.define({combine(t){return l.combineConfig(t,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new ii(e),scrollToMatch:e=>l.EditorView.scrollIntoView(e)})}});class Xt{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||Rr(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(r,n)=>n=="n"?`
|
|
2
2
|
`:n=="r"?"\r":n=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new Qr(this):new Jr(this)}getCursor(e,r=0,n){let i=e.doc?e:l.EditorState.create({doc:e});return n==null&&(n=i.doc.length),this.regexp?_(this,i,r,n):J(this,i,r,n)}}class en{constructor(e){this.spec=e}}function Kr(t,e,r){return(n,i,o,s)=>{if(r&&!r(n,i,o,s))return!1;let a=n>=s&&i<=s+o.length?o.slice(n-s,i-s):e.doc.sliceString(n,i);return t(a,e,n,i)}}function J(t,e,r,n){let i;return t.wholeWord&&(i=$r(e.doc,e.charCategorizer(e.selection.main.head))),t.test&&(i=Kr(t.test,e,i)),new Q(e.doc,t.unquoted,r,n,t.caseSensitive?void 0:o=>o.toLowerCase(),i)}function $r(t,e){return(r,n,i,o)=>((o>r||o+i.length<n)&&(o=Math.max(0,r-2),i=t.sliceString(o,Math.min(t.length,n+2))),(e(ye(i,r-o))!=l.CharCategory.Word||e(Se(i,r-o))!=l.CharCategory.Word)&&(e(Se(i,n-o))!=l.CharCategory.Word||e(ye(i,n-o))!=l.CharCategory.Word))}class Jr extends en{constructor(e){super(e)}nextMatch(e,r,n){let i=J(this.spec,e,n,e.doc.length).nextOverlapping();if(i.done){let o=Math.min(e.doc.length,r+this.spec.unquoted.length);i=J(this.spec,e,0,o).nextOverlapping()}return i.done||i.value.from==r&&i.value.to==n?null:i.value}prevMatchInRange(e,r,n){for(let i=n;;){let o=Math.max(r,i-1e4-this.spec.unquoted.length),s=J(this.spec,e,o,i),a=null;for(;!s.nextOverlapping().done;)a=s.value;if(a)return a;if(o==r)return null;i-=1e4}}prevMatch(e,r,n){let i=this.prevMatchInRange(e,0,r);return i||(i=this.prevMatchInRange(e,Math.max(0,n-this.spec.unquoted.length),e.doc.length)),i&&(i.from!=r||i.to!=n)?i:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,r){let n=J(this.spec,e,0,e.doc.length),i=[];for(;!n.next().done;){if(i.length>=r)return null;i.push(n.value)}return i}highlight(e,r,n,i){let o=J(this.spec,e,Math.max(0,r-this.spec.unquoted.length),Math.min(n+this.spec.unquoted.length,e.doc.length));for(;!o.next().done;)i(o.value.from,o.value.to)}}function _r(t,e,r){return(n,i,o)=>(!r||r(n,i,o))&&t(o[0],e,n,i)}function _(t,e,r,n){let i;return t.wholeWord&&(i=jr(e.charCategorizer(e.selection.main.head))),t.test&&(i=_r(t.test,e,i)),new Yt(e.doc,t.search,{ignoreCase:!t.caseSensitive,test:i},r,n)}function ye(t,e){return t.slice(l.findClusterBreak(t,e,!1),e)}function Se(t,e){return t.slice(e,l.findClusterBreak(t,e))}function jr(t){return(e,r,n)=>!n[0].length||(t(ye(n.input,n.index))!=l.CharCategory.Word||t(Se(n.input,n.index))!=l.CharCategory.Word)&&(t(Se(n.input,n.index+n[0].length))!=l.CharCategory.Word||t(ye(n.input,n.index+n[0].length))!=l.CharCategory.Word)}class Qr extends en{nextMatch(e,r,n){let i=_(this.spec,e,n,e.doc.length).next();return i.done&&(i=_(this.spec,e,0,r).next()),i.done?null:i.value}prevMatchInRange(e,r,n){for(let i=1;;i++){let o=Math.max(r,n-i*1e4),s=_(this.spec,e,o,n),a=null;for(;!s.next().done;)a=s.value;if(a&&(o==r||a.from>o+10))return a;if(o==r)return null}}prevMatch(e,r,n){return this.prevMatchInRange(e,0,r)||this.prevMatchInRange(e,n,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(r,n)=>{if(n=="&")return e.match[0];if(n=="$")return"$";for(let i=n.length;i>0;i--){let o=+n.slice(0,i);if(o>0&&o<e.match.length)return e.match[o]+n.slice(i)}return r})}matchAll(e,r){let n=_(this.spec,e,0,e.doc.length),i=[];for(;!n.next().done;){if(i.length>=r)return null;i.push(n.value)}return i}highlight(e,r,n,i){let o=_(this.spec,e,Math.max(0,r-250),Math.min(n+250,e.doc.length));for(;!o.next().done;)i(o.value.from,o.value.to)}}const ne=l.StateEffect.define(),Ke=l.StateEffect.define(),O=l.StateField.define({create(t){return new we(Ve(t).create(),null)},update(t,e){for(let r of e.effects)r.is(ne)?t=new we(r.value.create(),t.panel):r.is(Ke)&&(t=new we(t.query,r.value?$e:null));return t},provide:t=>l.showPanel.from(t,e=>e.panel)});class we{constructor(e,r){this.query=e,this.panel=r}}const Yr=l.Decoration.mark({class:"cm-searchMatch"}),Zr=l.Decoration.mark({class:"cm-searchMatch cm-searchMatch-selected"}),Xr=l.ViewPlugin.fromClass(class{constructor(t){this.view=t,this.decorations=this.highlight(t.state.field(O))}update(t){let e=t.state.field(O);(e!=t.startState.field(O)||t.docChanged||t.selectionSet||t.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:t,panel:e}){if(!e||!t.spec.valid)return l.Decoration.none;let{view:r}=this,n=new l.RangeSetBuilder;for(let i=0,o=r.visibleRanges,s=o.length;i<s;i++){let{from:a,to:c}=o[i];for(;i<s-1&&c>o[i+1].from-2*250;)c=o[++i].to;t.highlight(r.state,a,c,(h,u)=>{let f=r.state.selection.ranges.some(d=>d.from==h&&d.to==u);n.add(h,u,f?Zr:Yr)})}return n.finish()}},{decorations:t=>t.decorations});function le(t){return e=>{let r=e.state.field(O,!1);return r&&r.query.spec.valid?t(e,r):rn(e)}}const ke=le((t,{query:e})=>{let{to:r}=t.state.selection.main,n=e.nextMatch(t.state,r,r);if(!n)return!1;let i=l.EditorSelection.single(n.from,n.to),o=t.state.facet(Z);return t.dispatch({selection:i,effects:[Je(t,n),o.scrollToMatch(i.main,t)],userEvent:"select.search"}),nn(t),!0}),xe=le((t,{query:e})=>{let{state:r}=t,{from:n}=r.selection.main,i=e.prevMatch(r,n,n);if(!i)return!1;let o=l.EditorSelection.single(i.from,i.to),s=t.state.facet(Z);return t.dispatch({selection:o,effects:[Je(t,i),s.scrollToMatch(o.main,t)],userEvent:"select.search"}),nn(t),!0}),ei=le((t,{query:e})=>{let r=e.matchAll(t.state,1e3);return!r||!r.length?!1:(t.dispatch({selection:l.EditorSelection.create(r.map(n=>l.EditorSelection.range(n.from,n.to))),userEvent:"select.search.matches"}),!0)}),ti=({state:t,dispatch:e})=>{let r=t.selection;if(r.ranges.length>1||r.main.empty)return!1;let{from:n,to:i}=r.main,o=[],s=0;for(let a=new Q(t.doc,t.sliceDoc(n,i));!a.next().done;){if(o.length>1e3)return!1;a.value.from==n&&(s=o.length),o.push(l.EditorSelection.range(a.value.from,a.value.to))}return e(t.update({selection:l.EditorSelection.create(o,s),userEvent:"select.search.matches"})),!0},lt=le((t,{query:e})=>{let{state:r}=t,{from:n,to:i}=r.selection.main;if(r.readOnly)return!1;let o=e.nextMatch(r,n,n);if(!o)return!1;let s=o,a=[],c,h,u=[];s.precise?s.from==n&&s.to==i&&(h=r.toText(e.getReplacement(s)),a.push({from:s.from,to:s.to,insert:h}),u.push(l.EditorView.announce.of(r.phrase("replaced match on line $",r.doc.lineAt(n).number)+"."))):s=e.nextMatch(r,s.from,s.to);let f=t.state.changes(a);return s&&(c=l.EditorSelection.single(s.from,s.to).map(f),u.push(Je(t,s)),u.push(r.facet(Z).scrollToMatch(c.main,t))),t.dispatch({changes:f,selection:c,effects:u,userEvent:"input.replace"}),!0}),ni=le((t,{query:e})=>{if(t.state.readOnly)return!1;let r=[];for(let i of e.matchAll(t.state,1e9)){let{from:o,to:s,precise:a}=i;a&&r.push({from:o,to:s,insert:e.getReplacement(i)})}if(!r.length)return!1;let n=t.state.phrase("replaced $ matches",r.length)+".";return t.dispatch({changes:r,effects:l.EditorView.announce.of(n),userEvent:"input.replace.all"}),!0});function $e(t){return t.state.facet(Z).createPanel(t)}function Ve(t,e){var r,n,i,o,s;let a=t.selection.main,c=a.empty||a.to>a.from+100?"":t.sliceDoc(a.from,a.to);if(e&&!c)return e;let h=t.facet(Z);return new Xt({search:((r=e==null?void 0:e.literal)!==null&&r!==void 0?r:h.literal)?c:c.replace(/\n/g,"\\n"),caseSensitive:(n=e==null?void 0:e.caseSensitive)!==null&&n!==void 0?n:h.caseSensitive,literal:(i=e==null?void 0:e.literal)!==null&&i!==void 0?i:h.literal,regexp:(o=e==null?void 0:e.regexp)!==null&&o!==void 0?o:h.regexp,wholeWord:(s=e==null?void 0:e.wholeWord)!==null&&s!==void 0?s:h.wholeWord})}function tn(t){let e=l.getPanel(t,$e);return e&&e.dom.querySelector("[main-field]")}function nn(t){let e=tn(t);e&&e==t.root.activeElement&&e.select()}const rn=t=>{let e=t.state.field(O,!1);if(e&&e.panel){let r=tn(t);if(r&&r!=t.root.activeElement){let n=Ve(t.state,e.query.spec);n.valid&&t.dispatch({effects:ne.of(n)}),r.focus(),r.select()}}else t.dispatch({effects:[Ke.of(!0),e?ne.of(Ve(t.state,e.query.spec)):l.StateEffect.appendConfig.of(li)]});return!0},on=t=>{let e=t.state.field(O,!1);if(!e||!e.panel)return!1;let r=l.getPanel(t,$e);return r&&r.dom.contains(t.root.activeElement)&&t.focus(),t.dispatch({effects:Ke.of(!1)}),!0},ri=[{key:"Mod-f",run:rn,scope:"editor search-panel"},{key:"F3",run:ke,shift:xe,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:ke,shift:xe,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:on,scope:"editor search-panel"},{key:"Mod-Shift-l",run:ti},{key:"Mod-Alt-g",run:Pr},{key:"Mod-d",run:Gr,preventDefault:!0}];class ii{constructor(e){this.view=e;let r=this.query=e.state.field(O).query.spec;this.commit=this.commit.bind(this),this.searchField=l.crelt("input",{value:r.search,placeholder:E(e,"Find"),"aria-label":E(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=l.crelt("input",{value:r.replace,placeholder:E(e,"Replace"),"aria-label":E(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=l.crelt("input",{type:"checkbox",name:"case",form:"",checked:r.caseSensitive,onchange:this.commit}),this.reField=l.crelt("input",{type:"checkbox",name:"re",form:"",checked:r.regexp,onchange:this.commit}),this.wordField=l.crelt("input",{type:"checkbox",name:"word",form:"",checked:r.wholeWord,onchange:this.commit});function n(i,o,s){return l.crelt("button",{class:"cm-button",name:i,onclick:o,type:"button"},s)}this.dom=l.crelt("div",{onkeydown:i=>this.keydown(i),class:"cm-search"},[this.searchField,n("next",()=>ke(e),[E(e,"next")]),n("prev",()=>xe(e),[E(e,"previous")]),n("select",()=>ei(e),[E(e,"all")]),l.crelt("label",null,[this.caseField,E(e,"match case")]),l.crelt("label",null,[this.reField,E(e,"regexp")]),l.crelt("label",null,[this.wordField,E(e,"by word")]),...e.state.readOnly?[]:[l.crelt("br"),this.replaceField,n("replace",()=>lt(e),[E(e,"replace")]),n("replaceAll",()=>ni(e),[E(e,"replace all")])],l.crelt("button",{name:"close",onclick:()=>on(e),"aria-label":E(e,"close"),type:"button"},["×"])])}commit(){let e=new Xt({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:ne.of(e)}))}keydown(e){l.runScopeHandlers(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?xe:ke)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),lt(this.view))}update(e){for(let r of e.transactions)for(let n of r.effects)n.is(ne)&&!n.value.eq(this.query)&&this.setQuery(n.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Z).top}}function E(t,e){return t.state.phrase(e)}const ue=30,fe=/[\s\.,:;?!]/;function Je(t,{from:e,to:r}){let n=t.state.doc.lineAt(e),i=t.state.doc.lineAt(r).to,o=Math.max(n.from,e-ue),s=Math.min(i,r+ue),a=t.state.sliceDoc(o,s);if(o!=n.from){for(let c=0;c<ue;c++)if(!fe.test(a[c+1])&&fe.test(a[c])){a=a.slice(c);break}}if(s!=i){for(let c=a.length-1;c>a.length-ue;c--)if(!fe.test(a[c-1])&&fe.test(a[c])){a=a.slice(0,c);break}}return l.EditorView.announce.of(`${t.state.phrase("current match")}. ${a} ${t.state.phrase("on line")} ${n.number}.`)}const oi=l.EditorView.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),li=[O,l.Prec.low(Xr),oi];class st{constructor(e,r,n){this.from=e,this.to=r,this.diagnostic=n}}class U{constructor(e,r,n){this.diagnostics=e,this.panel=r,this.selected=n}static init(e,r,n){let i=n.facet(re).markerFilter;i&&(e=i(e,n));let o=e.slice().sort((m,g)=>m.from-g.from||m.to-g.to),s=new l.RangeSetBuilder,a=[],c=0,h=n.doc.iter(),u=0,f=n.doc.length;for(let m=0;;){let g=m==o.length?null:o[m];if(!g&&!a.length)break;let S,y;if(a.length)S=c,y=a.reduce((p,C)=>Math.min(p,C.to),g&&g.from>S?g.from:1e8);else{if(S=g.from,S>f)break;y=g.to,a.push(g),m++}for(;m<o.length;){let p=o[m];if(p.from==S&&(p.to>p.from||p.to==S))a.push(p),m++,y=Math.min(p.to,y);else{y=Math.min(p.from,y);break}}y=Math.min(y,f);let P=!1;if(a.some(p=>p.from==S&&(p.to==y||y==f))&&(P=S==y,!P&&y-S<10)){let p=S-(u+h.value.length);p>0&&(h.next(p),u=S);for(let C=S;;){if(C>=y){P=!0;break}if(!h.lineBreak&&u+h.value.length>C)break;C=u+h.value.length,u+=h.value.length,h.next()}}let F=ki(a);if(P)s.add(S,S,l.Decoration.widget({widget:new gi(F),diagnostics:a.slice()}));else{let p=a.reduce((C,z)=>z.markClass?C+" "+z.markClass:C,"");s.add(S,y,l.Decoration.mark({class:"cm-lintRange cm-lintRange-"+F+p,diagnostics:a.slice(),inclusiveEnd:a.some(C=>C.to>y)}))}if(c=y,c==f)break;for(let p=0;p<a.length;p++)a[p].to<=c&&a.splice(p--,1)}let d=s.finish();return new U(d,r,W(d))}}function W(t,e=null,r=0){let n=null;return t.between(r,1e9,(i,o,{spec:s})=>{if(!(e&&s.diagnostics.indexOf(e)<0))if(!n)n=new st(i,o,e||s.diagnostics[0]);else{if(s.diagnostics.indexOf(n.diagnostic)<0)return!1;n=new st(n.from,o,n.diagnostic)}}),n}function si(t,e){let r=e.pos,n=e.end||r,i=t.state.facet(re).hideOn(t,r,n);if(i!=null)return i;let o=t.startState.doc.lineAt(e.pos);return!!(t.effects.some(s=>s.is(ln))||t.changes.touchesRange(o.from,Math.max(o.to,n)))}function ai(t,e){return t.field(M,!1)?e:e.concat(l.StateEffect.appendConfig.of(xi))}const ln=l.StateEffect.define(),_e=l.StateEffect.define(),sn=l.StateEffect.define(),M=l.StateField.define({create(){return new U(l.Decoration.none,null,null)},update(t,e){if(e.docChanged&&t.diagnostics.size){let r=t.diagnostics.map(e.changes),n=null,i=t.panel;if(t.selected){let o=e.changes.mapPos(t.selected.from,1);n=W(r,t.selected.diagnostic,o)||W(r,null,o)}!r.size&&i&&e.state.facet(re).autoPanel&&(i=null),t=new U(r,i,n)}for(let r of e.effects)if(r.is(ln)){let n=e.state.facet(re).autoPanel?r.value.length?ie.open:null:t.panel;t=U.init(r.value,n,e.state)}else r.is(_e)?t=new U(t.diagnostics,r.value?ie.open:null,t.selected):r.is(sn)&&(t=new U(t.diagnostics,t.panel,r.value));return t},provide:t=>[l.showPanel.from(t,e=>e.panel),l.EditorView.decorations.from(t,e=>e.diagnostics)]}),ci=l.Decoration.mark({class:"cm-lintRange cm-lintRange-active"});function hi(t,e,r){let{diagnostics:n}=t.state.field(M),i,o=-1,s=-1;n.between(e-(r<0?1:0),e+(r>0?1:0),(c,h,{spec:u})=>{if(e>=c&&e<=h&&(c==h||(e>c||r>0)&&(e<h||r<0)))return i=u.diagnostics,o=c,s=h,!1});let a=t.state.facet(re).tooltipFilter;return i&&a&&(i=a(i,t.state)),i?{pos:o,end:s,above:t.state.doc.lineAt(o).to<s,create(){return{dom:ui(t,i)}}}:null}function ui(t,e){return l.crelt("ul",{class:"cm-tooltip-lint"},e.map(r=>cn(t,r,!1)))}const fi=t=>{let e=t.state.field(M,!1);(!e||!e.panel)&&t.dispatch({effects:ai(t.state,[_e.of(!0)])});let r=l.getPanel(t,ie.open);return r&&r.dom.querySelector(".cm-panel-lint ul").focus(),!0},at=t=>{let e=t.state.field(M,!1);return!e||!e.panel?!1:(t.dispatch({effects:_e.of(!1)}),!0)},di=t=>{let e=t.state.field(M,!1);if(!e)return!1;let r=t.state.selection.main,n=W(e.diagnostics,null,r.to+1);return!n&&(n=W(e.diagnostics,null,0),!n||n.from==r.from&&n.to==r.to)?!1:(t.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:!0}),!0)},mi=[{key:"Mod-Shift-m",run:fi,preventDefault:!0},{key:"F8",run:di}],re=l.Facet.define({combine(t){return{sources:t.map(e=>e.source).filter(e=>e!=null),...l.combineConfig(t.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:ct,tooltipFilter:ct,needsRefresh:(e,r)=>e?r?n=>e(n)||r(n):e:r,hideOn:(e,r)=>e?r?(n,i,o)=>e(n,i,o)||r(n,i,o):e:r,autoPanel:(e,r)=>e||r})}}});function ct(t,e){return t?e?(r,n)=>e(t(r,n),n):t:e}function an(t){let e=[];if(t)e:for(let{name:r}of t){for(let n=0;n<r.length;n++){let i=r[n];if(/[a-zA-Z]/.test(i)&&!e.some(o=>o.toLowerCase()==i.toLowerCase())){e.push(i);continue e}}e.push("")}return e}function cn(t,e,r){var n;let i=r?an(e.actions):[];return l.crelt("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},l.crelt("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(t):e.message),(n=e.actions)===null||n===void 0?void 0:n.map((o,s)=>{let a=!1,c=m=>{if(m.preventDefault(),a)return;a=!0;let g=W(t.state.field(M).diagnostics,e);g&&o.apply(t,g.from,g.to)},{name:h}=o,u=i[s]?h.indexOf(i[s]):-1,f=u<0?h:[h.slice(0,u),l.crelt("u",h.slice(u,u+1)),h.slice(u+1)],d=o.markClass?" "+o.markClass:"";return l.crelt("button",{type:"button",class:"cm-diagnosticAction"+d,onclick:c,onmousedown:c,"aria-label":` Action: ${h}${u<0?"":` (access key "${i[s]})"`}.`},f)}),e.source&&l.crelt("div",{class:"cm-diagnosticSource"},e.source))}class gi extends l.WidgetType{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return l.crelt("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class ht{constructor(e,r){this.diagnostic=r,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=cn(e,r,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class ie{constructor(e){this.view=e,this.items=[];let r=i=>{if(!(i.ctrlKey||i.altKey||i.metaKey)){if(i.keyCode==27)at(this.view),this.view.focus();else if(i.keyCode==38||i.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(i.keyCode==40||i.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(i.keyCode==36)this.moveSelection(0);else if(i.keyCode==35)this.moveSelection(this.items.length-1);else if(i.keyCode==13)this.view.focus();else if(i.keyCode>=65&&i.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:o}=this.items[this.selectedIndex],s=an(o.actions);for(let a=0;a<s.length;a++)if(s[a].toUpperCase().charCodeAt(0)==i.keyCode){let c=W(this.view.state.field(M).diagnostics,o);c&&o.actions[a].apply(e,c.from,c.to)}}else return;i.preventDefault()}},n=i=>{for(let o=0;o<this.items.length;o++)this.items[o].dom.contains(i.target)&&this.moveSelection(o)};this.list=l.crelt("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:r,onclick:n}),this.dom=l.crelt("div",{class:"cm-panel-lint"},this.list,l.crelt("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>at(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(M).selected;if(!e)return-1;for(let r=0;r<this.items.length;r++)if(this.items[r].diagnostic==e.diagnostic)return r;return-1}update(){let{diagnostics:e,selected:r}=this.view.state.field(M),n=0,i=!1,o=null,s=new Set;for(e.between(0,this.view.state.doc.length,(a,c,{spec:h})=>{for(let u of h.diagnostics){if(s.has(u))continue;s.add(u);let f=-1,d;for(let m=n;m<this.items.length;m++)if(this.items[m].diagnostic==u){f=m;break}f<0?(d=new ht(this.view,u),this.items.splice(n,0,d),i=!0):(d=this.items[f],f>n&&(this.items.splice(n,f-n),i=!0)),r&&d.diagnostic==r.diagnostic?d.dom.hasAttribute("aria-selected")||(d.dom.setAttribute("aria-selected","true"),o=d):d.dom.hasAttribute("aria-selected")&&d.dom.removeAttribute("aria-selected"),n++}});n<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)i=!0,this.items.pop();this.items.length==0&&(this.items.push(new ht(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),i=!0),o?(this.list.setAttribute("aria-activedescendant",o.id),this.view.requestMeasure({key:this,read:()=>({sel:o.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:a,panel:c})=>{let h=c.height/this.list.offsetHeight;a.top<c.top?this.list.scrollTop-=(c.top-a.top)/h:a.bottom>c.bottom&&(this.list.scrollTop+=(a.bottom-c.bottom)/h)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),i&&this.sync()}sync(){let e=this.list.firstChild;function r(){let n=e;e=n.nextSibling,n.remove()}for(let n of this.items)if(n.dom.parentNode==this.list){for(;e!=n.dom;)r();e=n.dom.nextSibling}else this.list.insertBefore(n.dom,e);for(;e;)r()}moveSelection(e){if(this.selectedIndex<0)return;let r=this.view.state.field(M),n=W(r.diagnostics,this.items[e].diagnostic);n&&this.view.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:!0,effects:sn.of(n)})}static open(e){return new ie(e)}}function pi(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(t)}</svg>')`}function de(t){return pi(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${t}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const yi=l.EditorView.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:de("#d11")},".cm-lintRange-warning":{backgroundImage:de("orange")},".cm-lintRange-info":{backgroundImage:de("#999")},".cm-lintRange-hint":{backgroundImage:de("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function Si(t){return t=="error"?4:t=="warning"?3:t=="info"?2:1}function ki(t){let e="hint",r=1;for(let n of t){let i=Si(n.severity);i>r&&(r=i,e=n.severity)}return e}const xi=[M,l.EditorView.decorations.compute([M],t=>{let{selected:e,panel:r}=t.field(M);return!e||!r||e.from==e.to?l.Decoration.none:l.Decoration.set([ci.range(e.from,e.to)])}),l.hoverTooltip(hi,{hideOn:si}),yi];var Fe=function(e){e===void 0&&(e={});var{crosshairCursor:r=!1}=e,n=[];e.closeBracketsKeymap!==!1&&(n=n.concat(ce.closeBracketsKeymap)),e.defaultKeymap!==!1&&(n=n.concat(wr)),e.searchKeymap!==!1&&(n=n.concat(ri)),e.historyKeymap!==!1&&(n=n.concat(Vn)),e.foldKeymap!==!1&&(n=n.concat(l.foldKeymap)),e.completionKeymap!==!1&&(n=n.concat(ce.completionKeymap)),e.lintKeymap!==!1&&(n=n.concat(mi));var i=[];return e.lineNumbers!==!1&&i.push(l.lineNumbers()),e.highlightActiveLineGutter!==!1&&i.push(l.highlightActiveLineGutter()),e.highlightSpecialChars!==!1&&i.push(l.highlightSpecialChars()),e.history!==!1&&i.push(Bn()),e.foldGutter!==!1&&i.push(l.foldGutter()),e.drawSelection!==!1&&i.push(l.drawSelection()),e.dropCursor!==!1&&i.push(l.dropCursor()),e.allowMultipleSelections!==!1&&i.push(l.EditorState.allowMultipleSelections.of(!0)),e.indentOnInput!==!1&&i.push(l.indentOnInput()),e.syntaxHighlighting!==!1&&i.push(l.syntaxHighlighting(l.defaultHighlightStyle,{fallback:!0})),e.bracketMatching!==!1&&i.push(l.bracketMatching()),e.closeBrackets!==!1&&i.push(ce.closeBrackets()),e.autocompletion!==!1&&i.push(ce.autocompletion()),e.rectangularSelection!==!1&&i.push(l.rectangularSelection()),r!==!1&&i.push(l.crosshairCursor()),e.highlightActiveLine!==!1&&i.push(l.highlightActiveLine()),e.highlightSelectionMatches!==!1&&i.push(Wr()),e.tabSize&&typeof e.tabSize=="number"&&i.push(l.indentUnit.of(" ".repeat(e.tabSize))),i.concat([l.keymap.of(n.flat())]).filter(Boolean)};const Ci="#e5c07b",ut="#e06c75",bi="#56b6c2",vi="#ffffff",me="#abb2bf",Ne="#7d8799",Ei="#61afef",Mi="#98c379",ft="#d19a66",Ai="#c678dd",Di="#21252b",dt="#2c313a",mt="#282c34",Te="#353a42",Bi="#3E4451",gt="#528bff",hn=l.EditorView.theme({"&":{color:me,backgroundColor:mt},".cm-content":{caretColor:gt},".cm-cursor, .cm-dropCursor":{borderLeftColor:gt},"&.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground, .cm-selectionBackground, .cm-content ::selection":{backgroundColor:Bi},".cm-panels":{backgroundColor:Di,color:me},".cm-panels.cm-panels-top":{borderBottom:"2px solid black"},".cm-panels.cm-panels-bottom":{borderTop:"2px solid black"},".cm-searchMatch":{backgroundColor:"#72a1ff59",outline:"1px solid #457dff"},".cm-searchMatch.cm-searchMatch-selected":{backgroundColor:"#6199ff2f"},".cm-activeLine":{backgroundColor:"#6699ff0b"},".cm-selectionMatch":{backgroundColor:"#aafe661a"},"&.cm-focused .cm-matchingBracket, &.cm-focused .cm-nonmatchingBracket":{backgroundColor:"#bad0f847"},".cm-gutters":{backgroundColor:mt,color:Ne,border:"none"},".cm-activeLineGutter":{backgroundColor:dt},".cm-foldPlaceholder":{backgroundColor:"transparent",border:"none",color:"#ddd"},".cm-tooltip":{border:"none",backgroundColor:Te},".cm-tooltip .cm-tooltip-arrow:before":{borderTopColor:"transparent",borderBottomColor:"transparent"},".cm-tooltip .cm-tooltip-arrow:after":{borderTopColor:Te,borderBottomColor:Te},".cm-tooltip-autocomplete":{"& > ul > li[aria-selected]":{backgroundColor:dt,color:me}}},{dark:!0}),un=l.HighlightStyle.define([{tag:l.tags.keyword,color:Ai},{tag:[l.tags.name,l.tags.deleted,l.tags.character,l.tags.propertyName,l.tags.macroName],color:ut},{tag:[l.tags.function(l.tags.variableName),l.tags.labelName],color:Ei},{tag:[l.tags.color,l.tags.constant(l.tags.name),l.tags.standard(l.tags.name)],color:ft},{tag:[l.tags.definition(l.tags.name),l.tags.separator],color:me},{tag:[l.tags.typeName,l.tags.className,l.tags.number,l.tags.changed,l.tags.annotation,l.tags.modifier,l.tags.self,l.tags.namespace],color:Ci},{tag:[l.tags.operator,l.tags.operatorKeyword,l.tags.url,l.tags.escape,l.tags.regexp,l.tags.link,l.tags.special(l.tags.string)],color:bi},{tag:[l.tags.meta,l.tags.comment],color:Ne},{tag:l.tags.strong,fontWeight:"bold"},{tag:l.tags.emphasis,fontStyle:"italic"},{tag:l.tags.strikethrough,textDecoration:"line-through"},{tag:l.tags.link,color:Ne,textDecoration:"underline"},{tag:l.tags.heading,fontWeight:"bold",color:ut},{tag:[l.tags.atom,l.tags.bool,l.tags.special(l.tags.variableName)],color:ft},{tag:[l.tags.processingInstruction,l.tags.string,l.tags.inserted],color:Mi},{tag:l.tags.invalid,color:vi}]),fn=[hn,l.syntaxHighlighting(un)];var dn=l.EditorView.theme({"&":{backgroundColor:"#fff"}},{dark:!1}),mn=function(e){e===void 0&&(e={});var{indentWithTab:r=!0,editable:n=!0,readOnly:i=!1,theme:o="light",placeholder:s="",basicSetup:a=!0}=e,c=[];switch(r&&c.unshift(l.keymap.of([Tr])),a&&(typeof a=="boolean"?c.unshift(Fe()):c.unshift(Fe(a))),s&&c.unshift(l.placeholder(s)),o){case"light":c.push(dn);break;case"dark":c.push(fn);break;case"none":break;default:c.push(o);break}return n===!1&&c.push(l.EditorView.editable.of(!1)),i&&c.push(l.EditorState.readOnly.of(!0)),[...c]},gn=t=>({line:t.state.doc.lineAt(t.state.selection.main.from),lineCount:t.state.doc.lines,lineBreak:t.state.lineBreak,length:t.state.doc.length,readOnly:t.state.readOnly,tabSize:t.state.tabSize,selection:t.state.selection,selectionAsSingle:t.state.selection.asSingle().main,ranges:t.state.selection.ranges,selectionCode:t.state.sliceDoc(t.state.selection.main.from,t.state.selection.main.to),selections:t.state.selection.ranges.map(e=>t.state.sliceDoc(e.from,e.to)),selectedText:t.state.selection.ranges.some(e=>!e.empty)});class Li{constructor(e,r){this.timeLeftMS=void 0,this.timeoutMS=void 0,this.isCancelled=!1,this.isTimeExhausted=!1,this.callbacks=[],this.timeLeftMS=r,this.timeoutMS=r,this.callbacks.push(e)}tick(){if(!this.isCancelled&&!this.isTimeExhausted&&(this.timeLeftMS--,this.timeLeftMS<=0)){this.isTimeExhausted=!0;var e=this.callbacks.slice();this.callbacks.length=0,e.forEach(r=>{try{r()}catch(n){console.error("TimeoutLatch callback error:",n)}})}}cancel(){this.isCancelled=!0,this.callbacks.length=0}reset(){this.timeLeftMS=this.timeoutMS,this.isCancelled=!1,this.isTimeExhausted=!1}get isDone(){return this.isCancelled||this.isTimeExhausted}}class pt{constructor(){this.interval=null,this.latches=new Set}add(e){this.latches.add(e),this.start()}remove(e){this.latches.delete(e),this.latches.size===0&&this.stop()}start(){this.interval===null&&(this.interval=setInterval(()=>{this.latches.forEach(e=>{e.tick(),e.isDone&&this.remove(e)})},1))}stop(){this.interval!==null&&(clearInterval(this.interval),this.interval=null)}}var Re=null,wi=()=>typeof window>"u"?new pt:(Re||(Re=new pt),Re),qe=l.Annotation.define(),Ti=200,Ri=[];function pn(t){var{value:e,selection:r,onChange:n,onStatistics:i,onCreateEditor:o,onUpdate:s,extensions:a=Ri,autoFocus:c,theme:h="light",height:u=null,minHeight:f=null,maxHeight:d=null,width:m=null,minWidth:g=null,maxWidth:S=null,placeholder:y="",editable:P=!0,readOnly:F=!1,indentWithTab:p=!0,basicSetup:C=!0,root:z,initialState:X}=t,[G,se]=b.useState(),[k,I]=b.useState(),[K,$]=b.useState(),A=b.useState(()=>({current:null}))[0],N=b.useState(()=>({current:null}))[0],Me=l.EditorView.theme({"&":{height:u,minHeight:f,maxHeight:d,width:m,minWidth:g,maxWidth:S},"& .cm-scroller":{height:"100% !important"}}),Ae=l.EditorView.updateListener.of(T=>{if(T.docChanged&&typeof n=="function"&&!T.transactions.some(De=>De.annotation(qe))){A.current?A.current.reset():(A.current=new Li(()=>{if(N.current){var De=N.current;N.current=null,De()}A.current=null},Ti),wi().add(A.current));var q=T.state.doc,H=q.toString();n(H,T)}i&&i(gn(T))}),ae=mn({theme:h,editable:P,readOnly:F,placeholder:y,indentWithTab:p,basicSetup:C}),ee=[Ae,Me,...ae];return s&&typeof s=="function"&&ee.push(l.EditorView.updateListener.of(s)),ee=ee.concat(a),b.useLayoutEffect(()=>{if(G&&!K){var T={doc:e,selection:r,extensions:ee},q=X?l.EditorState.fromJSON(X.json,T,X.fields):l.EditorState.create(T);if($(q),!k){var H=new l.EditorView({state:q,parent:G,root:z});I(H),o&&o(H,q)}}return()=>{k&&($(void 0),I(void 0))}},[G,K]),b.useEffect(()=>{t.container&&se(t.container)},[t.container]),b.useEffect(()=>()=>{k&&(k.destroy(),I(void 0)),A.current&&(A.current.cancel(),A.current=null)},[k]),b.useEffect(()=>{c&&k&&k.focus()},[c,k]),b.useEffect(()=>{k&&k.dispatch({effects:l.StateEffect.reconfigure.of(ee)})},[h,a,u,f,d,m,g,S,y,P,F,p,C,n,s]),b.useEffect(()=>{if(e!==void 0){var T=k?k.state.doc.toString():"";if(k&&e!==T){var q=A.current&&!A.current.isDone,H=()=>{k&&e!==k.state.doc.toString()&&k.dispatch({changes:{from:0,to:k.state.doc.toString().length,insert:e||""},annotations:[qe.of(!0)]})};q?N.current=H:H()}}},[e,k]),{state:K,setState:$,view:k,setView:I,container:G,setContainer:se}}var Pi=["className","value","selection","extensions","onChange","onStatistics","onCreateEditor","onUpdate","autoFocus","theme","height","minHeight","maxHeight","width","minWidth","maxWidth","basicSetup","placeholder","indentWithTab","editable","readOnly","root","initialState"],yn=b.forwardRef((t,e)=>{var{className:r,value:n="",selection:i,extensions:o=[],onChange:s,onStatistics:a,onCreateEditor:c,onUpdate:h,autoFocus:u,theme:f="light",height:d,minHeight:m,maxHeight:g,width:S,minWidth:y,maxWidth:P,basicSetup:F,placeholder:p,indentWithTab:C,editable:z,readOnly:X,root:G,initialState:se}=t,k=je._objectWithoutPropertiesLoose(t,Pi),I=b.useRef(null),{state:K,view:$,container:A,setContainer:N}=pn({root:G,value:n,autoFocus:u,theme:f,height:d,minHeight:m,maxHeight:g,width:S,minWidth:y,maxWidth:P,basicSetup:F,placeholder:p,indentWithTab:C,editable:z,readOnly:X,selection:i,onChange:s,onStatistics:a,onCreateEditor:c,onUpdate:h,extensions:o,initialState:se});b.useImperativeHandle(e,()=>({editor:I.current,state:K,view:$}),[I,A,K,$]);var Me=b.useCallback(ae=>{I.current=ae,N(ae)},[N]);if(typeof n!="string")throw new Error("value must be typeof string but got "+typeof n);var Ae=typeof f=="string"?"cm-theme-"+f:"cm-theme";return Sn.jsx("div",je._extends({ref:Me,className:""+Ae+(r?" "+r:"")},k))});yn.displayName="CodeMirror";exports.Annotation=l.Annotation;exports.AnnotationType=l.AnnotationType;exports.BidiSpan=l.BidiSpan;exports.BlockInfo=l.BlockInfo;Object.defineProperty(exports,"BlockType",{enumerable:!0,get:()=>l.BlockType});exports.BlockWrapper=l.BlockWrapper;exports.ChangeDesc=l.ChangeDesc;exports.ChangeSet=l.ChangeSet;Object.defineProperty(exports,"CharCategory",{enumerable:!0,get:()=>l.CharCategory});exports.Compartment=l.Compartment;exports.Decoration=l.Decoration;Object.defineProperty(exports,"Direction",{enumerable:!0,get:()=>l.Direction});exports.EditorSelection=l.EditorSelection;exports.EditorState=l.EditorState;exports.EditorView=l.EditorView;exports.Facet=l.Facet;exports.GutterMarker=l.GutterMarker;exports.Line=l.Line;Object.defineProperty(exports,"MapMode",{enumerable:!0,get:()=>l.MapMode});exports.MatchDecorator=l.MatchDecorator;exports.Prec=l.Prec;exports.Range=l.Range;exports.RangeSet=l.RangeSet;exports.RangeSetBuilder=l.RangeSetBuilder;exports.RangeValue=l.RangeValue;exports.RectangleMarker=l.RectangleMarker;exports.SelectionRange=l.SelectionRange;exports.StateEffect=l.StateEffect;exports.StateEffectType=l.StateEffectType;exports.StateField=l.StateField;exports.Text=l.Text;exports.Transaction=l.Transaction;exports.ViewPlugin=l.ViewPlugin;exports.ViewUpdate=l.ViewUpdate;exports.WidgetType=l.WidgetType;exports.codePointAt=l.codePointAt;exports.codePointSize=l.codePointSize;exports.combineConfig=l.combineConfig;exports.countColumn=l.countColumn;exports.crosshairCursor=l.crosshairCursor;exports.drawSelection=l.drawSelection;exports.dropCursor=l.dropCursor;exports.findClusterBreak=l.findClusterBreak;exports.findColumn=l.findColumn;exports.fromCodePoint=l.fromCodePoint;exports.getPanel=l.getPanel;exports.getTooltip=l.getTooltip;exports.gutter=l.gutter;exports.gutterLineClass=l.gutterLineClass;exports.gutterWidgetClass=l.gutterWidgetClass;exports.gutters=l.gutters;exports.highlightActiveLine=l.highlightActiveLine;exports.highlightActiveLineGutter=l.highlightActiveLineGutter;exports.highlightSpecialChars=l.highlightSpecialChars;exports.hoverTooltip=l.hoverTooltip;exports.keymap=l.keymap;exports.layer=l.layer;exports.lineNumberMarkers=l.lineNumberMarkers;exports.lineNumberWidgetMarker=l.lineNumberWidgetMarker;exports.lineNumbers=l.lineNumbers;exports.logException=l.logException;exports.placeholder=l.placeholder;exports.rectangularSelection=l.rectangularSelection;exports.runScopeHandlers=l.runScopeHandlers;exports.showDialog=l.showDialog;exports.showPanel=l.showPanel;exports.showTooltip=l.showTooltip;exports.ExternalChange=qe;exports.basicSetup=Fe;exports.default=yn;exports.defaultLightThemeOption=dn;exports.getDefaultExtensions=mn;exports.getStatistics=gn;exports.oneDark=fn;exports.oneDarkHighlightStyle=un;exports.oneDarkTheme=hn;exports.useCodeMirror=pn;
|