@nice2dev/ui-forms 1.4.11 → 1.4.13
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/index.cjs +7 -7
- package/dist/index.d.ts +59 -0
- package/dist/index.mjs +2065 -2036
- package/dist/studio.cjs +8 -8
- package/dist/studio.d.ts +51 -0
- package/dist/studio.mjs +222 -202
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),
|
|
2
|
-
`).length)),onChange:m=>{const c=m.target.value;d(c);const p=c.trim();if(p===""){
|
|
3
|
-
`).length)),onChange:A=>{const Q=A.target.value;M(Q);try{const G=JSON.parse(Q);te(null),j(G)}catch(G){te(G instanceof Error?G.message:k("schemaForm.invalidJson","Invalid JSON"))}}}),D&&t.jsx("div",{className:"nice-schema-form__json-error",children:D})]}):t.jsx(h.NiceForm,{items:J,data:x,onFieldChange:L,columns:p,labelPosition:u,readOnly:y}),f&&Y.length>0&&t.jsx("ul",{className:"nice-schema-form__errors",role:"alert",children:Y.map((A,Q)=>t.jsx("li",{className:"nice-schema-form__error",children:A.message},`${A.field}-${Q}`))})]})}),He="__eeFid",Ci={},Kt={type:"object",properties:{name:{type:"string",title:"Name",minLength:1,description:"Unique technical name of the entity (PascalCase)."},displayName:{type:"string",title:"Display name",description:"Human-friendly name shown in the UI."},tableName:{type:"string",title:"Table name",description:"Database table that backs this entity."},description:{type:"string",title:"Description",description:"Optional notes about the entity's purpose."},entityIcon:{type:"string",title:"Icon",description:"Icon key shown next to the entity."},isAudited:{type:"boolean",title:"Audited",description:"Track who created/changed each record and when."},isSoftDeleteEnabled:{type:"boolean",title:"Soft delete",description:"Flag rows as deleted instead of physically removing them."}},required:["name"]},Mt={type:"object",properties:{name:{type:"string",title:"Name",minLength:1,description:"Field's technical name (the database column)."},displayName:{type:"string",title:"Display name",description:"Human-friendly label shown in the UI."},dataType:{type:"string",title:"Type",description:"Storage / data type of the field.",enum:["Guid","string","text","int","long","decimal","double","bool","DateTime","DateOnly","json"]},isPrimaryKey:{type:"boolean",title:"Primary key",description:"Primary key — uniquely identifies each record."},isForeignKey:{type:"boolean",title:"Foreign key",description:"Foreign key — references another entity's primary key."},isRequired:{type:"boolean",title:"Required",description:"Value must be provided (NOT NULL)."},isUnique:{type:"boolean",title:"Unique",description:"Each value must be unique across all records."},isIndexed:{type:"boolean",title:"Indexed",description:"Add a database index for faster lookups and filtering."},isNullable:{type:"boolean",title:"Nullable",description:"Allow empty (NULL) values."},maxLength:{type:"integer",title:"Max length",description:"Maximum number of characters (for string types)."},defaultValue:{type:"string",title:"Default",description:"Value used when none is provided."},description:{type:"string",title:"Description",description:"Optional notes about the field."},isComputed:{type:"boolean",title:"Computed",description:"Value is derived from an expression instead of stored input."},computedExpression:{type:"string",title:"Computed expression",description:"Expression used to compute the value (when Computed is on)."}},required:["name","dataType"]};function Ye({title:e,help:i}){return t.jsxs("span",{className:"nice-entity-editor__field-label",children:[e,i?t.jsx(h.NiceTooltip,{content:i,children:t.jsx("span",{className:"nice-entity-editor__help",role:"img","aria-label":i,children:t.jsx(h.NiceIcon,{name:"info",size:14})})}):null]})}function Ti({schema:e,value:i,onChange:n,readOnly:s}){const o=e.properties??{};return t.jsx("div",{className:"nice-entity-editor__field-form",children:Object.entries(o).map(([a,d])=>{const r=i[a],l=d.description,m=d.title??a;if(d.type==="boolean")return t.jsx("div",{className:"nice-entity-editor__field-row nice-entity-editor__field-row--check",children:t.jsx(h.NiceCheckbox,{label:t.jsx(Ye,{title:m,help:l}),checked:!!r,onChange:p=>n(a,p),disabled:s})},a);if(Array.isArray(d.enum)&&d.enum.length>0)return t.jsxs("div",{className:"nice-entity-editor__field-row",children:[t.jsx(Ye,{title:m,help:l}),t.jsx(h.NiceSelect,{options:d.enum.map(p=>({label:String(p),value:String(p)})),value:r==null?"":String(r),onChange:p=>n(a,p),clearable:!0,disabled:s})]},a);const c=d.type==="integer"||d.type==="number";return t.jsxs("div",{className:"nice-entity-editor__field-row",children:[t.jsx(Ye,{title:m,help:l}),t.jsx(h.NiceTextInput,{value:r==null?"":String(r),onChange:p=>n(a,c?p===""?void 0:Number(p):p),disabled:s})]},a)})})}function Ei({fields:e,onChange:i,fieldSchema:n,readOnly:s}){const{t:o}=h.useNiceTranslation(),[a,d]=w.useState(null),r=w.useMemo(()=>e.map((p,u)=>({...p,[He]:String(u)})),[e]),l=w.useMemo(()=>[{field:"name",header:o("entityEditor.field.name","Name"),sortable:!0,render:p=>t.jsx("span",{className:"nice-entity-editor__name",children:String(p??"")})},{field:"dataType",header:o("entityEditor.field.type","Type"),sortable:!0,render:p=>t.jsx(h.NiceBadge,{variant:"secondary",size:"sm",outline:!0,children:String(p??"—")})},{field:"__flags",header:o("entityEditor.field.flags","Constraints"),headerTooltip:o("entityEditor.field.flags.help","Key / required / unique / indexed constraints on this field"),render:(p,u)=>{const y=[[!!(u!=null&&u.isPrimaryKey),"PK",o("entityEditor.flag.pk","Primary key"),"info"],[!!(u!=null&&u.isForeignKey),"FK",o("entityEditor.flag.fk","Foreign key"),"info"],[!!(u!=null&&u.isRequired),"Req",o("entityEditor.flag.required","Required (NOT NULL)"),"warning"],[!!(u!=null&&u.isUnique),"Uniq",o("entityEditor.flag.unique","Unique"),"secondary"],[!!(u!=null&&u.isIndexed),"Idx",o("entityEditor.flag.indexed","Indexed"),"secondary"]];return t.jsx("span",{className:"nice-entity-editor__flags",children:y.filter(([f])=>f).map(([,f,v,S])=>t.jsx(h.NiceTooltip,{content:v,children:t.jsx(h.NiceBadge,{variant:S,size:"sm",children:f})},f))})}}],[]),m=(p,u,y)=>{i(e.map((f,v)=>v===p?{...f,[u]:y}:f))},c=()=>{const p=[...e,{name:`field${e.length+1}`,dataType:"string"}];i(p),d(p.length-1)};if(a!=null&&e[a]){const p=e[a];return t.jsxs("div",{className:"nice-entity-editor__field-detail",children:[t.jsxs("header",{className:"nice-entity-editor__edit-header",children:[t.jsx(h.NiceTooltip,{content:o("entityEditor.field.backHint","Back to the field list"),children:t.jsx(h.NiceButton,{variant:"ghost",size:"sm",leftIcon:t.jsx(h.NiceIcon,{name:"arrow-left",size:14}),onClick:()=>d(null),children:o("entityEditor.field.back","Fields")})}),t.jsx("span",{className:"nice-entity-editor__breadcrumb-sep",children:"/"}),t.jsx("span",{className:"nice-entity-editor__edit-title",children:String(p.name??o("entityEditor.field.untitled","New field"))})]}),t.jsx(Ti,{schema:n,value:p,onChange:(u,y)=>m(a,u,y),readOnly:s}),t.jsx("div",{className:"nice-entity-editor__field-detail-actions",children:t.jsx(h.NiceButton,{variant:"primary",size:"sm",onClick:()=>d(null),children:o("entityEditor.field.done","Done")})})]})}return t.jsx(h.NiceDataGrid,{data:r,keyField:He,columns:l,searchable:!0,searchPlaceholder:o("entityEditor.field.search","Search fields…"),emptyText:o("entityEditor.field.empty","No fields yet. Add one to define this entity."),onRowClick:p=>d(Number(p[He])),onRowDelete:s?void 0:p=>i(e.filter((u,y)=>y!==Number(p))),toolbar:s?void 0:t.jsx(h.NiceButton,{variant:"primary",size:"sm",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:c,children:o("entityEditor.field.add","Add field")}),compact:!0,striped:!0})}const at=w.forwardRef(function(i,n){const{value:s,defaultValue:o,onChange:a,entityMetaSchema:d=Kt,fieldSchema:r=Mt,fieldsKey:l="fields",validationsKey:m="validations",activeTab:c,defaultActiveTab:p="general",onActiveTabChange:u,extraTabs:y,readOnly:f=!1,className:v,style:S,id:g,"data-testid":b}=i,{t:I}=h.useNiceTranslation(),[_,k]=h.useControllableState({value:s,defaultValue:o,fallbackValue:Ci,onChange:a,componentName:"NiceEntityForm"}),[x,j]=h.useControllableState({value:c,defaultValue:p,fallbackValue:"general",onChange:u,componentName:"NiceEntityForm"}),N=w.useMemo(()=>{const J=_[l];return Array.isArray(J)?J:[]},[_,l]),z=w.useMemo(()=>{const J=L=>{const E=L.toLowerCase();return/(int|long|decimal|double|float|number|money)/.test(E)?"number":/bool/.test(E)?"boolean":/date|time/.test(E)?"date":"string"},Y=[];for(const L of N){const E=String(L.name??"");E&&Y.push({field:E,label:String(L.displayName??E),type:J(String(L.dataType??"string"))})}return Y},[N]),O=w.useMemo(()=>{const J=_[m];return Array.isArray(J)?J:[]},[_,m]),M=J=>{k({..._,...J})},D=[{id:"general",label:I("entityEditor.tab.general","General"),content:t.jsx(Te,{schema:d,value:_,onChange:J=>M(J),columns:2,readOnly:f,liveValidation:!0})},{id:"fields",label:I("entityEditor.tab.fields","Fields"),badge:N.length||void 0,content:t.jsx(Ei,{fields:N,onChange:J=>M({[l]:J}),fieldSchema:r,readOnly:f})},{id:"validation",label:I("entityEditor.tab.validation","Validation"),badge:O.length||void 0,content:t.jsx(h.NiceValidationBuilder,{fields:z,value:O,onChange:J=>M({[m]:J})})},...y??[]],te="nice-entity-form"+(v?` ${v}`:"");return t.jsx("div",{ref:n,id:g,className:te,style:S,"data-testid":b,children:t.jsx(h.NiceTabs,{tabs:D,activeTab:x,onChange:j,variant:"enclosed"})})}),Qe="__eeRid",$i=[{target:".nice-entity-editor",titleKey:"tutorial.entityEditor.intro.title",title:"Entity editor",contentKey:"tutorial.entityEditor.intro.content",content:"Browse your entities in the list, then click one (or “New entity”) to edit its metadata, fields and validation on a dedicated screen.",placement:"auto"}],Ft=w.forwardRef(function(i,n){const{value:s,defaultValue:o,onChange:a,entityMetaSchema:d=Kt,fieldSchema:r=Mt,fieldsKey:l="fields",validationsKey:m="validations",nameKey:c="name",renderErPreview:p,readOnly:u=!1,tutorial:y,className:f,style:v,id:S,"data-testid":g}=i,{t:b}=h.useNiceTranslation(),[I,_]=h.useControllableState({value:s,defaultValue:o,fallbackValue:[],onChange:a,componentName:"NiceEntityEditor"}),[k,x]=w.useState("list"),[j,N]=w.useState(0),[z,O]=w.useState("general"),M=Math.min(j,Math.max(0,I.length-1)),D=I[M],te=k==="edit"&&D!=null,J=w.useMemo(()=>I.map((U,ee)=>({...U,[Qe]:String(ee)})),[I]),Y=U=>{N(U),O("general"),x("edit")},L=()=>{const U=[...I,{[c]:`Entity${I.length+1}`,[l]:[]}];_(U),N(U.length-1),O("general"),x("edit")},E=U=>{_(I.filter((ee,Z)=>Z!==U)),N(ee=>ee>=U?Math.max(0,ee-1):ee)},A=w.useMemo(()=>[{field:c,header:b("entityEditor.col.name","Name"),sortable:!0,render:U=>t.jsx("span",{className:"nice-entity-editor__name",children:String(U??"")})},{field:"displayName",header:b("entityEditor.col.displayName","Display name"),sortable:!0,render:U=>t.jsx("span",{className:"nice-entity-editor__muted",children:String(U??"—")})},{field:"tableName",header:b("entityEditor.col.table","Table"),sortable:!0,render:U=>t.jsx("span",{className:"nice-entity-editor__muted",children:String(U??"—")})},{field:l,header:b("entityEditor.col.fields","Fields"),align:"center",headerTooltip:b("entityEditor.col.fields.help","Number of fields defined on this entity"),render:U=>t.jsx(h.NiceBadge,{variant:"secondary",size:"sm",children:Array.isArray(U)?U.length:0})},{field:"__flags",header:b("entityEditor.col.flags","Flags"),render:(U,ee)=>t.jsxs("span",{className:"nice-entity-editor__flags",children:[ee!=null&&ee.isAudited?t.jsx(h.NiceTooltip,{content:b("entityEditor.flag.audited","Audited — tracks who changed each record and when"),children:t.jsx(h.NiceBadge,{variant:"info",size:"sm",outline:!0,children:b("entityEditor.flag.audited.abbr","Audit")})}):null,ee!=null&&ee.isSoftDeleteEnabled?t.jsx(h.NiceTooltip,{content:b("entityEditor.flag.softDelete","Soft delete — rows are flagged deleted, never physically removed"),children:t.jsx(h.NiceBadge,{variant:"secondary",size:"sm",outline:!0,children:b("entityEditor.flag.softDelete.abbr","Soft-del")})}):null]})}],[c,l]),Q=p?[{id:"er",label:b("entityEditor.tab.er","ER diagram"),content:t.jsx("div",{className:"nice-entity-editor__er",children:p(I)})}]:void 0,G="nice-entity-editor"+(f?` ${f}`:"");return t.jsxs("div",{ref:n,id:S,className:G,style:v,"data-testid":g,children:[y&&t.jsx("div",{className:"nice-entity-editor__tutorial",children:t.jsx(h.NiceTutorialButton,{steps:h.resolveTutorial(y,$i)})}),te?t.jsxs("div",{className:"nice-entity-editor__edit",children:[t.jsxs("header",{className:"nice-entity-editor__edit-header",children:[t.jsx(h.NiceTooltip,{content:b("entityEditor.backHint","Back to the entity list"),children:t.jsx(h.NiceButton,{variant:"ghost",size:"sm",leftIcon:t.jsx(h.NiceIcon,{name:"arrow-left",size:14}),onClick:()=>x("list"),children:b("entityEditor.back","Entities")})}),t.jsx("span",{className:"nice-entity-editor__breadcrumb-sep",children:"/"}),t.jsx("span",{className:"nice-entity-editor__edit-title",children:String((D==null?void 0:D[c])??b("entityEditor.untitled","Untitled entity"))}),!u&&t.jsx(h.NiceTooltip,{content:b("entityEditor.deleteHint","Delete this entity"),children:t.jsx(h.NiceButton,{variant:"ghost",size:"sm",leftIcon:t.jsx(h.NiceIcon,{name:"trash",size:14}),onClick:()=>{E(M),x("list")},children:b("entityEditor.delete","Delete")})})]}),t.jsx(at,{value:D,onChange:U=>_(I.map((ee,Z)=>Z===M?U:ee)),entityMetaSchema:d,fieldSchema:r,fieldsKey:l,validationsKey:m,activeTab:z,onActiveTabChange:O,extraTabs:Q,readOnly:u})]}):t.jsx("div",{className:"nice-entity-editor__list-view",children:t.jsx(h.NiceDataGrid,{data:J,keyField:Qe,columns:A,searchable:!0,searchPlaceholder:b("entityEditor.search","Search entities…"),emptyText:b("entityEditor.empty","No entities yet. Create one to get started."),onRowClick:U=>Y(Number(U[Qe])),onRowDelete:u?void 0:U=>E(Number(U)),toolbar:u?void 0:t.jsx(h.NiceButton,{variant:"primary",size:"sm",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:L,children:b("entityEditor.new","New entity")}),compact:!0,striped:!0})})]})}),Ki=4e6;function Mi(e,i){const n=e.split(/\r?\n/),s=i.split(/\r?\n/);if(n.length*s.length>Ki)return[...n.map(c=>({type:"remove",text:c})),...s.map(c=>({type:"add",text:c}))];const o=n.length,a=s.length,d=Array.from({length:o+1},()=>new Uint32Array(a+1));for(let c=o-1;c>=0;c--)for(let p=a-1;p>=0;p--)d[c][p]=n[c]===s[p]?d[c+1][p+1]+1:Math.max(d[c+1][p],d[c][p+1]);const r=[];let l=0,m=0;for(;l<o&&m<a;)n[l]===s[m]?(r.push({type:"same",text:n[l]}),l++,m++):d[l+1][m]>=d[l][m+1]?r.push({type:"remove",text:n[l++]}):r.push({type:"add",text:s[m++]});for(;l<o;)r.push({type:"remove",text:n[l++]});for(;m<a;)r.push({type:"add",text:s[m++]});return r}function Ot({before:e,after:i,context:n=3}){const{t:s}=h.useNiceTranslation(),o=w.useMemo(()=>{const a=Mi(e,i),d=new Set;a.forEach((m,c)=>{if(m.type!=="same")for(let p=Math.max(0,c-n);p<=Math.min(a.length-1,c+n);p++)d.add(p)});const r=[];let l=0;return a.forEach((m,c)=>{d.has(c)?(l>0&&(r.push({type:"gap",count:l}),l=0),r.push(m)):l++}),l>0&&r.length>0&&r.push({type:"gap",count:l}),r},[e,i,n]);return o.length===0?t.jsx("p",{className:"nice-development-studio__muted",children:s("devStudio.diff.none","No changes.")}):t.jsx("pre",{className:"nice-development-studio__diff","aria-label":s("devStudio.diff.label","Changes"),children:o.map((a,d)=>a.type==="gap"?t.jsxs("span",{className:"nice-development-studio__diff-gap",children:[s("devStudio.diff.unchanged","{count} unchanged lines").replace("{count}",String(a.count)),`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),xe=require("@nice2dev/ui-core"),_=require("react"),h=require("@nice2dev/ui"),T=require("./studio.cjs"),pi=require("@nice2dev/ui-diagrams");function hi(e){var s,o;const i={text:"text",email:"email",password:"password",phone:"phone",url:"url",textarea:"textarea",number:"number",date:"date",datetime:"datetime",time:"time",select:"select",multiselect:"tags",checkbox:"checkbox",toggle:"toggle",radio:"radio",slider:"slider",rating:"rating",color:"color",file:"file",image:"file"},n=[];for(const a of e.sections)for(const d of a.fields)d.type==="heading"||d.type==="paragraph"||d.type==="divider"||d.type==="spacer"||d.type==="section"||n.push({field:d.name,label:d.label||d.name,type:i[d.type]||"text",placeholder:d.placeholder,hint:d.helpText,defaultValue:d.defaultValue,required:d.required||((s=d.validations)==null?void 0:s.some(r=>r.type==="required")),disabled:d.disabled,readOnly:d.readonly,group:a.title,options:(o=d.options)==null?void 0:o.map(r=>typeof r=="string"?{label:r,value:r}:{label:r.label,value:r.value})});return n}function Nt(e){var n;const i={text:"NiceTextInput",textarea:"NiceTextArea",number:"NiceNumberInput",email:"NiceTextInput",password:"NicePasswordInput",date:"NiceDateTimePicker",datetime:"NiceDateTimePicker",time:"NiceDateTimePicker",select:"NiceSelect",multiselect:"NiceTagBox",checkbox:"NiceCheckbox",toggle:"NiceToggle",radio:"NiceRadioGroup",slider:"NiceSlider",rating:"NiceRating",color:"NiceColorPicker"};return{dataField:e.name,label:{text:e.label},editorType:i[e.type]||"NiceTextInput",editorOptions:{placeholder:e.placeholder,disabled:e.disabled,readOnly:e.readonly,...e.props},colSpan:Math.ceil((e.colSpan||12)/6),validationRules:(n=e.validations)==null?void 0:n.map(s=>({type:s.type,message:s.message,...s.value!==void 0?{[s.type]:s.value}:{}})),helpText:e.helpText}}function vi(e){const i=[];for(const n of e.sections)n.title?i.push({itemType:"group",caption:n.title,colCount:n.columns||2,items:n.fields.map(Nt)}):i.push(...n.fields.map(Nt));return i}function fi(e){const i=[];e.version||i.push("Missing schema version"),e.id||i.push("Missing form ID"),(!e.sections||e.sections.length===0)&&i.push("Form must have at least one section");const n=new Set;for(const s of e.sections||[])for(const o of s.fields||[])o.id||i.push(`Field missing ID: ${o.name}`),o.name||i.push(`Field missing name: ${o.id}`),n.has(o.name)&&i.push(`Duplicate field name: ${o.name}`),n.add(o.name);return{valid:i.length===0,errors:i}}const gi={text:"text",string:"text",textarea:"textarea",number:"number",integer:"number",email:"email",password:"password",phone:"phone",tel:"phone",url:"url",date:"date",datetime:"datetime",time:"time",select:"select",dropdown:"select",multiselect:"multiselect",checkbox:"checkbox",boolean:"checkbox",toggle:"toggle",switch:"toggle",radio:"radio",slider:"slider",range:"slider",rating:"rating",stars:"rating",color:"color",file:"file",upload:"file",signature:"signature",richtext:"richtext",markdown:"markdown"};function Mt(e){return gi[String(e??"").toLowerCase()]??"text"}function yi(e){return(Array.isArray(e)?e:e.fields).map((n,s)=>{const o=n.name??n.field??n.id??`field${s+1}`,a=n.validation??{},d=[],r=(u,m)=>{m!==void 0&&d.push({type:u,value:m,...a.message?{message:a.message}:{}})};return r("min",a.min),r("max",a.max),r("minLength",a.minLength),r("maxLength",a.maxLength),r("pattern",a.pattern),{id:n.id??o,name:o,type:Mt(n.type),...n.label!==void 0?{label:n.label}:{},...n.placeholder!==void 0?{placeholder:n.placeholder}:{},...n.helpText!==void 0?{helpText:n.helpText}:{},...n.defaultValue!==void 0?{defaultValue:n.defaultValue}:{},...n.required?{required:!0}:{},...n.options?{options:[...n.options]}:{},...d.length?{validations:d}:{}}})}const Si={text:{type:"string"},textarea:{type:"string"},password:{type:"string",format:"password"},phone:{type:"string",format:"phone"},url:{type:"string",format:"uri"},email:{type:"string",format:"email"},date:{type:"string",format:"date"},datetime:{type:"string",format:"date-time"},time:{type:"string",format:"time"},color:{type:"string",format:"color"},number:{type:"number"},slider:{type:"number"},rating:{type:"integer"},checkbox:{type:"boolean"},toggle:{type:"boolean"},select:{type:"string"},radio:{type:"string"},multiselect:{type:"array",items:{type:"string"}},file:{type:"string",format:"data-url"},signature:{type:"string",format:"data-url"},richtext:{type:"string"},markdown:{type:"string"},code:{type:"string"},image:{type:"string",format:"uri"}};function ki(e,i){if(i)for(const n of i)switch(n.type){case"minLength":typeof n.value=="number"&&(e.minLength=n.value);break;case"maxLength":typeof n.value=="number"&&(e.maxLength=n.value);break;case"min":typeof n.value=="number"&&(e.minimum=n.value);break;case"max":typeof n.value=="number"&&(e.maximum=n.value);break;case"pattern":typeof n.value=="string"&&(e.pattern=n.value);break;case"email":e.format="email";break;case"url":e.format="uri";break}}function bi(e){if(e.type==="heading"||e.type==="paragraph"||e.type==="divider"||e.type==="spacer")return null;const i=Si[e.type];if(!i)return null;const n={...i};return e.label&&(n.title=e.label),e.helpText&&(n.description=e.helpText),e.defaultValue!==void 0&&(n.default=e.defaultValue),e.options&&(e.type==="select"||e.type==="radio")&&(n.enum=e.options.map(s=>typeof s=="string"?s:s.value)),e.options&&e.type==="multiselect"&&(n.items={type:"string",enum:e.options.map(s=>typeof s=="string"?s:String(s.value))}),ki(n,e.validations),n}function xi(e){const i={},n=[],s=a=>{var d;for(const r of a){if(r.type==="section"&&r.children){s(r.children);continue}const u=bi(r);u&&(i[r.name]=u,(r.required||(d=r.validations)!=null&&d.some(m=>m.type==="required"))&&n.push(r.name))}};for(const a of e.sections)s(a.fields);const o={$schema:"http://json-schema.org/draft-07/schema#",$id:e.id,type:"object",title:e.title,description:e.description,properties:i,additionalProperties:!1};return n.length>0&&(o.required=n),o}function wt(e){const{t:i}=xe.useNiceTranslation(),{value:n,onChange:s,readOnly:o}=e,[a,d]=_.useState(()=>{try{return n===void 0?"":JSON.stringify(n,null,2)}catch{return""}}),[r,u]=_.useState(null);return _.useEffect(()=>{try{d(n===void 0?"":JSON.stringify(n,null,2))}catch{}},[JSON.stringify(n)]),t.jsxs("div",{className:"nice-schema-form__json-field",children:[t.jsx("textarea",{className:"nice-schema-form__json-textarea",value:a,readOnly:o,spellCheck:!1,rows:Math.min(12,Math.max(3,a.split(`
|
|
2
|
+
`).length)),onChange:m=>{const c=m.target.value;d(c);const p=c.trim();if(p===""){u(null),s(void 0);return}try{s(JSON.parse(p)),u(null)}catch(l){u(l instanceof Error?l.message:i("jsonSchemaToFormItems.invalidJson","Invalid JSON"))}}}),r&&t.jsx("div",{className:"nice-schema-form__json-error",children:r})]})}function ji(e){switch(e){case"email":return"email";case"uri":case"url":return"url";case"date":return"date";case"date-time":return"datetime";case"time":return"time";case"color":return"color";case"password":return"password";case"phone":return"phone";case"data-url":return"file";default:return"text"}}function Ni(e,i,n,s={}){const o={field:e,label:i.title??e,required:n,hint:i.description,defaultValue:i.default};if(i.enum&&i.enum.length>0)return{...o,type:"select",options:i.enum.map(a=>({label:String(a),value:a}))};switch(i.type){case"number":case"integer":return{...o,type:"number"};case"boolean":return{...o,type:"checkbox"};case"string":return{...o,type:ji(i.format)};case"array":{const a=i.items;if(a!=null&&a.enum&&a.enum.length>0)return{...o,type:"tags",options:a.enum.map(d=>({label:String(d),value:String(d)}))};if((a==null?void 0:a.type)==="object"&&a.properties&&s.renderArrayField){const d=s.renderArrayField;return{...o,render:(r,u)=>d(r??[],u,a,o.label)}}return(a==null?void 0:a.type)==="string"||(a==null?void 0:a.type)==="number"||(a==null?void 0:a.type)==="integer"?{...o,type:"tags"}:{...o,render:(d,r)=>t.jsx(wt,{value:d,onChange:r})}}case"object":if(s.renderObjectField){const a=s.renderObjectField;return{...o,render:(d,r)=>a(d??{},r,i,o.label)}}return{...o,render:(a,d)=>t.jsx(wt,{value:a,onChange:d})};default:return{...o,type:"text"}}}function st(e,i={}){const{uiSchema:n,renderArrayField:s,renderObjectField:o}=i,a={renderArrayField:s,renderObjectField:o},d=e.properties??{},r=new Set(e.required??[]);return Object.keys(d).map(u=>{const m=Ni(u,d[u],r.has(u),a);return n!=null&&n[u]?{...m,...n[u]}:m})}const wi={text:"text",textarea:"textarea",number:"number",email:"email",password:"password",phone:"phone",url:"url",date:"date",datetime:"datetime",time:"time",select:"select",multiselect:"tags",checkbox:"checkbox",toggle:"toggle",radio:"radio",slider:"slider",rating:"rating",color:"color"};function ot(e,i={}){var o,a;const{uiSchema:n}=i,s=[];for(const d of e){if(d.type==="section"&&d.children){for(const m of ot(d.children,i))s.push(d.label?{...m,group:d.label}:m);continue}const r=wi[d.type];if(!r)continue;const u={field:d.name,label:d.label,type:r,required:d.required||((o=d.validations)==null?void 0:o.some(m=>m.type==="required")),placeholder:d.placeholder,hint:d.helpText,defaultValue:d.defaultValue,disabled:d.disabled,readOnly:d.readonly,options:(a=d.options)==null?void 0:a.map(m=>typeof m=="string"?{label:m,value:m}:{label:m.label,value:m.value})};s.push(n!=null&&n[d.name]?{...u,...n[d.name]}:u)}return s}function _t(e){return e==null||e===""||Array.isArray(e)&&e.length===0}function at(e,i){const n=[],s=i.properties??{},o=new Set(i.required??[]);for(const a of Object.keys(s)){const d=s[a],r=e[a];if(o.has(a)&&_t(r)){n.push({field:a,message:`${d.title??a} is required`});continue}if(!_t(r)&&(d.enum&&!d.enum.includes(r)&&n.push({field:a,message:`${d.title??a} must be one of: ${d.enum.join(", ")}`}),(d.type==="number"||d.type==="integer")&&typeof r=="number"&&(d.minimum!==void 0&&r<d.minimum&&n.push({field:a,message:`${d.title??a} must be ≥ ${d.minimum}`}),d.maximum!==void 0&&r>d.maximum&&n.push({field:a,message:`${d.title??a} must be ≤ ${d.maximum}`})),d.type==="string"&&typeof r=="string"&&(d.minLength!==void 0&&r.length<d.minLength&&n.push({field:a,message:`${d.title??a} must be at least ${d.minLength} chars`}),d.maxLength!==void 0&&r.length>d.maxLength&&n.push({field:a,message:`${d.title??a} must be at most ${d.maxLength} chars`}),d.pattern)))try{new RegExp(d.pattern).test(r)||n.push({field:a,message:`${d.title??a} has an invalid format`})}catch{}}return n}const Ye="__nafRid";function _i(e){return Array.isArray(e)?`[${e.length}]`:e&&typeof e=="object"?"{…}":e==null?"":String(e)}const dt=_.forwardRef(function(i,n){const{value:s,defaultValue:o,onChange:a,itemSchema:d,title:r,readOnly:u=!1,columns:m,className:c,style:p,"data-testid":l}=i,[g,f]=h.useControllableState({value:s,defaultValue:o,fallbackValue:[],onChange:a,componentName:"NiceArrayField"}),v=d.properties??{},S=_.useMemo(()=>(m??Object.keys(v)).map(x=>{const j=v[x]??{},N={field:x,header:j.title??x};return j.type==="boolean"?(N.render=P=>P?t.jsx(h.NiceIcon,{name:"check",size:14,title:"true"}):"",N.align="center"):(j.type==="array"||j.type==="object")&&(N.render=P=>_i(P)),N}),[d,m]),y=_.useMemo(()=>st(d),[d]),b=_.useMemo(()=>g.map((k,x)=>({...k,[Ye]:String(x)})),[g]),I=k=>{const{[Ye]:x,...j}=k;return j},w="nice-array-field"+(c?` ${c}`:"");return t.jsx("div",{ref:n,className:w,style:p,"data-testid":l,children:t.jsx(h.NiceDataGrid,{data:b,keyField:Ye,columns:S,editMode:"popup",formItems:y,editFormTitle:r?`${r} — item`:"Edit item",emptyText:`No items${r?` in ${r}`:""}`,compact:!0,onRowAdd:u?void 0:k=>f([...g,I(k)]),onRowEdit:u?void 0:(k,x)=>{const j=Number(k);f(g.map((N,P)=>P===j?I(x):N))},onRowDelete:u?void 0:k=>{const x=Number(k);f(g.filter((j,N)=>N!==x))}})})}),Ii=[{target:".nice-schema-form",titleKey:"tutorial.schemaForm.intro.title",title:"Schema form",contentKey:"tutorial.schemaForm.intro.content",content:"This form is generated from a schema. Required fields and validation errors are flagged; use the JSON toggle for raw editing.",placement:"auto"},{target:'[data-tour="sf-viewtoggle"]',titleKey:"tutorial.schemaForm.viewToggle.title",title:"Form ⇄ JSON",contentKey:"tutorial.schemaForm.viewToggle.content",content:"Switch between the visual form and the raw JSON value — handy for power users and copy/paste.",placement:"bottom"},{target:".nice-schema-form",titleKey:"tutorial.schemaForm.validation.title",title:"Live validation",contentKey:"tutorial.schemaForm.validation.content",content:"Values are validated against the schema as you type; any problems are listed below the form.",placement:"auto"}];function Ci(e){const i=[],n=s=>{for(const o of s){if(o.type==="section"&&o.children){n(o.children);continue}o.required&&i.push({id:`${o.name}-required`,field:o.name,op:"required"});for(const a of o.validations??[])i.push({id:`${o.name}-${a.type}`,field:o.name,op:a.type,value:typeof a.value=="boolean"?void 0:a.value,message:a.message??(a.type==="required"?`${o.label??o.name} is required`:void 0)})}};return n(e),i}function Ti(e,i){return h.evaluateValidation(Ci(e),i).filter(n=>n.severity==="error").map(n=>({field:n.field,message:n.message}))}const Ee=_.forwardRef(function(i,n){const{schema:s,fields:o,uiSchema:a,value:d,defaultValue:r,onChange:u,onValidate:m,showJsonView:c=!1,columns:p=1,labelPosition:l="top",readOnly:g=!1,liveValidation:f=!0,validationRules:v,tutorial:S,className:y,style:b,id:I,"data-testid":w}=i,{t:k}=h.useNiceTranslation(),[x,j]=h.useControllableState({value:d,defaultValue:r,fallbackValue:{},onChange:u,componentName:"NiceSchemaForm"}),[N,P]=_.useState(!1),[F,K]=_.useState(""),[G,ee]=_.useState(null),B=_.useMemo(()=>s?st(s,{uiSchema:a,renderArrayField:(q,M,H,U)=>t.jsx(dt,{value:q,onChange:M,itemSchema:H,title:U,readOnly:g})}):o?ot(o,{uiSchema:a}):[],[s,o,a,g]),ne=_.useMemo(()=>{const q=s?at(x,s):o?Ti(o,x):[];if(v!=null&&v.length){const M=h.evaluateValidation(v,x).filter(H=>H.severity==="error").map(H=>({field:H.field,message:H.message}));return[...q,...M]}return q},[s,o,x,v]);_.useEffect(()=>{m==null||m(ne)},[ne,m]),_.useEffect(()=>{if(N)try{K(JSON.stringify(x,null,2)),ee(null)}catch{}},[N,x]);const L=(q,M)=>{j({...x,[q]:M})},A="nice-schema-form"+(y?` ${y}`:"");return t.jsxs("div",{ref:n,id:I,className:A,style:b,"data-testid":w,children:[S&&t.jsx("div",{className:"nice-schema-form__tutorial",children:t.jsx(h.NiceTutorialButton,{steps:h.resolveTutorial(S,Ii)})}),c&&t.jsxs("div",{className:"nice-schema-form__toolbar","data-tour":"sf-viewtoggle",children:[t.jsx("button",{type:"button",className:"nice-schema-form__tab"+(N?"":" nice-schema-form__tab--active"),onClick:()=>P(!1),children:k("schemaForm.tab.form","Form")}),t.jsx(h.NiceTooltip,{content:k("schemaForm.tab.json.help","Edit the raw JSON value directly"),children:t.jsx("button",{type:"button",className:"nice-schema-form__tab"+(N?" nice-schema-form__tab--active":""),onClick:()=>P(!0),children:k("schemaForm.tab.json","JSON")})})]}),N?t.jsxs("div",{className:"nice-schema-form__json",children:[t.jsx("textarea",{className:"nice-schema-form__json-textarea",value:F,readOnly:g,spellCheck:!1,rows:Math.min(24,Math.max(6,F.split(`
|
|
3
|
+
`).length)),onChange:q=>{const M=q.target.value;K(M);try{const H=JSON.parse(M);ee(null),j(H)}catch(H){ee(H instanceof Error?H.message:k("schemaForm.invalidJson","Invalid JSON"))}}}),G&&t.jsx("div",{className:"nice-schema-form__json-error",children:G})]}):t.jsx(h.NiceForm,{items:B,data:x,onFieldChange:L,columns:p,labelPosition:l,readOnly:g}),f&&ne.length>0&&t.jsx("ul",{className:"nice-schema-form__errors",role:"alert",children:ne.map((q,M)=>t.jsx("li",{className:"nice-schema-form__error",children:q.message},`${q.field}-${M}`))})]})}),Qe="__eeFid",Ei={},Ft={type:"object",properties:{name:{type:"string",title:"Name",minLength:1,description:"Unique technical name of the entity (PascalCase)."},displayName:{type:"string",title:"Display name",description:"Human-friendly name shown in the UI."},tableName:{type:"string",title:"Table name",description:"Database table that backs this entity."},description:{type:"string",title:"Description",description:"Optional notes about the entity's purpose."},entityIcon:{type:"string",title:"Icon",description:"Icon key shown next to the entity."},isAudited:{type:"boolean",title:"Audited",description:"Track who created/changed each record and when."},isSoftDeleteEnabled:{type:"boolean",title:"Soft delete",description:"Flag rows as deleted instead of physically removing them."}},required:["name"]},Ot={type:"object",properties:{name:{type:"string",title:"Name",minLength:1,description:"Field's technical name (the database column)."},displayName:{type:"string",title:"Display name",description:"Human-friendly label shown in the UI."},dataType:{type:"string",title:"Type",description:"Storage / data type of the field.",enum:["Guid","string","text","int","long","decimal","double","bool","DateTime","DateOnly","json"]},isPrimaryKey:{type:"boolean",title:"Primary key",description:"Primary key — uniquely identifies each record."},isForeignKey:{type:"boolean",title:"Foreign key",description:"Foreign key — references another entity's primary key."},isRequired:{type:"boolean",title:"Required",description:"Value must be provided (NOT NULL)."},isUnique:{type:"boolean",title:"Unique",description:"Each value must be unique across all records."},isIndexed:{type:"boolean",title:"Indexed",description:"Add a database index for faster lookups and filtering."},isNullable:{type:"boolean",title:"Nullable",description:"Allow empty (NULL) values."},maxLength:{type:"integer",title:"Max length",description:"Maximum number of characters (for string types)."},defaultValue:{type:"string",title:"Default",description:"Value used when none is provided."},description:{type:"string",title:"Description",description:"Optional notes about the field."},isComputed:{type:"boolean",title:"Computed",description:"Value is derived from an expression instead of stored input."},computedExpression:{type:"string",title:"Computed expression",description:"Expression used to compute the value (when Computed is on)."}},required:["name","dataType"]};function Xe({title:e,help:i}){return t.jsxs("span",{className:"nice-entity-editor__field-label",children:[e,i?t.jsx(h.NiceTooltip,{content:i,children:t.jsx("span",{className:"nice-entity-editor__help",role:"img","aria-label":i,children:t.jsx(h.NiceIcon,{name:"info",size:14})})}):null]})}function $i({schema:e,value:i,onChange:n,readOnly:s}){const o=e.properties??{};return t.jsx("div",{className:"nice-entity-editor__field-form",children:Object.entries(o).map(([a,d])=>{const r=i[a],u=d.description,m=d.title??a;if(d.type==="boolean")return t.jsx("div",{className:"nice-entity-editor__field-row nice-entity-editor__field-row--check",children:t.jsx(h.NiceCheckbox,{label:t.jsx(Xe,{title:m,help:u}),checked:!!r,onChange:p=>n(a,p),disabled:s})},a);if(Array.isArray(d.enum)&&d.enum.length>0)return t.jsxs("div",{className:"nice-entity-editor__field-row",children:[t.jsx(Xe,{title:m,help:u}),t.jsx(h.NiceSelect,{options:d.enum.map(p=>({label:String(p),value:String(p)})),value:r==null?"":String(r),onChange:p=>n(a,p),clearable:!0,disabled:s})]},a);const c=d.type==="integer"||d.type==="number";return t.jsxs("div",{className:"nice-entity-editor__field-row",children:[t.jsx(Xe,{title:m,help:u}),t.jsx(h.NiceTextInput,{value:r==null?"":String(r),onChange:p=>n(a,c?p===""?void 0:Number(p):p),disabled:s})]},a)})})}function Ki({fields:e,onChange:i,fieldSchema:n,readOnly:s}){const{t:o}=h.useNiceTranslation(),[a,d]=_.useState(null),r=_.useMemo(()=>e.map((p,l)=>({...p,[Qe]:String(l)})),[e]),u=_.useMemo(()=>[{field:"name",header:o("entityEditor.field.name","Name"),sortable:!0,render:p=>t.jsx("span",{className:"nice-entity-editor__name",children:String(p??"")})},{field:"dataType",header:o("entityEditor.field.type","Type"),sortable:!0,render:p=>t.jsx(h.NiceBadge,{variant:"secondary",size:"sm",outline:!0,children:String(p??"—")})},{field:"__flags",header:o("entityEditor.field.flags","Constraints"),headerTooltip:o("entityEditor.field.flags.help","Key / required / unique / indexed constraints on this field"),render:(p,l)=>{const g=[[!!(l!=null&&l.isPrimaryKey),"PK",o("entityEditor.flag.pk","Primary key"),"info"],[!!(l!=null&&l.isForeignKey),"FK",o("entityEditor.flag.fk","Foreign key"),"info"],[!!(l!=null&&l.isRequired),"Req",o("entityEditor.flag.required","Required (NOT NULL)"),"warning"],[!!(l!=null&&l.isUnique),"Uniq",o("entityEditor.flag.unique","Unique"),"secondary"],[!!(l!=null&&l.isIndexed),"Idx",o("entityEditor.flag.indexed","Indexed"),"secondary"]];return t.jsx("span",{className:"nice-entity-editor__flags",children:g.filter(([f])=>f).map(([,f,v,S])=>t.jsx(h.NiceTooltip,{content:v,children:t.jsx(h.NiceBadge,{variant:S,size:"sm",children:f})},f))})}}],[]),m=(p,l,g)=>{i(e.map((f,v)=>v===p?{...f,[l]:g}:f))},c=()=>{const p=[...e,{name:`field${e.length+1}`,dataType:"string"}];i(p),d(p.length-1)};if(a!=null&&e[a]){const p=e[a];return t.jsxs("div",{className:"nice-entity-editor__field-detail",children:[t.jsxs("header",{className:"nice-entity-editor__edit-header",children:[t.jsx(h.NiceTooltip,{content:o("entityEditor.field.backHint","Back to the field list"),children:t.jsx(h.NiceButton,{variant:"ghost",size:"sm",leftIcon:t.jsx(h.NiceIcon,{name:"arrow-left",size:14}),onClick:()=>d(null),children:o("entityEditor.field.back","Fields")})}),t.jsx("span",{className:"nice-entity-editor__breadcrumb-sep",children:"/"}),t.jsx("span",{className:"nice-entity-editor__edit-title",children:String(p.name??o("entityEditor.field.untitled","New field"))})]}),t.jsx($i,{schema:n,value:p,onChange:(l,g)=>m(a,l,g),readOnly:s}),t.jsx("div",{className:"nice-entity-editor__field-detail-actions",children:t.jsx(h.NiceButton,{variant:"primary",size:"sm",onClick:()=>d(null),children:o("entityEditor.field.done","Done")})})]})}return t.jsx(h.NiceDataGrid,{data:r,keyField:Qe,columns:u,searchable:!0,searchPlaceholder:o("entityEditor.field.search","Search fields…"),emptyText:o("entityEditor.field.empty","No fields yet. Add one to define this entity."),onRowClick:p=>d(Number(p[Qe])),onRowDelete:s?void 0:p=>i(e.filter((l,g)=>g!==Number(p))),toolbar:s?void 0:t.jsx(h.NiceButton,{variant:"primary",size:"sm",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:c,children:o("entityEditor.field.add","Add field")}),compact:!0,striped:!0})}const rt=_.forwardRef(function(i,n){const{value:s,defaultValue:o,onChange:a,entityMetaSchema:d=Ft,fieldSchema:r=Ot,fieldsKey:u="fields",validationsKey:m="validations",activeTab:c,defaultActiveTab:p="general",onActiveTabChange:l,extraTabs:g,readOnly:f=!1,className:v,style:S,id:y,"data-testid":b}=i,{t:I}=h.useNiceTranslation(),[w,k]=h.useControllableState({value:s,defaultValue:o,fallbackValue:Ei,onChange:a,componentName:"NiceEntityForm"}),[x,j]=h.useControllableState({value:c,defaultValue:p,fallbackValue:"general",onChange:l,componentName:"NiceEntityForm"}),N=_.useMemo(()=>{const B=w[u];return Array.isArray(B)?B:[]},[w,u]),P=_.useMemo(()=>{const B=L=>{const A=L.toLowerCase();return/(int|long|decimal|double|float|number|money)/.test(A)?"number":/bool/.test(A)?"boolean":/date|time/.test(A)?"date":"string"},ne=[];for(const L of N){const A=String(L.name??"");A&&ne.push({field:A,label:String(L.displayName??A),type:B(String(L.dataType??"string"))})}return ne},[N]),F=_.useMemo(()=>{const B=w[m];return Array.isArray(B)?B:[]},[w,m]),K=B=>{k({...w,...B})},G=[{id:"general",label:I("entityEditor.tab.general","General"),content:t.jsx(Ee,{schema:d,value:w,onChange:B=>K(B),columns:2,readOnly:f,liveValidation:!0})},{id:"fields",label:I("entityEditor.tab.fields","Fields"),badge:N.length||void 0,content:t.jsx(Ki,{fields:N,onChange:B=>K({[u]:B}),fieldSchema:r,readOnly:f})},{id:"validation",label:I("entityEditor.tab.validation","Validation"),badge:F.length||void 0,content:t.jsx(h.NiceValidationBuilder,{fields:P,value:F,onChange:B=>K({[m]:B})})},...g??[]],ee="nice-entity-form"+(v?` ${v}`:"");return t.jsx("div",{ref:n,id:y,className:ee,style:S,"data-testid":b,children:t.jsx(h.NiceTabs,{tabs:G,activeTab:x,onChange:j,variant:"enclosed"})})}),Ze="__eeRid",Mi=[{target:".nice-entity-editor",titleKey:"tutorial.entityEditor.intro.title",title:"Entity editor",contentKey:"tutorial.entityEditor.intro.content",content:"Browse your entities in the list, then click one (or “New entity”) to edit its metadata, fields and validation on a dedicated screen.",placement:"auto"}],zt=_.forwardRef(function(i,n){const{value:s,defaultValue:o,onChange:a,entityMetaSchema:d=Ft,fieldSchema:r=Ot,fieldsKey:u="fields",validationsKey:m="validations",nameKey:c="name",renderErPreview:p,readOnly:l=!1,tutorial:g,className:f,style:v,id:S,"data-testid":y}=i,{t:b}=h.useNiceTranslation(),[I,w]=h.useControllableState({value:s,defaultValue:o,fallbackValue:[],onChange:a,componentName:"NiceEntityEditor"}),[k,x]=_.useState("list"),[j,N]=_.useState(0),[P,F]=_.useState("general"),K=Math.min(j,Math.max(0,I.length-1)),G=I[K],ee=k==="edit"&&G!=null,B=_.useMemo(()=>I.map((U,X)=>({...U,[Ze]:String(X)})),[I]),ne=U=>{N(U),F("general"),x("edit")},L=()=>{const U=[...I,{[c]:`Entity${I.length+1}`,[u]:[]}];w(U),N(U.length-1),F("general"),x("edit")},A=U=>{w(I.filter((X,ye)=>ye!==U)),N(X=>X>=U?Math.max(0,X-1):X)},q=_.useMemo(()=>[{field:c,header:b("entityEditor.col.name","Name"),sortable:!0,render:U=>t.jsx("span",{className:"nice-entity-editor__name",children:String(U??"")})},{field:"displayName",header:b("entityEditor.col.displayName","Display name"),sortable:!0,render:U=>t.jsx("span",{className:"nice-entity-editor__muted",children:String(U??"—")})},{field:"tableName",header:b("entityEditor.col.table","Table"),sortable:!0,render:U=>t.jsx("span",{className:"nice-entity-editor__muted",children:String(U??"—")})},{field:u,header:b("entityEditor.col.fields","Fields"),align:"center",headerTooltip:b("entityEditor.col.fields.help","Number of fields defined on this entity"),render:U=>t.jsx(h.NiceBadge,{variant:"secondary",size:"sm",children:Array.isArray(U)?U.length:0})},{field:"__flags",header:b("entityEditor.col.flags","Flags"),render:(U,X)=>t.jsxs("span",{className:"nice-entity-editor__flags",children:[X!=null&&X.isAudited?t.jsx(h.NiceTooltip,{content:b("entityEditor.flag.audited","Audited — tracks who changed each record and when"),children:t.jsx(h.NiceBadge,{variant:"info",size:"sm",outline:!0,children:b("entityEditor.flag.audited.abbr","Audit")})}):null,X!=null&&X.isSoftDeleteEnabled?t.jsx(h.NiceTooltip,{content:b("entityEditor.flag.softDelete","Soft delete — rows are flagged deleted, never physically removed"),children:t.jsx(h.NiceBadge,{variant:"secondary",size:"sm",outline:!0,children:b("entityEditor.flag.softDelete.abbr","Soft-del")})}):null]})}],[c,u]),M=p?[{id:"er",label:b("entityEditor.tab.er","ER diagram"),content:t.jsx("div",{className:"nice-entity-editor__er",children:p(I)})}]:void 0,H="nice-entity-editor"+(f?` ${f}`:"");return t.jsxs("div",{ref:n,id:S,className:H,style:v,"data-testid":y,children:[g&&t.jsx("div",{className:"nice-entity-editor__tutorial",children:t.jsx(h.NiceTutorialButton,{steps:h.resolveTutorial(g,Mi)})}),ee?t.jsxs("div",{className:"nice-entity-editor__edit",children:[t.jsxs("header",{className:"nice-entity-editor__edit-header",children:[t.jsx(h.NiceTooltip,{content:b("entityEditor.backHint","Back to the entity list"),children:t.jsx(h.NiceButton,{variant:"ghost",size:"sm",leftIcon:t.jsx(h.NiceIcon,{name:"arrow-left",size:14}),onClick:()=>x("list"),children:b("entityEditor.back","Entities")})}),t.jsx("span",{className:"nice-entity-editor__breadcrumb-sep",children:"/"}),t.jsx("span",{className:"nice-entity-editor__edit-title",children:String((G==null?void 0:G[c])??b("entityEditor.untitled","Untitled entity"))}),!l&&t.jsx(h.NiceTooltip,{content:b("entityEditor.deleteHint","Delete this entity"),children:t.jsx(h.NiceButton,{variant:"ghost",size:"sm",leftIcon:t.jsx(h.NiceIcon,{name:"trash",size:14}),onClick:()=>{A(K),x("list")},children:b("entityEditor.delete","Delete")})})]}),t.jsx(rt,{value:G,onChange:U=>w(I.map((X,ye)=>ye===K?U:X)),entityMetaSchema:d,fieldSchema:r,fieldsKey:u,validationsKey:m,activeTab:P,onActiveTabChange:F,extraTabs:M,readOnly:l})]}):t.jsx("div",{className:"nice-entity-editor__list-view",children:t.jsx(h.NiceDataGrid,{data:B,keyField:Ze,columns:q,searchable:!0,searchPlaceholder:b("entityEditor.search","Search entities…"),emptyText:b("entityEditor.empty","No entities yet. Create one to get started."),onRowClick:U=>ne(Number(U[Ze])),onRowDelete:l?void 0:U=>A(Number(U)),toolbar:l?void 0:t.jsx(h.NiceButton,{variant:"primary",size:"sm",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:L,children:b("entityEditor.new","New entity")}),compact:!0,striped:!0})})]})}),Fi=4e6;function Oi(e,i){const n=e.split(/\r?\n/),s=i.split(/\r?\n/);if(n.length*s.length>Fi)return[...n.map(c=>({type:"remove",text:c})),...s.map(c=>({type:"add",text:c}))];const o=n.length,a=s.length,d=Array.from({length:o+1},()=>new Uint32Array(a+1));for(let c=o-1;c>=0;c--)for(let p=a-1;p>=0;p--)d[c][p]=n[c]===s[p]?d[c+1][p+1]+1:Math.max(d[c+1][p],d[c][p+1]);const r=[];let u=0,m=0;for(;u<o&&m<a;)n[u]===s[m]?(r.push({type:"same",text:n[u]}),u++,m++):d[u+1][m]>=d[u][m+1]?r.push({type:"remove",text:n[u++]}):r.push({type:"add",text:s[m++]});for(;u<o;)r.push({type:"remove",text:n[u++]});for(;m<a;)r.push({type:"add",text:s[m++]});return r}function Dt({before:e,after:i,context:n=3}){const{t:s}=h.useNiceTranslation(),o=_.useMemo(()=>{const a=Oi(e,i),d=new Set;a.forEach((m,c)=>{if(m.type!=="same")for(let p=Math.max(0,c-n);p<=Math.min(a.length-1,c+n);p++)d.add(p)});const r=[];let u=0;return a.forEach((m,c)=>{d.has(c)?(u>0&&(r.push({type:"gap",count:u}),u=0),r.push(m)):u++}),u>0&&r.length>0&&r.push({type:"gap",count:u}),r},[e,i,n]);return o.length===0?t.jsx("p",{className:"nice-development-studio__muted",children:s("devStudio.diff.none","No changes.")}):t.jsx("pre",{className:"nice-development-studio__diff","aria-label":s("devStudio.diff.label","Changes"),children:o.map((a,d)=>a.type==="gap"?t.jsxs("span",{className:"nice-development-studio__diff-gap",children:[s("devStudio.diff.unchanged","{count} unchanged lines").replace("{count}",String(a.count)),`
|
|
4
4
|
`]},d):t.jsxs("span",{className:`nice-development-studio__diff-line nice-development-studio__diff-line--${a.type}`,children:[a.type==="add"?"+ ":a.type==="remove"?"- ":" ",a.text,`
|
|
5
|
-
`]},d))})}function Fi({open:e,onClose:i,session:n,preset:s,locales:o,prefill:a,onCreated:d}){var I,_,k,x;const{t:r}=h.useNiceTranslation(),l=n.workspaces.filter(j=>!j.readOnly),m=s.requiredLocales??[],[c,p]=w.useState(()=>{var j;return{workspaceId:a.workspaceId&&l.some(N=>N.id===a.workspaceId)?a.workspaceId:((j=l[0])==null?void 0:j.id)??"",packageId:a.packageId,name:"",entities:[{name:"Item",fields:[{name:"Id",dataType:"Guid",isPrimaryKey:!0,isRequired:!0},{name:"Name",dataType:"string",isRequired:!0,maxLength:200}]}],locales:[...new Set([...m,...o.slice(0,2)])],views:!0,permissions:!0}}),[u,y]=w.useState(null),[f,v]=w.useState(!1),S=w.useMemo(()=>[...new Set((n.modulesByWs[c.workspaceId]??[]).map(j=>j.packageId).filter(Boolean))].sort(),[n.modulesByWs,c.workspaceId]);if(!e)return null;const g=new Set(Object.values(n.modulesByWs).flatMap(j=>j.map(N=>N.id))),b=async()=>{s.generateModule&&c.name.trim()&&y(await s.generateModule({...c,name:c.name.trim()},{existingIds:g}))};return t.jsx(h.NiceModal,{open:e,onClose:i,title:r("devStudio.wizard.title","New module"),size:"xl","data-testid":"studio-module-wizard",children:t.jsx(h.NiceWizard,{finishLabel:r("devStudio.wizard.create","Create module"),onCancel:i,onStepChange:j=>{j===3&&b()},onComplete:async()=>{if(f)return;v(!0);const j=await n.createModule({...c,name:c.name.trim()});v(!1),j&&(d({workspaceId:j.workspaceId,id:j.id}),i())},steps:[{id:"identity",title:r("devStudio.wizard.identity","Name and place"),validate:()=>c.name.trim()&&c.workspaceId?!0:r("devStudio.wizard.needName","Give the module a name."),content:t.jsxs("div",{className:"nice-development-studio__form",children:[t.jsx(h.NiceSelect,{label:r("devStudio.wizard.workspace","Project"),value:c.workspaceId,options:l.map(j=>({value:j.id,label:j.label})),onChange:j=>p({...c,workspaceId:String(j)})}),t.jsx(h.NiceTextInput,{label:r("devStudio.wizard.package","Package"),value:c.packageId??"",placeholder:S.join(", "),onChange:j=>p({...c,packageId:j||void 0})}),t.jsx(h.NiceTextInput,{label:r("devStudio.wizard.name","Name"),value:c.name,placeholder:r("devStudio.wizard.namePlaceholder","e.g. Bike rental"),onChange:j=>p({...c,name:j})}),t.jsx(h.NiceTextInput,{label:r("devStudio.wizard.description","Description"),value:c.description??"",onChange:j=>p({...c,description:j||void 0})})]})},{id:"entities",title:r("devStudio.wizard.entities","Entities"),content:t.jsx(Ft,{value:c.entities,onChange:j=>p({...c,entities:j}),entityMetaSchema:(I=s.entities)==null?void 0:I.entityMetaSchema,fieldSchema:(_=s.entities)==null?void 0:_.fieldSchema,fieldsKey:(k=s.entities)==null?void 0:k.fieldsKey,nameKey:(x=s.entities)==null?void 0:x.nameKey})},{id:"options",title:r("devStudio.wizard.options","Options"),content:t.jsxs("div",{className:"nice-development-studio__form",children:[t.jsxs("fieldset",{className:"nice-development-studio__fieldset",children:[t.jsx("legend",{children:r("devStudio.wizard.locales","Languages")}),[...new Set([...m,...o])].map(j=>t.jsx(h.NiceCheckbox,{label:j,checked:c.locales.includes(j),disabled:m.includes(j),onChange:N=>p({...c,locales:N?[...c.locales,j]:c.locales.filter(z=>z!==j)})},j))]}),t.jsx(h.NiceCheckbox,{label:r("devStudio.wizard.views","A list and a form view per entity"),checked:!!c.views,onChange:j=>p({...c,views:j})}),t.jsx(h.NiceCheckbox,{label:r("devStudio.wizard.permissions","Viewer, editor and admin permissions"),checked:!!c.permissions,onChange:j=>p({...c,permissions:j})})]})},{id:"review",title:r("devStudio.wizard.review","Review"),content:u?t.jsxs("div",{children:[t.jsx("p",{children:r("devStudio.wizard.willCreate","Module {id} with these files:").replace("{id}",u.id)}),t.jsx("ul",{className:"nice-development-studio__list",children:u.files.map(j=>t.jsxs("li",{children:[t.jsx(h.NiceIcon,{name:"file",size:12})," ",j.path]},j.path))})]}):t.jsx("p",{className:"nice-development-studio__muted",children:r("devStudio.wizard.generating","Generating…")})}]})})}function Oi({open:e,moduleLabel:i,changes:n,original:s,conflict:o,onSave:a,onOverwrite:d,onReload:r,onClose:l}){const{t:m}=h.useNiceTranslation();return e?t.jsxs(h.NiceModal,{open:e,onClose:l,size:"xl",title:m("devStudio.review.title","Save {module}").replace("{module}",i),"data-testid":"studio-review",footer:o?t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{variant:"ghost",onClick:l,children:m("devStudio.cancel","Cancel")}),t.jsx(h.NiceButton,{variant:"secondary",onClick:r,children:m("devStudio.review.reload","Reload theirs (drop mine)")}),t.jsx(h.NiceButton,{variant:"danger",onClick:d,children:m("devStudio.review.overwrite","Overwrite with mine")})]}):t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{variant:"ghost",onClick:l,children:m("devStudio.cancel","Cancel")}),t.jsx(h.NiceButton,{variant:"primary",onClick:a,children:m("devStudio.review.save","Save {count} files").replace("{count}",String(n.length))})]}),children:[o&&t.jsxs("p",{className:"nice-development-studio__error",role:"alert",children:[m("devStudio.review.conflict","These files changed since you opened them:")," ",o.conflicts.map(c=>c.path).join(", ")]}),n.map(c=>t.jsxs("section",{className:"nice-development-studio__source",children:[t.jsx("h4",{className:"nice-development-studio__source-title",children:c.type==="delete"?m("devStudio.change.delete","Delete {path}").replace("{path}",c.path):c.baseVersion===void 0&&!s(c.path)?m("devStudio.change.new","New file {path}").replace("{path}",c.path):c.path}),t.jsx(Ot,{before:s(c.path),after:c.type==="write"?c.text:""})]},c.path))]}):null}function zi({open:e,moduleId:i,templates:n,onApply:s,onClose:o}){const{t:a}=h.useNiceTranslation(),d=w.useMemo(()=>n.filter(p=>p.modules.some(u=>u.moduleId===i)).map(p=>p.id),[n,i]),[r,l]=w.useState(d);if(!e)return null;const m=n.map(p=>{var u,y;return{id:p.id,label:((u=p.translations.en)==null?void 0:u.name)??((y=Object.values(p.translations)[0])==null?void 0:y.name)??p.id}}),c=[{field:"label",header:a("devStudio.explorer.name","Name")}];return t.jsx(h.NiceModal,{open:e,onClose:o,title:a("devStudio.picker.title","Templates with {module}").replace("{module}",i),"data-testid":"studio-template-picker",footer:t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{variant:"ghost",onClick:o,children:a("devStudio.cancel","Cancel")}),t.jsx(h.NiceButton,{variant:"primary",onClick:()=>{const p=n.filter(u=>r.includes(u.id)!==d.includes(u.id)).map(u=>({...u,modules:r.includes(u.id)?[...u.modules,{moduleId:i}]:u.modules.filter(y=>y.moduleId!==i)}));s(p)},children:a("devStudio.apply","Apply")})]}),children:t.jsx(h.NiceTreeGrid,{data:m,columns:c,keyField:"id",sortable:!1,compact:!0,checkable:!0,checkedKeys:r,onCheckedChange:l,searchable:!0,"aria-label":a("devStudio.explorer.templates","Templates")})})}function wt({open:e,title:i,workspaces:n,workspaceId:s,idLabel:o,initialId:a="",withLabel:d,onSubmit:r,onClose:l}){var S;const{t:m}=h.useNiceTranslation(),[c,p]=w.useState(s??((S=n[0])==null?void 0:S.id)??""),[u,y]=w.useState(a),[f,v]=w.useState("");return e?t.jsx(h.NiceModal,{open:e,onClose:l,title:i,footer:t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{variant:"ghost",onClick:l,children:m("devStudio.cancel","Cancel")}),t.jsx(h.NiceButton,{variant:"primary",disabled:!u.trim()||!c,onClick:()=>r({workspaceId:c,id:u.trim(),label:f.trim()||u.trim()}),children:m("devStudio.ok","OK")})]}),children:t.jsxs("div",{className:"nice-development-studio__form",children:[t.jsx(h.NiceSelect,{label:m("devStudio.wizard.workspace","Project"),value:c,options:n.map(g=>({value:g.id,label:g.label})),onChange:g=>p(String(g))}),t.jsx(h.NiceTextInput,{label:o,value:u,onChange:y}),d&&t.jsx(h.NiceTextInput,{label:m("devStudio.package.label","Name"),value:f,onChange:v})]})}):null}const _t=e=>JSON.stringify(e??null,null,2);function Le({value:e,onChange:i,readOnly:n,height:s=320,label:o}){const{t:a}=h.useNiceTranslation(),[d,r]=w.useState(()=>_t(e)),[l,m]=w.useState(null),c=w.useRef(e);return w.useEffect(()=>{c.current!==e&&(c.current=e,r(_t(e)),m(null))},[e]),t.jsxs("div",{className:"nice-development-studio__json",role:"group","aria-label":o,children:[t.jsx(h.NiceSimpleCodeEditor,{value:d,language:"json",height:s,readOnly:n,lineNumbers:!0,onChange:p=>{r(p);try{const u=JSON.parse(p);m(null),c.current=u,i==null||i(u)}catch(u){m(u instanceof Error?u.message:String(u))}}}),l&&t.jsxs("p",{className:"nice-development-studio__error",role:"alert",children:[a("devStudio.json.invalid","Not valid JSON:")," ",l]})]})}const H=e=>`${e.workspaceId}/${e.id}`;function Xe(e,i,n){const s=new Set(e.deleted),o=new Map;for(const u of e.files)s.has(u.path)||o.set(u.path,e.raw[u.path]!==void 0?{...u,text:e.raw[u.path]}:u);for(const[u,y]of Object.entries(e.raw))!o.has(u)&&!s.has(u)&&o.set(u,{path:u,text:y});const a=[...o.values()],d={moduleId:e.key.id,files:a,locales:n},r=$.buildDocuments(i.kinds,a,d),l=new Map(a.map(u=>[u.path,u.text])),m={};for(const u of r)if(u.key in e.drafts)try{const y=u.kind.encode(e.drafts[u.key],a.filter(f=>u.paths.includes(f.path)),d);for(const f of y.files)l.set(f.path,f.text),s.delete(f.path);for(const f of y.deleted??[])l.delete(f),s.add(f)}catch(y){m[u.key]=y instanceof Error?y.message:String(y)}const c=new Map(e.files.map(u=>[u.path,u])),p=[];for(const[u,y]of l){const f=c.get(u);(!f||f.text!==y)&&p.push({type:"write",path:u,text:y,baseVersion:f==null?void 0:f.version})}for(const u of s){const y=c.get(u);y&&p.push({type:"delete",path:u,baseVersion:y.version})}return{...e,working:a,documents:r,changes:p,pending:l,encodeErrors:m,dirty:p.length>0}}function zt(e,i){const n=[];for(const s of e.documents){if(s.error&&n.push({severity:"error",code:"file.unreadable",message:`${s.paths[0]} cannot be read: ${s.error}`,messageKey:"devStudio.issue.unreadable",params:{path:s.paths[0]},moduleId:e.key.id,path:s.paths[0]}),s.kind.editor!=="manifest"||!i.manifestSections)continue;const o=e.drafts[s.key]??s.model??{};for(const a of i.manifestSections){const{section:d}=$.fitManifestSection(a,o);if(d.schema)for(const r of st(o,d.schema))n.push({severity:"error",code:"manifest.schema",message:`${d.title}: ${r.field} — ${r.message}`,moduleId:e.key.id,path:s.paths[0],pointer:`/${r.field.replace(/\./g,"/")}`})}}for(const[s,o]of Object.entries(e.encodeErrors))n.push({severity:"error",code:"document.encode",message:`${s}: ${o}`,moduleId:e.key.id});if(i.validateModule){const s=[...e.pending.entries()].map(([o,a])=>({path:o,text:a}));n.push(...i.validateModule({key:e.key,files:s,documents:e.documents,contents:e.contents}).map(o=>({...o,moduleId:o.moduleId??e.key.id})))}return n}const Di=(e,i={})=>Object.entries(i).reduce((n,[s,o])=>n.split(`{${s}}`).join(String(o)),e),Pi=e=>e instanceof Error?e.message:String(e);function Li(e,i,n){const[s,o]=w.useState([]),[a,d]=w.useState({}),r=w.useRef(a);r.current=a;const[l,m]=w.useState({}),[c,p]=w.useState(null),[u,y]=w.useState({}),[f,v]=w.useState({}),[S,g]=w.useState(0),[b,I]=w.useState([]),_=w.useRef({provider:e,preset:i,options:n});_.current={provider:e,preset:i,options:n};const k=w.useCallback((F,T,K)=>{var R,B;return Di(((B=(R=_.current.options).t)==null?void 0:B.call(R,F,T))??T,K)},[]),x=w.useCallback((F,T,K)=>{I(R=>[...R,{level:F,message:T,data:K,timestamp:Date.now()}].slice(-300))},[]),j=w.useCallback(async(F,T)=>{var K,R;g(B=>B+1);try{return await T()}catch(B){x("error",`${F}: ${Pi(B)}`),(R=(K=_.current.options).onError)==null||R.call(K,B,F);return}finally{g(B=>B-1)}},[x]),N=w.useCallback(async()=>{const F=_.current.provider;F&&await j(k("devStudio.log.list","List"),async()=>{const T=await F.listWorkspaces();o(T);const K=await Promise.all(T.map(async R=>{const[B,W]=await Promise.all([F.listModules(R.id),F.listPackages?F.listPackages(R.id):Promise.resolve(void 0)]);return[R.id,B,W]}));d(Object.fromEntries(K.map(([R,B])=>[R,B]))),m(Object.fromEntries(K.filter(([,,R])=>R).map(([R,,B])=>[R,B]))),p(F.listTemplates?await F.listTemplates():null)})},[j,k]);w.useEffect(()=>{N()},[e,N]);const z=w.useMemo(()=>{const F={};for(const[T,K]of Object.entries(u))F[T]=Xe(K,i,n.locales);return F},[u,i,n.locales]),O=w.useCallback(async F=>{var X,V;const T=H(F),K=_.current.provider;if(!K)return;const R=await j(k("devStudio.log.open","Open {id}",{id:F.id}),()=>K.readModule(F));if(!R)return;const B=(V=(X=r.current[F.workspaceId])==null?void 0:X.find(se=>se.id===F.id))==null?void 0:V.contents,W={key:F,files:R,raw:{},deleted:[],drafts:{},contents:B};return y(se=>se[T]?se:{...se,[T]:W}),x("info",k("devStudio.log.opened","Opened {id} ({count} files)",{id:F.id,count:R.length})),Xe(W,_.current.preset,_.current.options.locales)},[j,x,k]),M=w.useCallback((F,T)=>{const K=H(F);y(R=>R[K]?{...R,[K]:T(R[K])}:R)},[]),D=w.useCallback((F,T,K)=>M(F,R=>({...R,drafts:{...R.drafts,[T]:K}})),[M]),te=w.useCallback((F,T,K,R=[])=>M(F,B=>{const W={...B.raw};K===null?delete W[T]:W[T]=K;const X={...B.drafts};for(const V of R)delete X[V];return{...B,raw:W,drafts:X,deleted:B.deleted.filter(V=>V!==T)}}),[M]),J=w.useCallback((F,T)=>M(F,K=>{const R={...K.raw};delete R[T];const B=!K.files.some(W=>W.path===T);return{...K,raw:R,deleted:B?K.deleted:[...new Set([...K.deleted,T])]}}),[M]),Y=w.useCallback(F=>M(F,T=>({...T,raw:{},deleted:[],drafts:{}})),[M]),L=w.useCallback(async F=>{const T=_.current.provider;if(!T)return;const K=await j(k("devStudio.log.reload","Reload {id}",{id:F.id}),()=>T.readModule(F));K&&(M(F,R=>({key:F,files:K,raw:{},deleted:[],drafts:{},contents:R.contents})),x("info",k("devStudio.log.reloaded","Reloaded {id}",{id:F.id})))},[j,M,x,k]),E=w.useCallback(F=>{const T=H(F);y(K=>{const R={...K};return delete R[T],R})},[]),A=w.useCallback(async(F,T={})=>{var oe;const K=_.current.provider,R=H(F),B=u[R];if(!K||!B)return;const W=Xe(B,_.current.preset,_.current.options.locales);if(W.changes.length===0)return{ok:!0};const X=T.force?W.changes.map(ae=>({...ae,baseVersion:void 0})):W.changes,V=await j(k("devStudio.log.save","Save {id}",{id:F.id}),()=>K.writeModule(F,X));if(!V)return;if(!V.ok)return x("warn",k("devStudio.log.conflicts","{id}: {count} file(s) changed meanwhile",{id:F.id,count:V.conflicts.length})),V;const se=[];for(const[ae,me]of W.pending){const ue=B.files.find(Ee=>Ee.path===ae);se.push({...ue,path:ae,text:me,version:((oe=V.versions)==null?void 0:oe[ae])??(ue==null?void 0:ue.version)})}M(F,ae=>({key:F,files:se,raw:{},deleted:[],drafts:{},contents:ae.contents}));const _e=X.map(ae=>ae.type==="delete"?k("devStudio.log.changeDelete","delete {path}",{path:ae.path}):k("devStudio.log.changeWrite","write {path}",{path:ae.path})).join(", ");return x("info",k("devStudio.log.saved","Saved {id}: {changes}",{id:F.id,changes:_e})),V},[u,j,M,x,k]),Q=w.useCallback(async F=>{const T=H(F),K=z[T];if(!K)return[];const R=zt(K,i),B=_.current.provider;let W=[];if(B!=null&&B.validate){const V=[...K.pending.entries()].map(([se,_e])=>({path:se,text:_e}));W=await j(k("devStudio.log.validate","Validate {id}",{id:F.id}),()=>B.validate(F,V))??[]}v(V=>({...V,[T]:W}));const X=[...R,...W];x(X.some(V=>V.severity==="error")?"warn":"info",X.length===0?k("devStudio.log.noProblems","{id}: no problems",{id:F.id}):k("devStudio.log.problems","{id}: {count} problem(s)",{id:F.id,count:X.length}));for(const V of X)x(V.severity==="error"?"error":V.severity==="warning"?"warn":"info",`${V.path?`${V.path}: `:""}${V.messageKey?k(V.messageKey,V.message,V.params):V.message}`);return X},[z,i,j,x,k]),G=w.useCallback(async F=>{const{provider:T,preset:K}=_.current;if(!(T!=null&&T.createModule)||!K.generateModule)return;const R=new Set(Object.values(a).flatMap(X=>X.map(V=>V.id))),B=await j(k("devStudio.log.generate","Generate module"),()=>K.generateModule(F,{existingIds:R}));if(!B)return;const W=await j(k("devStudio.log.create","Create {id}",{id:B.id}),()=>T.createModule({workspaceId:F.workspaceId,packageId:B.packageId??F.packageId,id:B.id,files:B.files}));return W&&(x("info",k("devStudio.log.created","Created {id}",{id:W.id})),await N()),W},[a,j,x,N,k]),U=w.useCallback(async(F,T)=>{const{provider:K,preset:R}=_.current;if(!(K!=null&&K.createModule)||!R.duplicateModule)return;const B=await j(k("devStudio.log.read","Read {id}",{id:F.id}),()=>K.readModule(F));if(!B)return;const W=await j(k("devStudio.log.duplicate","Duplicate"),()=>R.duplicateModule(B,T));if(!W)return;const X=await j(k("devStudio.log.create","Create {id}",{id:W.id}),()=>K.createModule({workspaceId:T.workspaceId,packageId:W.packageId??T.packageId,id:W.id,files:W.files}));return X&&(x("info",k("devStudio.log.duplicated","Duplicated {id} as {copy}",{id:F.id,copy:X.id})),await N()),X},[j,x,N,k]),ee=w.useCallback(async F=>{const T=_.current.provider;if(!(T!=null&&T.deleteModule))return!1;const K=await j(k("devStudio.log.delete","Delete {id}",{id:F.id}),async()=>(await T.deleteModule(F),!0));return K&&(E(F),x("info",k("devStudio.log.deleted","Deleted {id}",{id:F.id})),await N()),!!K},[j,E,x,N,k]),Z=w.useCallback(async F=>{const T=_.current.provider;if(!(T!=null&&T.savePackage))return;const K=await j(k("devStudio.log.savePackage","Save package {id}",{id:F.id}),()=>T.savePackage(F));return K&&(x("info",k("devStudio.log.savedPackage","Saved package {id}",{id:K.id})),await N()),K},[j,x,N,k]),le=w.useCallback(async(F,T)=>{const K=_.current.provider;if(!(K!=null&&K.saveTemplate))return;const R=await j(k("devStudio.log.saveTemplate","Save template {id}",{id:F.id}),()=>K.saveTemplate(F,T?{previousId:T}:void 0));return R&&K.listTemplates&&(p(await K.listTemplates()),x("info",k("devStudio.log.savedTemplate","Saved template {id}",{id:R.id}))),R},[j,x,k]),we=w.useCallback(async F=>{const T=_.current.provider;if(!(T!=null&&T.deleteTemplate))return!1;const K=await j(k("devStudio.log.deleteTemplate","Delete template {id}",{id:F}),async()=>(await T.deleteTemplate(F),!0));return K&&T.listTemplates&&(p(await T.listTemplates()),x("info",k("devStudio.log.deletedTemplate","Deleted template {id}",{id:F}))),!!K},[j,x,k]);return{workspaces:s,modulesByWs:a,packagesByWs:l,templates:c,modules:z,serverIssues:f,busy:S>0,logs:b,clearLogs:()=>I([]),log:x,refresh:N,openModule:O,close:E,setDraft:D,setRaw:te,deleteFile:J,discard:Y,reload:L,save:A,validate:Q,createModule:G,duplicateModule:U,deleteModule:ee,savePackage:Z,saveTemplate:le,deleteTemplate:we}}const ve="__none",Re="t:",Ri={entities:"entities",views:"views",workflows:"workflows",i18n:"translations",permissions:"permissions",rbac:"access",dataSources:"dataSources",seeds:"seeds",hooks:"hooks",script:"scripts",scriptList:"scripts"},Bi=["entities","views","workflows","translations","permissions","access","dataSources","seeds","hooks","scripts"],dt={entities:"database",views:"grid",workflows:"git-branch",translations:"globe",permissions:"shield",access:"users",dataSources:"server",seeds:"list",hooks:"zap",scripts:"code",files:"folder"},Dt={views:"grid",workflows:"git-branch",dataSources:"server",scripts:"code"},Pt={frontend:"code",backend:"server",noCode:"list",sql:"database"},Lt=e=>e.kind.treeGroup??Ri[e.kind.editor],Rt=e=>e==="views"||e==="workflows"||e==="dataSources",Ne=(e,i)=>i.kind.editor==="scriptList"?ie(e,i):void 0,Ae=e=>Object.prototype.hasOwnProperty.call(dt,e),ge=(e,i)=>Ae(e)?dt[e]:(i==null?void 0:i.icon)??"folder";function ye(e,i,n,s){const o=(a,d)=>e(a,d).replace("{count}",String(n??0));if(!Ae(i)){const a=s?e(s.labelKey??`devStudio.group.${i}`,s.label):i;return n===void 0?a:`${a}: ${n}`}switch(i){case"entities":return o("devStudio.group.entities","Entities: {count}");case"views":return o("devStudio.group.views","Views: {count}");case"workflows":return o("devStudio.group.workflows","Workflows: {count}");case"dataSources":return o("devStudio.group.dataSources","Data sources: {count}");case"scripts":return o("devStudio.group.scripts","Scripts: {count}");case"files":return o("devStudio.group.files","Files: {count}");case"translations":return e("devStudio.group.translations","Translations");case"permissions":return e("devStudio.group.permissions","Permissions");case"access":return e("devStudio.group.access","Access");case"seeds":return e("devStudio.group.seeds","Seed data");case"hooks":return e("devStudio.group.hooks","Lifecycle hooks")}}function Bt(e){switch(e.kind){case"workspace":return`w|${e.workspaceId}`;case"package":return`p|${e.workspaceId}|${e.packageId??ve}`;case"module":return`m|${H(e.module)}`;case"group":return`g|${H(e.module)}|${e.group}${e.section?`|${e.section}`:""}`;case"section":return`s|${H(e.module)}|${e.sectionId}`;case"folder":return`fo|${H(e.module)}|${e.folderId}`;case"entity":return`e|${H(e.module)}|${e.docKey}|${e.index}`;case"item":return`i|${H(e.module)}|${e.group}|${e.docKey}|${e.itemKey}`;case"document":return`d|${H(e.module)}|${e.docKey}`;case"panel":return`x|${H(e.module)}|${e.panelKey}`;case"file":return`f|${H(e.module)}|${e.path}`;case"templates":return"t";case"category":return`c|${e.category}`;case"template":return`t|${e.templateId}`;case"templateModule":return`tm|${e.templateId}|${e.moduleId}`}}const ie=(e,i)=>e.drafts[i.key]??i.model,fe=(e,i)=>e.documents.find(n=>n.key===i),xe=(e,i)=>e.changes.some(n=>i.paths.includes(n.path));function rt(e){const i=[];for(const n of e.documents){if(n.kind.editor!=="entities")continue;const s=ie(e,n);Array.isArray(s)&&s.forEach((o,a)=>i.push({docKey:n.key,index:a,entity:o}))}return i}const Ce=e=>rt(e).map(i=>i.entity),ct=(e,i="name")=>String(e.displayName||e[i]||"");function de(e,i){var s;if(i.kind.editor==="scriptList"){const o=(s=Ne(e,i))==null?void 0:s.scripts;return Array.isArray(o)?o:[]}const n=ie(e,i);return Array.isArray(n)?i.kind.editor==="dataSources"?n.map((o,a)=>{const d=o??{},r=typeof d.key=="string"&&d.key?d.key:typeof d.name=="string"&&d.name?d.name:`#${a}`,l=h.isModuleDataSource(o);return{key:r,label:typeof d.label=="string"&&d.label||r,...l?{definition:o}:{rawReason:"not a data source the editor knows"},source:o}}):n:[]}const Oe="__standard",lt=e=>h.standardDataSources($.entitiesToSchemas(Ce(e))),Ai=(e,i)=>(i.shape==="object"?e("devStudio.dataSources.byId","{entity}: one by Id"):e("devStudio.dataSources.all","{entity}: all rows")).replace("{entity}",i.label??i.key);function qi(e){return e.documents.filter(i=>i.kind.editor==="dataSources").flatMap(i=>ie(e,i)??[]).filter(h.isModuleDataSource)}function ut(e,i,n){return n===null?e.filter((s,o)=>o!==i):e.map((s,o)=>o===i?n:s)}function mt(e,i,n){return i.kind.editor==="scriptList"?{...Ne(e,i)??{scripts:[]},scripts:n}:n}function At(e,i,n){return n===null?e.filter(s=>s.key!==i):e.map(s=>s.key===i?n:s)}function qt(e,i,n){const s=new Map((i??[]).map(o=>[o.id,o]));for(const o of n){const a=o.packageId??ve;s.has(a)||s.set(a,{id:a,workspaceId:e,label:o.packageId??"",derived:!0})}return[...s.values()].sort((o,a)=>o.id===ve?1:a.id===ve?-1:o.label.localeCompare(a.label))}const De=(e,i)=>e&&/^[a-z0-9-]+$/.test(e)?e:i,Be=e=>e.slice(e.lastIndexOf("/")+1);function Wt(e){var n;const i=$.studioLayoutPath(e.working);return $.parseStudioLayout((n=e.working.find(s=>s.path===i))==null?void 0:n.text)}function Wi(e){const i=[...Bi],n=[...e??[]].filter(o=>!i.includes(o.id)).sort((o,a)=>(o.order??1e3)-(a.order??1e3)),s=[...i];for(const o of n){const a=o.order===void 0?s.length:Math.min(s.length,Math.max(0,Math.floor(o.order/10)));s.splice(a,0,o.id)}return s}function Vi(e,i,n){var p;const{t:s}=n,o=i.key,a=u=>{var y;return(y=n.groups)==null?void 0:y.find(f=>f.id===u)},d=new Map;for(const u of i.documents){const y=Lt(u);y&&d.set(y,[...d.get(y)??[],u])}const r=(u,y)=>({id:`${y}/d:${u.key}`,node:{kind:"document",module:o,docKey:u.key},label:Be(u.paths[0]??u.label),icon:"warning",noForm:!0,dirty:xe(i,u)}),l=[],m=lt(i);for(const u of Wi(n.groups)){const y=d.get(u)??(u==="dataSources"&&m.length?[]:void 0);if(!y)continue;const f=a(u),v=`${e}/g:${u}`,S={kind:"group",module:o,group:u};if(u==="entities"){const g=[];for(const I of y){const _=ie(i,I);if(!Array.isArray(_)){g.push(r(I,v));continue}const k=xe(i,I);_.forEach((x,j)=>{const N=x.fields;g.push({id:`${v}/e:${I.key}#${j}`,node:{kind:"entity",module:o,docKey:I.key,index:j},label:ct(x)||`#${j+1}`,icon:"table",info:Array.isArray(N)?String(N.length):void 0,dirty:k,search:String(x.name??""),ref:`entities:${String(x.name??`#${j}`)}`})})}const b=g.filter(I=>I.node.kind==="entity").length;l.push({id:v,node:S,label:ye(s,u,b),icon:ge(u,f),children:g});continue}if(u==="scripts"){l.push({id:v,node:S,icon:ge(u,f),...Ji(v,i,y,s)});continue}if(Rt(u)){const g=[];for(const I of y){if(I.model===void 0){g.push(r(I,v));continue}const _=xe(i,I);for(const k of de(i,I))g.push({id:`${v}/i:${I.key}#${k.key}`,node:{kind:"item",module:o,group:u,docKey:I.key,itemKey:k.key},label:k.label||k.key,icon:Dt[u],noForm:k.definition===void 0,dirty:_,search:k.key,ref:`${u}:${k.key}`})}const b=g.filter(I=>I.node.kind==="item").length;if(u==="dataSources")for(const I of m)g.push({id:`${v}/std:${I.key}`,node:{kind:"item",module:o,group:u,docKey:Oe,itemKey:I.key},label:Ai(s,I),icon:"lock",info:s("devStudio.dataSources.standard","standard"),readOnly:!0,search:I.key});l.push({id:v,node:S,label:ye(s,u,b),icon:ge(u,f),children:g});continue}if(!Ae(u)){l.push({id:v,node:S,label:ye(s,u,y.length,f),icon:ge(u,f),children:y.map(g=>({id:`${v}/d:${g.key}`,node:{kind:"document",module:o,docKey:g.key},label:Be(g.paths[0]??g.label),icon:g.kind.icon??ge(u,f),noForm:g.model===void 0,dirty:xe(i,g),search:g.paths.join(" "),ref:`${u}:${g.paths[0]??g.key}`}))});continue}if(y.length===1){const g=y[0];l.push({id:v,node:{kind:"document",module:o,docKey:g.key},label:ye(s,u),icon:ge(u,f),noForm:g.model===void 0,dirty:xe(i,g)});continue}l.push({id:v,node:S,label:ye(s,u),icon:ge(u,f),children:y.map(g=>({id:`${v}/d:${g.key}`,node:{kind:"document",module:o,docKey:g.key},label:g.label,icon:ge(u,f),noForm:g.model===void 0,dirty:xe(i,g),search:g.paths.join(" ")}))})}const c=Gi(e,i,l,Wt(i),(u,y)=>ye(s,u,y,a(u)));for(const u of((p=n.panels)==null?void 0:p.call(n,i))??[])c.push({id:`${e}/x:${u.key}`,node:{kind:"panel",module:o,panelKey:u.key},label:u.label,icon:"puzzle"});if(n.advanced){const u=new Set(i.changes.map(f=>f.path)),y=[...i.working].sort((f,v)=>f.path.localeCompare(v.path));c.push({id:`${e}/g:files`,node:{kind:"group",module:o,group:"files"},label:ye(s,"files",y.length),icon:dt.files,children:y.map(f=>({id:`${e}/g:files/f:${f.path}`,node:{kind:"file",module:o,path:f.path},label:f.path,icon:"file",dirty:u.has(f.path)}))})}return c}function Ji(e,i,n,s){const o=i.key,a=n.filter(r=>r.kind.editor==="scriptList").length,d=[];for(const r of n){const l=xe(i,r),m=r.paths[0]??r.key,c=Ne(i,r);if(r.kind.editor!=="scriptList"||r.model===void 0||!c){d.push({id:`${e}/d:${r.key}`,node:{kind:"document",module:o,docKey:r.key},label:Be(m),icon:r.model===void 0?"warning":"code",noForm:r.model===void 0,dirty:l,search:r.paths.join(" "),ref:`scripts:${m}`});continue}for(const p of c.scripts){const u=p.definition;d.push({id:`${e}/i:${r.key}#${p.key}`,node:{kind:"item",module:o,group:"scripts",docKey:r.key,itemKey:p.key},label:p.label||p.key,icon:u?Pt[u.kind]:Dt.scripts,info:u==null?void 0:u.category,noForm:u===void 0,dirty:l,search:`${p.key} ${(u==null?void 0:u.category)??""}`,ref:`scripts:${p.key}`})}if(c.holds==="phases"||Object.keys(c.phases??{}).length>0){const p=s("devStudio.scripts.database","Database scripts");d.push({id:`${e}/d:${r.key}`,node:{kind:"document",module:o,docKey:r.key},label:a>1?`${p} (${Be(m)})`:p,icon:"database",info:String(Object.values(c.phases??{}).reduce((u,y)=>u+y.length,0)),dirty:l,search:r.paths.join(" "),ref:`scripts:${m}`})}}return{label:ye(s,"scripts",d.length),children:d}}const Ui=new Set(["entities","views","workflows","dataSources","scripts"]),Pe=e=>e.reduce((i,n)=>i+(n.node.kind==="folder"?Pe(n.children??[]):n.ref?1:0),0);function Gi(e,i,n,s,o){var y;if($.isEmptyStudioLayout(s))return n;const a=i.key,d=new Set(s.sections.map(f=>f.id)),r=f=>{var v;return(f.ref?(v=s.placement[f.ref])==null?void 0:v.order:void 0)??Number.MAX_SAFE_INTEGER},l=f=>f.some(v=>{var S;return v.ref&&((S=s.placement[v.ref])==null?void 0:S.order)!==void 0})?[...f].sort((v,S)=>r(v)-r(S)):f,m=(f,v,S,g,b)=>{var z;const I=s.folders.filter(O=>O.group===S&&(O.section&&d.has(O.section)?O.section:void 0)===g),_=new Set(I.map(O=>O.id)),k=O=>M=>({...M,id:`${O}${M.id.startsWith(v)?M.id.slice(v.length):`/${M.id}`}`}),x=new Map,j=[];for(const O of b){const M=O.ref?(z=s.placement[O.ref])==null?void 0:z.folder:void 0;M&&_.has(M)?x.set(M,[...x.get(M)??[],O]):j.push(O)}const N=(O,M)=>I.filter(D=>(D.parent&&_.has(D.parent)?D.parent:void 0)===O).map(D=>{const te=`${M}/fo:${D.id}`,J=[...N(D.id,te),...l(x.get(D.id)??[]).map(k(te))];return{id:te,node:{kind:"folder",module:a,folderId:D.id,group:S},label:D.label,icon:"folder",info:String(Pe(J)),children:J}});return[...N(void 0,f),...l(j).map(k(f))]},c=[],p=new Map(s.sections.map(f=>[f.id,[]]));for(const f of n){if(f.node.kind!=="group"||!f.children){c.push(f);continue}const v=f.node.group,S=new Map;for(const b of f.children){const I=b.ref?(y=s.placement[b.ref])==null?void 0:y.section:void 0,_=I&&d.has(I)?I:void 0;S.set(_,[...S.get(_)??[],b])}const g=m(f.id,f.id,v,void 0,S.get(void 0)??[]);c.push({...f,label:u(f,v,g),children:g});for(const b of s.sections){const I=S.get(b.id)??[],_=s.folders.some(j=>j.group===v&&j.section===b.id);if(I.length===0&&!_)continue;const k=`${e}/s:${b.id}/g:${v}`,x=m(k,f.id,v,b.id,I);p.get(b.id).push({...f,id:k,node:{kind:"group",module:a,group:v,section:b.id},label:u(f,v,x),children:x})}}for(const f of s.sections){const v=p.get(f.id)??[];c.push({id:`${e}/s:${f.id}`,node:{kind:"section",module:a,sectionId:f.id},label:f.label,icon:"layers",info:String(v.reduce((S,g)=>S+Pe(g.children??[]),0)),children:v})}return c;function u(f,v,S){return Ui.has(v)||!Ae(v)?o(v,Pe(S)):f.label}}function tt(e){const i=e.label||e.id;return i===e.id&&e.id.includes("/")?e.id.slice(e.id.lastIndexOf("/")+1):i}const Ze=e=>e.parentId??(e.id.includes("/")?e.id.slice(0,e.id.lastIndexOf("/")):void 0);function Hi(e,i,n,s){const o=new Map(n.map(m=>[m.id,m]));for(const m of n){let c=Ze(m);for(;c&&!o.has(c);){const p={id:c,workspaceId:e,label:"",derived:!0};o.set(c,p),c=Ze(p)}}const a=[...o.values()],d=m=>{const c=Ze(m);return c&&o.has(c)&&c!==m.id?c:void 0},r=m=>m.sort((c,p)=>c.id===ve?1:p.id===ve?-1:tt(c).localeCompare(tt(p))),l=(m,c)=>r(a.filter(p=>d(p)===m)).map(p=>{const u=`${c}/p:${p.id}`;return s(p,u,l(p.id,u))});return l(void 0,i)}function Yi(e){const{t:i}=e,n=i("devStudio.explorer.noPackage","No package"),s=e.workspaces.map(l=>{const m=e.modulesByWs[l.id]??[],c=`w:${l.id}`;return{id:c,node:{kind:"workspace",workspaceId:l.id},label:l.label,icon:De(l.icon,"folder"),info:String(m.length),readOnly:l.readOnly,search:l.id,children:Hi(l.id,c,qt(l.id,e.packagesByWs[l.id],m),(p,u,y)=>{const f=m.filter(v=>(v.packageId??ve)===p.id).sort((v,S)=>v.label.localeCompare(S.label));return{id:u,node:{kind:"package",workspaceId:l.id,packageId:p.id===ve?void 0:p.id},label:p.id===ve?n:tt(p),icon:De(p.icon,"archive"),info:String(f.length),search:p.id,children:[...y,...f.map(v=>{var k;const S=H(v),g=e.modules[S],b=`${u}/m:${v.id}`,I=g?Vi(b,g,e):void 0,_=g?[...rt(g).map(x=>`${x.entity.name??""} ${ct(x.entity)}`),...g.documents.filter(x=>x.kind.editor==="views").flatMap(x=>de(g,x).map(j=>`${j.key} ${j.label}`))]:[];return{id:b,node:{kind:"module",module:{workspaceId:v.workspaceId,id:v.id}},label:v.label,icon:De(v.icon,"box"),info:v.version,readOnly:v.readOnly,shadowedBy:v.shadowedBy,dirty:g==null?void 0:g.dirty,issues:(k=e.issueCounts)==null?void 0:k[S],search:[v.id,v.description??"",v.search??"",..._].join(" "),children:I}})]}})}});if(e.templates){const l=new Map;for(const p of e.workspaces)for(const u of e.modulesByWs[p.id]??[])l.has(u.id)||l.set(u.id,u);const m=new Map;for(const p of e.templates){const u=p.category??"";m.set(u,[...m.get(u)??[],p])}const c=p=>{var u,y;return((u=p.translations.en)==null?void 0:u.name)??((y=Object.values(p.translations)[0])==null?void 0:y.name)??p.id};s.push({id:Re,node:{kind:"templates"},label:i("devStudio.tree.templates","Templates"),icon:"layers",info:String(e.templates.length),children:[...m.entries()].sort(([p],[u])=>p.localeCompare(u)).map(([p,u])=>{const y=`${Re}/c:${p}`;return{id:y,node:{kind:"category",category:p},label:p||i("devStudio.explorer.noCategory","Other"),icon:"folder",info:String(u.length),children:[...u].sort((f,v)=>(f.sortOrder??0)-(v.sortOrder??0)||c(f).localeCompare(c(v))).map(f=>{const v=`${y}/t:${f.id}`;return{id:v,node:{kind:"template",templateId:f.id},label:c(f),icon:De(f.icon,"layers"),info:String(f.modules.length),readOnly:f.readOnly,search:`${f.id} ${(f.tags??[]).join(" ")}`,children:f.modules.map(S=>{const g=l.get(S.moduleId);return{id:`${v}/m:${S.moduleId}`,node:{kind:"templateModule",templateId:f.id,moduleId:S.moduleId,target:g?{workspaceId:g.workspaceId,id:g.id}:void 0},label:(g==null?void 0:g.label)??S.moduleId,icon:"box",info:S.required?i("devStudio.template.required","required"):void 0,missing:!g,search:S.moduleId}})}})}})})}const o=new Map,a=new Map,d=new Map,r=(l,m,c=0)=>{for(const p of l){p.depth=c,o.set(p.id,p),m&&a.set(p.id,m);const u=Bt(p.node);d.has(u)||d.set(u,p.id),p.children&&r(p.children,p.id,c+1)}};return r(s),{rows:s,byId:o,parentOf:a,rowOfNode:d}}function It(e,i){const n=[];let s=i;for(;s;){const o=e.byId.get(s);if(!o)break;n.unshift(o),s=e.parentOf.get(s)}return n}const et=(e,i)=>e.rowOfNode.get(Bt(i));function Me(e){return"module"in e?e.module:void 0}function Qi(e,i){var s;const n="module"in e?i.modules[H(e.module)]:void 0;switch(e.kind){case"module":return n!=null&&n.documents.some(o=>o.kind.editor==="manifest")?{kind:"manifest",module:e.module}:void 0;case"entity":return{kind:"entity",module:e.module,docKey:e.docKey,index:e.index};case"item":{if(e.docKey===Oe)return{...e};const o=n&&fe(n,e.docKey),a=o&&de(n,o).find(d=>d.key===e.itemKey);return(a==null?void 0:a.definition)!==void 0||i.advanced?{...e}:void 0}case"document":{const o=n&&fe(n,e.docKey);return(o==null?void 0:o.model)!==void 0?{kind:"document",module:e.module,docKey:e.docKey}:o&&i.advanced?{kind:"file",module:e.module,path:o.paths[0]}:void 0}case"panel":return{kind:"panel",module:e.module,panelKey:e.panelKey};case"file":return{kind:"file",module:e.module,path:e.path};case"package":{const o=(s=i.packages)==null?void 0:s.find(a=>a.id===e.packageId);return o&&!o.derived?{kind:"package",pkg:o}:void 0}case"template":return{kind:"template",templateId:e.templateId};default:return}}function Ct(e){switch(e.kind){case"manifest":case"problems":case"history":return{kind:"module",module:e.module};case"entity":return{kind:"entity",module:e.module,docKey:e.docKey,index:e.index};case"item":return{...e};case"document":return{kind:"document",module:e.module,docKey:e.docKey};case"panel":return{kind:"panel",module:e.module,panelKey:e.panelKey};case"file":return{kind:"file",module:e.module,path:e.path};case"package":return{kind:"package",workspaceId:e.pkg.workspaceId,packageId:e.pkg.id};case"template":return e.templateId?{kind:"template",templateId:e.templateId}:void 0}}const Xi=/^\/(?:[A-Za-z]+\/)?(\d+)(?:\/|$)/;function Vt(e,i){const n=e.key,s=i.path?e.documents.find(r=>r.paths.includes(i.path)):void 0;if(!s)return{kind:"module",module:n};const o=Lt(s),a=s.paths.length===1?Xi.exec(i.pointer??""):null,d=a?Number(a[1]):-1;if(o==="entities"){const r=ie(e,s);return Array.isArray(r)&&d>=0&&d<r.length?{kind:"entity",module:n,docKey:s.key,index:d}:{kind:"group",module:n,group:o}}if(o==="scripts"&&s.kind.editor==="scriptList"){const r=d>=0?de(e,s)[d]:void 0;return r?{kind:"item",module:n,group:"scripts",docKey:s.key,itemKey:r.key}:{kind:"document",module:n,docKey:s.key}}if(Rt(o)){const r=d>=0?de(e,s)[d]:void 0;return r?{kind:"item",module:n,group:o,docKey:s.key,itemKey:r.key}:{kind:"group",module:n,group:o}}return o?{kind:"document",module:n,docKey:s.key}:s.kind.editor==="manifest"?{kind:"module",module:n}:{kind:"file",module:n,path:s.paths[0]}}function Zi(e,i){const n=new Set(e.documents.filter(o=>o.kind.editor==="dataSources").flatMap(o=>de(e,o).map(a=>a.key)));let s=i;for(let o=2;n.has(s);o++)s=`${i}${o}`;return s}function Jt(e,i,n,s){var p,u,y;const o=e.key,a={...s,key:Zi(e,s.key)},d=f=>({kind:"item",module:o,group:"dataSources",docKey:f,itemKey:a.key}),r=e.documents.find(f=>f.kind.editor==="dataSources"&&Array.isArray(ie(e,f)));if(r)return n.setDraft(o,r.key,[...ie(e,r)??[],a]),d(r.key);const l=i.kinds.find(f=>f.editor==="dataSources"),m=l&&((p=i.newFile)==null?void 0:p.call(i,l.id,{key:o,files:e.working,documents:e.documents}));if(!l||!m||e.working.some(f=>f.path===m.path))return;const c={moduleId:o.id,files:e.working,locales:i.locales??[]};try{const f=l.decode([m],c),v=(u=l.encode([...Array.isArray(f)?f:[],a],[m],c).files.find(S=>S.path===m.path))==null?void 0:u.text;return v===void 0?void 0:(n.setRaw(o,m.path,v),d(`${l.id}:${((y=l.group)==null?void 0:y.call(l,m.path))??m.path}`))}catch{return}}function en(e,i){var o;if(e.documents.some(a=>a.kind.editor==="dataSources"&&a.model!==void 0))return!0;const n=i.kinds.find(a=>a.editor==="dataSources"),s=n&&((o=i.newFile)==null?void 0:o.call(i,n.id,{key:e.key,files:e.working,documents:e.documents}));return!!s&&!e.working.some(a=>a.path===s.path)}const tn=[{target:".nice-i18n-editor",titleKey:"tutorial.i18nEditor.intro.title",title:"Translations",contentKey:"tutorial.i18nEditor.intro.content",content:"Edit translations as a keys × locales grid. Add keys and locales; amber cells mark missing translations.",placement:"auto"},{target:'[data-tour="i18n-grid"]',titleKey:"tutorial.i18nEditor.grid.title",title:"Keys × locales",contentKey:"tutorial.i18nEditor.grid.content",content:"Each row is a translation key and each column a locale. Edit a cell to set a translation; amber cells are still missing.",placement:"top"},{target:'[data-tour="i18n-add"]',titleKey:"tutorial.i18nEditor.add.title",title:"Add keys & locales",contentKey:"tutorial.i18nEditor.add.content",content:"Add a new translation key or a new locale column here; new cells start empty and are flagged as missing.",placement:"top"}],pt=w.forwardRef(function(i,n){const{value:s,defaultValue:o,onChange:a,locales:d,allowEditLocales:r=!0,allowEditKeys:l=!0,highlightMissing:m=!0,readOnly:c=!1,tutorial:p,className:u,style:y,id:f,"data-testid":v}=i,{t:S}=be.useNiceTranslation(),[g,b]=be.useControllableState({value:s,defaultValue:o,fallbackValue:{},onChange:a,componentName:"NiceI18nEditor"}),[I,_]=w.useState(""),[k,x]=w.useState(""),j=w.useMemo(()=>d??Object.keys(g),[d,g]),N=w.useMemo(()=>{const L=new Set;for(const E of Object.keys(g))for(const A of Object.keys(g[E]??{}))L.add(A);return[...L].sort()},[g]),z=(L,E,A)=>{b({...g,[L]:{...g[L]??{},[E]:A}})},O=(L,E)=>{if(!E||E===L)return;const A={};for(const Q of Object.keys(g)){const G={...g[Q]??{}};L in G&&(G[E]=G[L],delete G[L]),A[Q]=G}b(A)},M=L=>{const E={};for(const A of Object.keys(g)){const Q={...g[A]??{}};delete Q[L],E[A]=Q}b(E)},D=()=>{const L=I.trim();if(!L||N.includes(L))return;const E={};for(const A of j)E[A]={...g[A]??{},[L]:""};for(const A of Object.keys(g))E[A]||(E[A]=g[A]);b(E),_("")},te=()=>{const L=k.trim();if(!L||g[L])return;const E={};for(const A of N)E[A]="";b({...g,[L]:E}),x("")},J=L=>{const E={...g};delete E[L],b(E)},Y="nice-i18n-editor"+(u?` ${u}`:"");return t.jsxs("div",{ref:n,id:f,className:Y,style:y,"data-testid":v,children:[p&&t.jsx("div",{className:"nice-i18n-editor__tutorial",children:t.jsx(be.NiceTutorialButton,{steps:be.resolveTutorial(p,tn)})}),t.jsx("div",{className:"nice-i18n-editor__scroll","data-tour":"i18n-grid",children:t.jsxs("table",{className:"nice-i18n-editor__table",children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{className:"nice-i18n-editor__key-head",children:S("i18nEditor.keyHead","Key")}),j.map(L=>t.jsxs("th",{className:"nice-i18n-editor__locale-head",children:[t.jsx("span",{children:L}),r&&!c&&t.jsx("button",{type:"button",className:"nice-i18n-editor__locale-remove","aria-label":`${S("i18nEditor.removeLocale","Remove locale")} ${L}`,onClick:()=>J(L),children:t.jsx(be.NiceIcon,{name:"close",size:12})})]},L))]})}),t.jsxs("tbody",{children:[N.map(L=>t.jsxs("tr",{children:[t.jsxs("td",{className:"nice-i18n-editor__key-cell",children:[l&&!c?t.jsx("input",{className:"nice-i18n-editor__key-input",defaultValue:L,onBlur:E=>O(L,E.target.value.trim()),"aria-label":S("i18nEditor.keyAria","Translation key")}):t.jsx("span",{className:"nice-i18n-editor__key-text",children:L}),l&&!c&&t.jsx("button",{type:"button",className:"nice-i18n-editor__key-remove","aria-label":`${S("i18nEditor.removeKey","Remove key")} ${L}`,onClick:()=>M(L),children:t.jsx(be.NiceIcon,{name:"close",size:12})})]}),j.map(E=>{var G;const A=((G=g[E])==null?void 0:G[L])??"",Q=m&&A==="";return t.jsx("td",{className:"nice-i18n-editor__cell",children:t.jsx("input",{className:"nice-i18n-editor__cell-input"+(Q?" nice-i18n-editor__cell-input--missing":""),value:A,readOnly:c,onChange:U=>z(E,L,U.target.value),"aria-label":`${L} (${E})`})},E)})]},L)),N.length===0&&t.jsx("tr",{children:t.jsx("td",{className:"nice-i18n-editor__empty",colSpan:j.length+1,children:S("i18nEditor.empty","No translation keys yet.")})})]})]})}),!c&&(l||r)&&t.jsxs("div",{className:"nice-i18n-editor__toolbar","data-tour":"i18n-add",children:[l&&t.jsxs("div",{className:"nice-i18n-editor__add",children:[t.jsx("input",{className:"nice-i18n-editor__add-input",placeholder:S("i18nEditor.newKeyPlaceholder","new.key"),value:I,onChange:L=>_(L.target.value),onKeyDown:L=>{L.key==="Enter"&&D()},"aria-label":S("i18nEditor.newKeyAria","New key")}),t.jsxs("button",{type:"button",onClick:D,children:["+ ",S("i18nEditor.addKey","Key")]})]}),r&&t.jsxs("div",{className:"nice-i18n-editor__add",children:[t.jsx("input",{className:"nice-i18n-editor__add-input",placeholder:S("i18nEditor.newLocalePlaceholder","locale (e.g. de)"),value:k,onChange:L=>x(L.target.value),onKeyDown:L=>{L.key==="Enter"&&te()},"aria-label":S("i18nEditor.newLocaleAria","New locale")}),t.jsxs("button",{type:"button",onClick:te,children:["+ ",S("i18nEditor.addLocale","Locale")]})]})]})]})});function ht(e,i){switch(i){case"frontend":return e("devStudio.scripts.kind.frontend","Frontend");case"backend":return e("devStudio.scripts.kind.backend","Backend");case"noCode":return e("devStudio.scripts.kind.noCode","No-code");case"sql":return e("devStudio.scripts.kind.sql","SQL")}}const nn=(e,i)=>{switch(i){case"frontend":return e("devStudio.scripts.hint.frontend","TypeScript or JavaScript run in the browser.");case"backend":return e("devStudio.scripts.hint.backend","C# or JavaScript run on the server.");case"noCode":return e("devStudio.scripts.hint.noCode","Steps over the app data, set up without code.");case"sql":return e("devStudio.scripts.hint.sql","A query or procedure run in the database.")}},Ut={typescript:"TypeScript",javascript:"JavaScript",csharp:"C#",sql:"SQL"},sn=e=>{const i=(e??"").toLowerCase();return i.startsWith("csharp")||i==="c#"?"csharp":i.endsWith("sql")?"sql":i==="typescript"||i==="javascript"?i:"plaintext"};function Gt(e,i){var s;const n=e.documents.flatMap(o=>{var a;return(((a=Ne(e,o))==null?void 0:a.scripts)??[]).map(d=>{var r;return(r=d.definition)==null?void 0:r.category})});return[...new Set([...((s=i.scripts)==null?void 0:s.categories)??[],...n])].filter(o=>!!o).sort((o,a)=>o.localeCompare(a))}function Ht({value:e,onChange:i,categories:n,readOnly:s,testId:o}){const{t:a}=h.useNiceTranslation(),d=n.filter(r=>r!==e).slice(0,12);return t.jsxs("div",{className:"nice-development-studio__script-category",children:[t.jsx(h.NiceTextInput,{label:a("devStudio.scripts.category","Category"),value:e,onChange:i,readOnly:s,size:"sm","data-testid":o}),!s&&d.length>0&&t.jsx("div",{className:"nice-development-studio__chips",children:d.map(r=>t.jsx(h.NiceButton,{size:"xs",variant:"ghost",onClick:()=>i(r),children:r},r))})]})}function on({value:e,onChange:i,readOnly:n}){const{t:s}=h.useNiceTranslation(),o=(a,d)=>i(e.map((r,l)=>l===a?{...r,...d}:r));return t.jsxs("fieldset",{className:"nice-development-studio__script-params",children:[t.jsx("legend",{children:s("devStudio.scripts.parameters","Parameters")}),e.map((a,d)=>t.jsxs("div",{className:"nice-development-studio__script-param",children:[t.jsx(h.NiceTextInput,{label:s("devStudio.scripts.param.name","Name"),labelPlacement:"inside",value:a.name,onChange:r=>o(d,{name:r}),readOnly:n,size:"sm"}),t.jsx(h.NiceTextInput,{label:s("devStudio.scripts.param.type","Type"),labelPlacement:"inside",value:a.type??"",onChange:r=>o(d,{type:r||void 0}),readOnly:n,size:"sm"}),t.jsx(h.NiceTextInput,{label:s("devStudio.scripts.param.description","Description"),labelPlacement:"inside",value:a.description??"",onChange:r=>o(d,{description:r||void 0}),readOnly:n,size:"sm"}),!n&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost","aria-label":s("devStudio.scripts.param.remove","Remove parameter"),onClick:()=>i(e.filter((r,l)=>l!==d)),children:t.jsx(h.NiceIcon,{name:"trash",size:14})})]},d)),!n&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:()=>i([...e,{name:`arg${e.length+1}`,type:"string"}]),children:s("devStudio.scripts.param.add","Add parameter")})]})}function an({module:e,doc:i,item:n,preset:s,session:o,readOnly:a,scriptRunner:d,scriptIo:r,onRenamed:l}){var x,j;const{t:m}=h.useNiceTranslation(),c=n.definition,p=w.useMemo(()=>Gt(e,s),[e,s]);if(!c)return null;const u=de(e,i),y=N=>{const z={...c,...N},O=z.name&&!u.some(D=>D!==n&&D.key===z.name)?z.name:n.key,M={...n,key:O,label:z.displayName||z.name||n.label,definition:z};o.setDraft(e.key,i.key,mt(e,i,u.map(D=>D.key===n.key?M:D))),O!==n.key&&l(O)},f=N=>{if(N===c.kind)return;const z=$.studioScriptLanguages(N),O=c.language&&z.includes(c.language)?c.language:z[0],M=$.newStudioScript({kind:N,name:c.name,language:O});y({kind:N,language:O,steps:N==="noCode"?c.steps??[]:void 0,source:N==="noCode"?void 0:c.source??M.source})},v=((x=s.scripts)==null?void 0:x.kinds)??$.NICE_STUDIO_SCRIPT_KINDS,S=$.studioScriptLanguages(c.kind),g=(j=s.scripts)==null?void 0:j.triggers,b=e.documents.flatMap(N=>{var z;return((z=Ne(e,N))==null?void 0:z.scripts)??[]}).map(N=>N.key).filter(N=>N!==n.key),I=e.documents.filter(N=>N.kind.editor==="dataSources").flatMap(N=>ie(e,N)??[]).map(N=>N.key),_=c.sourcePath?e.documents.find(N=>N.paths.includes(c.sourcePath)):void 0;let k;return c.kind==="noCode"?k=t.jsx(h.NiceNoCodeScriptEditor,{value:{parameters:c.parameters,steps:c.steps??[]},onChange:N=>y({steps:N.steps}),dataSources:I,scripts:b,io:r,readOnly:a}):c.sourcePath&&c.source===void 0?k=t.jsxs("p",{className:"nice-development-studio__muted",children:[m("devStudio.scripts.sourcePath","The code is in {path}.").replace("{path}",c.sourcePath),_?"":` ${m("devStudio.scripts.sourceMissing","The module has no such file.")}`]}):d&&c.kind==="frontend"&&c.language==="javascript"?k=t.jsx(h.NiceScriptRunner,{...d,value:c.source??"",onChange:N=>y({source:N})}):k=t.jsx(h.NiceSimpleCodeEditor,{value:c.source??"",onChange:N=>y({source:N}),language:sn(c.language),height:"100%",lineNumbers:!0,readOnly:a}),t.jsxs("div",{className:"nice-development-studio__script","data-testid":"studio-script-editor",children:[t.jsxs("div",{className:"nice-development-studio__script-meta",children:[t.jsx(h.NiceTextInput,{label:m("devStudio.scripts.name","Name"),value:c.name,onChange:N=>y({name:N}),readOnly:a,size:"sm","data-testid":"studio-script-name"}),t.jsx(h.NiceTextInput,{label:m("devStudio.scripts.displayName","Display name"),value:c.displayName??"",onChange:N=>y({displayName:N||void 0}),readOnly:a,size:"sm"}),t.jsx(h.NiceSelect,{label:m("devStudio.scripts.kind","Kind"),value:c.kind,options:v.map(N=>({value:N,label:ht(m,N)})),onChange:N=>f(String(N)),disabled:a,size:"sm"}),S.length>0&&t.jsx(h.NiceSelect,{label:m("devStudio.scripts.language","Language"),value:c.language??S[0],options:[...new Set([...S,...c.language?[c.language]:[]])].map(N=>({value:N,label:Ut[N]??N})),onChange:N=>y({language:String(N)}),disabled:a,size:"sm"}),t.jsx(Ht,{value:c.category??"",onChange:N=>y({category:N||void 0}),categories:p,readOnly:a}),g&&g.length>0?t.jsx(h.NiceSelect,{label:m("devStudio.scripts.trigger","Runs on"),value:c.trigger??"",options:[{value:"",label:m("devStudio.scripts.trigger.none","When called")},...g.map(N=>({value:N.id,label:N.label}))],onChange:N=>y({trigger:String(N)||void 0}),disabled:a,size:"sm"}):t.jsx(h.NiceTextInput,{label:m("devStudio.scripts.trigger","Runs on"),value:c.trigger??"",onChange:N=>y({trigger:N||void 0}),readOnly:a,size:"sm"}),c.kind!=="noCode"&&t.jsx(h.NiceTextInput,{label:m("devStudio.scripts.returnType","Returns"),value:c.returnType??"",onChange:N=>y({returnType:N||void 0}),readOnly:a,size:"sm"}),t.jsx(h.NiceTextArea,{label:m("devStudio.scripts.description","Description"),value:c.description??"",onChange:N=>y({description:N||void 0}),readOnly:a,rows:3}),t.jsx(on,{value:c.parameters??[],onChange:N=>y({parameters:N}),readOnly:a})]}),t.jsx("div",{className:"nice-development-studio__script-body",children:k})]})}function dn({value:e,onChange:i,preset:n,readOnly:s}){var f;const{t:o}=h.useNiceTranslation(),a=e.phases??{},d=Object.keys(a),[r,l]=w.useState(d[0]??""),m=d.includes(r)?r:d[0]??"",c=(((f=n.scripts)==null?void 0:f.phases)??$.NICE_STUDIO_SCRIPT_PHASES).filter(v=>!d.includes(v)),p=v=>i({...e,phases:v}),u=a[m]??[],y=v=>p({...a,[m]:v});return e.holds==="scripts"?t.jsx("p",{className:"nice-development-studio__muted",children:o("devStudio.scripts.noPhases","This file holds named scripts only.")}):t.jsxs("div",{className:"nice-development-studio__phases","data-testid":"studio-script-phases",children:[t.jsxs("div",{className:"nice-development-studio__phases-bar",children:[d.map(v=>t.jsx(h.NiceButton,{size:"sm",variant:v===m?"primary":"ghost","aria-pressed":v===m,onClick:()=>l(v),children:`${v} (${a[v].length})`},v)),!s&&c.length>0&&t.jsx(h.NiceSelect,{"aria-label":o("devStudio.scripts.addPhase","Add phase"),placeholder:o("devStudio.scripts.addPhase","Add phase"),value:"",options:c,onChange:v=>{const S=String(v);S&&(p({...a,[S]:[]}),l(S))},size:"sm"}),!s&&m&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"trash",size:14}),onClick:()=>{const v={...a};delete v[m],p(v)},children:o("devStudio.scripts.removePhase","Remove phase")})]}),m?t.jsx("ol",{className:"nice-development-studio__statements",children:u.map((v,S)=>t.jsxs("li",{className:"nice-development-studio__statement",children:[t.jsx(h.NiceSimpleCodeEditor,{value:v,onChange:g=>y(u.map((b,I)=>I===S?g:b)),language:"sql",height:Math.min(240,28+20*(v.split(`
|
|
6
|
-
`).length||1)),readOnly:s}),!s&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost","aria-label":o("devStudio.scripts.removeStatement","Remove statement"),onClick:()=>
|
|
7
|
-
`:""];const j=S.holds==="scripts"&&S.scripts.length===0?"phases":S.holds;return{model:{...S,phases:x,...j?{holds:j}:{}},screen:N=>({kind:"document",module:o,docKey:N})}}const g=$.newStudioScript({kind:s.choice,name:s.name,language:s.language,category:s.category,trigger:s.trigger});let b=g.name;for(let k=2;S.scripts.some(x=>x.key===b);k++)b=`${g.name}${k}`;const I={...g,name:b},_={key:b,label:I.displayName||b,definition:I,source:{}};return{model:{...S,scripts:[...S.scripts,_]},screen:k=>({kind:"item",module:o,group:"scripts",docKey:k,itemKey:b})}};if(r){const S=l(Ne(e,r)??{scripts:[]});return n.setDraft(o,r.key,S.model),S.screen(r.key)}const m=Yt(e,i);if(!m)return;const c=l(m.model),{path:p}=m.file,u=(y=m.kind.encode(c.model,[m.file],m.ctx).files.find(S=>S.path===p))==null?void 0:y.text;if(u!==void 0)return n.setRaw(o,p,u),c.screen(`${m.kind.id}:${((v=(f=m.kind).group)==null?void 0:v.call(f,p))??p}`)}function Xt(e,i){return e.documents.some(n=>n.kind.editor==="scriptList"&&n.model!==void 0)||Yt(e,i)!==void 0}function Zt({module:e,preset:i,onAdd:n,onClose:s}){var N,z,O;const{t:o}=h.useNiceTranslation(),a=((N=i.scripts)==null?void 0:N.kinds)??$.NICE_STUDIO_SCRIPT_KINDS,d=((z=i.scripts)==null?void 0:z.phases)??$.NICE_STUDIO_SCRIPT_PHASES,[r,l]=w.useState(a[0]??"frontend"),[m,c]=w.useState(""),[p,u]=w.useState(""),[y,f]=w.useState(""),[v,S]=w.useState(void 0),[g,b]=w.useState(d.includes("postInstall")?"postInstall":d[0]),I=w.useMemo(()=>Gt(e,i),[e,i]),_=r==="phase"?[]:$.studioScriptLanguages(r),k=r==="phase"||!!m.trim(),x=()=>{k&&(s(),n({choice:r,name:m.trim(),category:p.trim()||void 0,trigger:y||void 0,language:v&&_.includes(v)?v:void 0,phase:g}))},j=[...a.map(M=>({id:M,icon:Pt[M],label:ht(o,M),hint:nn(o,M)})),{id:"phase",icon:"database",label:o("devStudio.scripts.kind.phase","Database script"),hint:o("devStudio.scripts.hint.phase","SQL run when the module is installed or removed.")}];return t.jsx(h.NiceModal,{open:!0,onClose:s,title:o("devStudio.scripts.add","Add script"),footer:t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{variant:"ghost",onClick:s,children:o("devStudio.cancel","Cancel")}),t.jsx(h.NiceButton,{variant:"primary",disabled:!k,onClick:x,"data-testid":"studio-script-add-ok",children:o("devStudio.scripts.create","Create")})]}),children:t.jsxs("div",{className:"nice-development-studio__form",children:[t.jsx("div",{className:"nice-development-studio__script-kinds",children:j.map(M=>t.jsxs("button",{type:"button","aria-pressed":M.id===r,className:`nice-development-studio__script-kind${M.id===r?" nice-development-studio__script-kind--active":""}`,onClick:()=>l(M.id),"data-testid":`studio-script-kind-${M.id}`,children:[t.jsx(h.NiceIcon,{name:M.icon,size:20}),t.jsx("strong",{children:M.label}),t.jsx("span",{children:M.hint})]},M.id))}),r==="phase"?t.jsxs(t.Fragment,{children:[t.jsx(h.NiceSelect,{label:o("devStudio.scripts.phase","Phase"),value:g,options:[...d],onChange:M=>b(String(M)),size:"sm"}),t.jsx(h.NiceTextInput,{label:o("devStudio.scripts.comment","What it does"),value:m,onChange:c,size:"sm"})]}):t.jsxs(t.Fragment,{children:[t.jsx(h.NiceTextInput,{label:o("devStudio.scripts.name","Name"),value:m,onChange:c,onKeyDown:M=>{M.key==="Enter"&&x()},size:"sm","data-testid":"studio-script-add-name"}),_.length>1&&t.jsx(h.NiceSelect,{label:o("devStudio.scripts.language","Language"),value:v&&_.includes(v)?v:_[0],options:_.map(M=>({value:M,label:Ut[M]??M})),onChange:M=>S(String(M)),size:"sm"}),t.jsx(Ht,{value:p,onChange:u,categories:I}),((O=i.scripts)==null?void 0:O.triggers)&&i.scripts.triggers.length>0&&t.jsx(h.NiceSelect,{label:o("devStudio.scripts.trigger","Runs on"),value:y,options:[{value:"",label:o("devStudio.scripts.trigger.none","When called")},...i.scripts.triggers.map(M=>({value:M.id,label:M.label}))],onChange:M=>f(String(M)),size:"sm"})]})]})})}function Tt(e){var m,c;const{module:i,doc:n,preset:s,session:o,locales:a,readOnly:d}=e,r=ie(i,n),l=p=>o.setDraft(i.key,n.key,p);switch(n.kind.editor){case"manifest":return t.jsx(rn,{...e});case"i18n":{const p=r??{};return t.jsx(pt,{value:p,onChange:l,locales:[...new Set([...a,...Object.keys(p)])],allowEditLocales:!0,allowEditKeys:!0,highlightMissing:!0,readOnly:d})}case"permissions":return t.jsx(cn,{value:r??{permissions:[],groups:[]},onChange:l,readOnly:d});case"seeds":return t.jsx(mn,{value:r??{seeds:{}},onChange:l,entities:Ce(i),readOnly:d});case"rbac":return t.jsx(h.NiceAccessManager,{value:r,onChange:l,readOnly:d});case"hooks":return t.jsx(h.NiceLifecycleHooksEditor,{triggers:((m=s.hooks)==null?void 0:m.triggers)??[],handlers:(c=s.hooks)==null?void 0:c.handlers,bindings:r??[],onChange:l,groupByTrigger:!0,allowCondition:!0,readOnly:d});case"script":return e.scriptRunner?t.jsx(h.NiceScriptRunner,{...e.scriptRunner,value:String(r??""),onChange:l}):t.jsx(h.NiceSimpleCodeEditor,{value:String(r??""),onChange:l,language:"javascript",height:"100%",lineNumbers:!0,readOnly:d});case"scriptList":return t.jsx(dn,{value:r??{scripts:[]},onChange:l,preset:s,readOnly:d});case"text":return t.jsx(h.NiceSimpleCodeEditor,{value:String(r??""),onChange:l,height:"100%",lineNumbers:!0,readOnly:d});default:return t.jsx(Le,{value:r,onChange:l,readOnly:d,height:"100%",label:n.label})}}function rn({module:e,doc:i,preset:n,session:s,readOnly:o,advanced:a}){var I;const{t:d}=h.useNiceTranslation(),r=ie(e,i),l=w.useMemo(()=>r??{},[r]),m=_=>s.setDraft(e.key,i.key,_),c=n.manifestSections,p=w.useMemo(()=>(c??[]).map(_=>$.fitManifestSection(_,l)),[c,l]),u=c??[],y=w.useMemo(()=>new Set(p.flatMap(_=>_.keys)),[p]),f=Object.keys(l).filter(_=>!y.has(_)),[v,S]=w.useState(((I=p[0])==null?void 0:I.section.id)??"__other"),g=p.find(_=>_.section.id===v),b=a?t.jsx(Le,{value:Object.fromEntries(f.map(_=>[_,l[_]])),readOnly:o,label:d("devStudio.manifest.other","Other properties"),onChange:_=>{if(_&&typeof _=="object"&&!Array.isArray(_)){const k=Object.fromEntries(Object.entries(l).filter(([x])=>y.has(x)));m({...k,..._})}}}):t.jsxs("div",{className:"nice-development-studio__note",children:[t.jsx("p",{children:d("devStudio.manifest.kept","These properties have no form here. Saving keeps them exactly as they are; switch to the advanced mode to edit them.")}),t.jsx("ul",{className:"nice-development-studio__chips",children:f.map(_=>t.jsx("li",{className:"nice-development-studio__tag",children:_},_))})]});return t.jsxs("div",{className:"nice-development-studio__sections","data-testid":"studio-manifest-form",children:[t.jsxs("nav",{className:"nice-development-studio__section-nav","aria-label":d("devStudio.manifest.sections","Sections"),children:[p.map(({section:_})=>t.jsx(h.NiceButton,{size:"sm",variant:v===_.id?"primary":"ghost","aria-pressed":v===_.id,onClick:()=>S(_.id),children:_.title},_.id)),f.length>0&&t.jsx(h.NiceButton,{size:"sm",variant:v==="__other"?"primary":"ghost","aria-pressed":v==="__other",onClick:()=>S("__other"),children:`${d("devStudio.manifest.other","Other properties")} (${f.length})`})]}),t.jsx("div",{className:"nice-development-studio__section-body",children:g?t.jsx(Te,{schema:g.section.schema,fields:g.section.fields,uiSchema:g.section.uiSchema,value:Object.fromEntries(g.keys.filter(_=>_ in l).map(_=>[_,l[_]])),onChange:_=>{const k={...l};for(const x of g.keys)_[x]===void 0?delete k[x]:k[x]=_[x];m(k)},readOnly:o}):f.length>0||u.length===0?b:null})]})}function cn({value:e,onChange:i,readOnly:n}){const{t:s}=h.useNiceTranslation(),o={code:s("devStudio.permissions.code","Code"),name:s("devStudio.permissions.name","Name"),description:s("devStudio.permissions.description","Description")},a=w.useMemo(()=>{const r={};for(const l of e.groups)for(const m of l.permissions)r[`${l.id}:${m}`]=!0;return r},[e.groups]),d=(r,l)=>{const m=e.permissions[r],c={...m,...l};i({permissions:e.permissions.map((p,u)=>u===r?c:p),groups:l.code!==void 0&&l.code!==m.code?e.groups.map(p=>({...p,permissions:p.permissions.map(u=>u===m.code?c.code:u)})):e.groups})};return t.jsxs("div",{className:"nice-development-studio__permissions",children:[t.jsx("h4",{children:s("devStudio.permissions.codes","Permissions")}),t.jsxs("table",{className:"nice-development-studio__table",children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:o.code}),t.jsx("th",{children:o.name}),t.jsx("th",{children:o.description}),!n&&t.jsx("th",{"aria-label":s("devStudio.delete","Delete")})]})}),t.jsx("tbody",{children:e.permissions.map((r,l)=>t.jsxs("tr",{children:[["code","name","description"].map(m=>t.jsx("td",{children:t.jsx("input",{className:"nice-development-studio__cell",value:r[m]??"",readOnly:n,"aria-label":`${o[m]} ${r.code}`,onChange:c=>d(l,{[m]:c.target.value})})},m)),!n&&t.jsx("td",{children:t.jsx(h.NiceButton,{size:"sm",variant:"ghost",ariaLabel:`${s("devStudio.delete","Delete")} ${r.code}`,onClick:()=>i({permissions:e.permissions.filter((m,c)=>c!==l),groups:e.groups.map(m=>({...m,permissions:m.permissions.filter(c=>c!==r.code)}))}),children:t.jsx(h.NiceIcon,{name:"trash",size:14})})})]},l))})]}),!n&&t.jsxs("div",{className:"nice-development-studio__row",children:[t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:()=>i({...e,permissions:[...e.permissions,{code:`New.Permission${e.permissions.length+1}`}]}),children:s("devStudio.permissions.addCode","New permission")}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:()=>i({...e,groups:[...e.groups,{id:`group${e.groups.length+1}`,label:s("devStudio.permissions.newGroup","Group {n}").replace("{n}",String(e.groups.length+1)),permissions:[]}]}),children:s("devStudio.permissions.addGroup","New group")})]}),t.jsx("h4",{children:s("devStudio.permissions.groups","Groups")}),t.jsx(h.NicePermissionMatrix,{roles:e.groups.map(r=>({id:r.id,label:r.label})),actions:e.permissions.map(r=>({id:r.code,label:r.name||r.code})),value:a,readOnly:n,showBulkActions:!0,onChange:r=>i({...e,groups:e.groups.map(l=>({...l,permissions:e.permissions.map(m=>m.code).filter(m=>r[`${l.id}:${m}`]===!0)}))})})]})}const Et=e=>e===null||typeof e!="object";function ln(e){const i=e.toLowerCase();return/(int|long|decimal|double|float|number|money)/.test(i)?"number":/bool/.test(i)?"boolean":"string"}function un(e,i){const n={},s=Array.isArray(i==null?void 0:i.fields)?i.fields:[];for(const o of s){const a=String(o.name??"");a&&e.every(d=>Et(d[a]))&&(n[a]={type:ln(String(o.dataType??o.type??"string")),title:String(o.displayName||a)})}for(const o of e)for(const[a,d]of Object.entries(o))!(a in n)&&e.every(r=>Et(r[a]))&&(n[a]={type:typeof d=="number"?"number":typeof d=="boolean"?"boolean":"string",title:a});return{type:"object",properties:n}}function mn({value:e,onChange:i,entities:n,readOnly:s}){const{t:o}=h.useNiceTranslation(),a=r=>n.find(l=>l.name===r||l.tableName===r),d=r=>{const l=e[r]??{},m=Object.keys(l);return m.length===0?t.jsx("p",{className:"nice-development-studio__muted",children:o("devStudio.seeds.empty","No rows.")}):t.jsx(h.NiceTabs,{tabs:m.map(c=>{const p=l[c];return{id:c,label:`${c} (${p.length})`,content:t.jsx(ot,{value:p,itemSchema:un(p,a(c)),title:c,readOnly:s,onChange:u=>{const y=u.length===p.length?u.map((f,v)=>f===p[v]?f:{...p[v],...f}):u;i({...e,[r]:{...l,[c]:y}})}})}})})};return t.jsx(h.NiceTabs,{tabs:[{id:"seeds",label:o("devStudio.seeds.data","Data"),content:d("seeds")},{id:"demo",label:o("devStudio.seeds.demo","Demo data"),content:d("demoSeeds")}]})}function pn({module:e,path:i,session:n,readOnly:s}){var c;const{t:o}=h.useNiceTranslation(),[a,d]=w.useState("source"),r=e.changes.find(p=>p.path===i),l=e.documents.filter(p=>p.paths.includes(i)).map(p=>p.key),m=((c=e.files.find(p=>p.path===i))==null?void 0:c.text)??"";return t.jsxs("div",{className:"nice-development-studio__source","data-testid":"studio-file-source",children:[t.jsx("div",{className:"nice-development-studio__row",children:t.jsxs("div",{className:"nice-development-studio__segmented",role:"group","aria-label":o("devStudio.doc.mode","Show"),children:[t.jsx(h.NiceButton,{size:"sm",variant:a==="source"?"primary":"ghost","aria-pressed":a==="source",onClick:()=>d("source"),children:o("devStudio.doc.source","Source")}),t.jsx(h.NiceButton,{size:"sm",variant:a==="changes"?"primary":"ghost","aria-pressed":a==="changes",onClick:()=>d("changes"),children:`${o("devStudio.doc.changes","Changes")}${r?" (1)":""}`})]})}),a==="source"?t.jsx(h.NiceSimpleCodeEditor,{value:e.pending.get(i)??"",language:i.endsWith(".json")?"json":i.endsWith(".js")?"javascript":"plaintext",height:"100%",lineNumbers:!0,readOnly:s,onChange:p=>n.setRaw(e.key,i,$.keepTextFormat(p,e.pending.get(i)),l)}):r?t.jsx(Ot,{before:m,after:r.type==="write"?r.text:""}):t.jsx("p",{className:"nice-development-studio__muted",children:o("devStudio.diff.none","No changes.")})]})}const hn=e=>({type:"object",required:["id"],properties:{id:{type:"string",title:e("devStudio.template.id","Id (slug)")},category:{type:"string",title:e("devStudio.template.category","Category")},subCategory:{type:"string",title:e("devStudio.template.subCategory","Subcategory")},parentId:{type:"string",title:e("devStudio.template.parent","Parent template")},icon:{type:"string",title:e("devStudio.template.icon","Icon")},sortOrder:{type:"number",title:e("devStudio.template.sortOrder","Order")},tags:{type:"array",items:{type:"string"},title:e("devStudio.template.tags","Tags")}}});function vn({session:e,template:i,locales:n,extraSchema:s,readOnly:o,onSaved:a,onDeleted:d}){var _;const{t:r}=h.useNiceTranslation(),[l,m]=w.useState(()=>i??{id:"",translations:{[n[0]??"en"]:{name:""}},modules:[]}),[c,p]=w.useState(null),u=o||!!(i!=null&&i.readOnly),y={id:l.id,category:l.category,subCategory:l.subCategory,parentId:l.parentId,icon:l.icon,sortOrder:l.sortOrder,tags:l.tags},f=Object.fromEntries(Object.entries(l.translations).map(([k,x])=>[k,{name:x.name,description:x.description??""}])),v=w.useMemo(()=>e.workspaces.map(k=>{const x=e.modulesByWs[k.id]??[],j=[...new Set(x.map(N=>N.packageId??""))].sort();return{id:`w:${k.id}`,label:k.label,kind:"workspace",children:j.map(N=>({id:`w:${k.id}/p:${N}`,label:N||r("devStudio.explorer.noPackage","No package"),kind:"package",children:x.filter(z=>(z.packageId??"")===N).map(z=>({id:`m:${z.id}`,label:z.label,kind:"module"}))}))}}),[e.workspaces,e.modulesByWs,r]),S=w.useMemo(()=>{const k=new Map;for(const x of Object.values(e.modulesByWs))for(const j of x)k.set(j.id,j.label);return k},[e.modulesByWs]),g=k=>m({...l,modules:k}),b=(k,x)=>{const j=[...l.modules],[N]=j.splice(k,1);j.splice(k+x,0,N),g(j)},I=[{field:"label",header:r("devStudio.explorer.name","Name")}];return t.jsxs("div",{className:"nice-development-studio__template","data-testid":"studio-template-editor",children:[t.jsxs("div",{className:"nice-development-studio__doc-bar",children:[t.jsx(h.NiceIcon,{name:"layers",size:14}),t.jsx("strong",{className:"nice-development-studio__doc-title",children:i?((_=l.translations.en)==null?void 0:_.name)||l.id:r("devStudio.template.new","New template")}),t.jsx("span",{className:"nice-development-studio__spacer"}),!u&&t.jsx(h.NiceButton,{size:"sm",variant:"primary",disabled:!l.id.trim(),onClick:async()=>{p(null);const k=await e.saveTemplate({...l,id:l.id.trim()},i==null?void 0:i.id);k?a==null||a(k):p(r("devStudio.template.saveFailed","The template could not be saved; see the output panel."))},children:r("devStudio.save","Save")}),!u&&i&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"trash",size:14}),onClick:async()=>{await e.deleteTemplate(i.id)&&(d==null||d())},children:r("devStudio.delete","Delete")})]}),c&&t.jsx("p",{className:"nice-development-studio__error",role:"alert",children:c}),t.jsxs("div",{className:"nice-development-studio__columns",children:[t.jsxs("section",{children:[t.jsx("h4",{children:r("devStudio.template.basics","Template")}),t.jsx(Te,{schema:hn(r),value:y,readOnly:u,onChange:k=>m({...l,id:String(k.id??""),category:k.category||void 0,subCategory:k.subCategory||void 0,parentId:k.parentId||void 0,icon:k.icon||void 0,sortOrder:typeof k.sortOrder=="number"?k.sortOrder:void 0,tags:Array.isArray(k.tags)?k.tags:void 0})}),s&&t.jsx(Te,{schema:s,value:l.extra??{},readOnly:u,onChange:k=>m({...l,extra:k})}),t.jsx("h4",{children:r("devStudio.template.translations","Name and description")}),t.jsx(pt,{value:f,locales:[...new Set([...n,...Object.keys(f)])],allowEditLocales:!0,readOnly:u,onChange:k=>m({...l,translations:Object.fromEntries(Object.entries(k).map(([x,j])=>[x,{name:j.name??"",...j.description?{description:j.description}:{}}]))})})]}),t.jsxs("section",{children:[t.jsx("h4",{children:r("devStudio.template.modules","Modules")}),t.jsx(h.NiceTreeGrid,{data:v,nested:!0,keyField:"id",childrenField:"children",columns:I,sortable:!1,compact:!0,checkable:!0,checkStrategy:"leaves",isRowCheckable:k=>k.kind!=="workspace",isRowDisabled:()=>u,checkedKeys:l.modules.map(k=>`m:${k.moduleId}`),onCheckedChange:k=>{const x=k.filter(z=>z.startsWith("m:")).map(z=>z.slice(2)),j=l.modules.filter(z=>x.includes(z.moduleId)),N=x.filter(z=>!j.some(O=>O.moduleId===z)).map(z=>({moduleId:z}));g([...j,...N])},checkedSummary:k=>r("devStudio.template.summary","{count} modules · {required} required").replace("{count}",String(k.checked)).replace("{required}",String(l.modules.filter(x=>x.required).length)),searchable:!0,searchFields:["label"],virtualScroll:!0,height:320,"aria-label":r("devStudio.template.modules","Modules")}),t.jsxs("table",{className:"nice-development-studio__table",children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:r("devStudio.template.module","Module")}),t.jsx("th",{children:r("devStudio.template.required","required")}),t.jsx("th",{children:r("devStudio.template.condition","Condition")}),!u&&t.jsx("th",{"aria-label":r("devStudio.template.order","Order")})]})}),t.jsx("tbody",{children:l.modules.map((k,x)=>t.jsxs("tr",{children:[t.jsx("td",{children:S.get(k.moduleId)??k.moduleId}),t.jsx("td",{children:t.jsx("input",{type:"checkbox",checked:!!k.required,disabled:u,"aria-label":`${r("devStudio.template.required","required")} ${k.moduleId}`,onChange:j=>g(l.modules.map((N,z)=>z===x?{...N,required:j.target.checked}:N))})}),t.jsx("td",{children:t.jsx("input",{className:"nice-development-studio__cell",value:k.condition??"",readOnly:u,"aria-label":`${r("devStudio.template.condition","Condition")} ${k.moduleId}`,onChange:j=>g(l.modules.map((N,z)=>z===x?{...N,condition:j.target.value||void 0}:N))})}),!u&&t.jsxs("td",{className:"nice-development-studio__nowrap",children:[t.jsx(h.NiceButton,{size:"sm",variant:"ghost",disabled:x===0,ariaLabel:r("devStudio.template.up","Move up"),onClick:()=>b(x,-1),children:t.jsx(h.NiceIcon,{name:"chevron-up",size:12})}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",disabled:x===l.modules.length-1,ariaLabel:r("devStudio.template.down","Move down"),onClick:()=>b(x,1),children:t.jsx(h.NiceIcon,{name:"chevron-down",size:12})})]})]},k.moduleId))})]})]})]})]})}function fn({session:e,pkg:i,readOnly:n,onNewModule:s,onOpenModule:o}){const{t:a}=h.useNiceTranslation(),[d,r]=w.useState({id:i.id,label:i.label,description:i.description,icon:i.icon}),l=(e.modulesByWs[i.workspaceId]??[]).filter(c=>c.packageId===i.id),m=!n&&!i.derived&&!i.readOnly;return t.jsxs("div",{className:"nice-development-studio__template","data-testid":"studio-package-editor",children:[t.jsxs("div",{className:"nice-development-studio__doc-bar",children:[t.jsx(h.NiceIcon,{name:"archive",size:14}),t.jsx("strong",{className:"nice-development-studio__doc-title",children:i.label||i.id}),t.jsx("span",{className:"nice-development-studio__spacer"}),!n&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:s,children:a("devStudio.package.newModule","New module here")}),m&&t.jsx(h.NiceButton,{size:"sm",variant:"primary",onClick:()=>void e.savePackage({...i,id:String(d.id??i.id),label:String(d.label??""),description:d.description||void 0,icon:d.icon||void 0}),children:a("devStudio.save","Save")})]}),i.derived?t.jsx("p",{className:"nice-development-studio__muted",children:a("devStudio.package.derived","This package comes from the modules themselves (their category); rename it by changing their manifests.")}):t.jsx(Te,{schema:{type:"object",required:["id","label"],properties:{id:{type:"string",title:a("devStudio.package.id","Id")},label:{type:"string",title:a("devStudio.package.label","Name")},description:{type:"string",title:a("devStudio.package.description","Description")},icon:{type:"string",title:a("devStudio.template.icon","Icon")}}},value:d,readOnly:!m,onChange:c=>r(c)}),t.jsx("h4",{children:a("devStudio.template.modules","Modules")}),t.jsxs("ul",{className:"nice-development-studio__list",children:[l.map(c=>t.jsxs("li",{children:[t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"box",size:14}),onClick:()=>o(c.id),children:c.label}),c.description&&t.jsx("span",{className:"nice-development-studio__muted",children:c.description})]},c.id)),l.length===0&&t.jsx("li",{className:"nice-development-studio__muted",children:a("devStudio.explorer.empty","No modules.")})]})]})}const gn=e=>"module"in e?e.module:void 0;function yn(e){const{screen:i,crumbs:n,session:s,readOnly:o,tutorialButton:a,onBack:d,onSave:r}=e,{t:l}=h.useNiceTranslation(),m=gn(i),c=m?s.modules[H(m)]:void 0,p=o(m),u=Sn(i,c,s);return t.jsxs("div",{className:"nice-development-studio__edit","data-testid":"studio-edit-screen",children:[t.jsxs("header",{className:"nice-development-studio__edit-header",children:[t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"arrow-left",size:14}),onClick:d,"data-testid":"studio-back",children:l("devStudio.edit.back","Back")}),t.jsx(h.NiceBreadcrumb,{className:"nice-development-studio__crumbs",size:"sm",separator:"›",items:n}),t.jsx("span",{className:"nice-development-studio__spacer"}),u&&!p&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"trash",size:14}),onClick:()=>{u(),d()},children:l("devStudio.delete","Delete")}),c&&t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"check",size:14}),onClick:()=>void s.validate(c.key),children:l("devStudio.validate","Validate")}),!p&&t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{size:"sm",variant:"ghost",disabled:!c.dirty,onClick:()=>s.discard(c.key),children:l("devStudio.discard","Discard changes")}),t.jsx(h.NiceButton,{size:"sm",variant:"primary",disabled:!c.dirty,onClick:()=>r(c.key),"data-tour":"devstudio-save",children:c.dirty?l("devStudio.saveCount","Save ({count})").replace("{count}",String(c.changes.length)):l("devStudio.save","Save")})]})]}),a]}),t.jsx("div",{className:"nice-development-studio__edit-body",children:t.jsx(bn,{...e,module:c,readOnlyHere:p})})]})}function Sn(e,i,n){if(!i||e.kind!=="entity"&&e.kind!=="item"||e.kind==="item"&&e.docKey===Oe)return;const s=fe(i,e.docKey);if(!s)return;if(e.kind==="entity"){const a=ie(i,s);return Array.isArray(a)?()=>n.setDraft(i.key,s.key,ut(a,e.index,null)):void 0}if(e.group==="dataSources"){const a=ie(i,s)??[],d=de(i,s).findIndex(r=>r.key===e.itemKey);return d<0?void 0:()=>n.setDraft(i.key,s.key,a.filter((r,l)=>l!==d))}const o=de(i,s);return()=>n.setDraft(i.key,s.key,mt(i,s,At(o,e.itemKey,null)))}function kn(e,i){return Object.values(i.modules).filter(n=>H(n.key)!==H(e.key)).flatMap(n=>$.entitiesToSchemas(Ce(n)).map(s=>({...s,schema:n.key.id})))}function he(){const{t:e}=h.useNiceTranslation();return t.jsx("p",{className:"nice-development-studio__muted",children:e("devStudio.edit.gone","This is no longer in the module.")})}function bn(e){var c,p,u,y,f;const{screen:i,module:n,session:s,preset:o,provider:a,locales:d,advanced:r,readOnlyHere:l}=e,{t:m}=h.useNiceTranslation();if(i.kind==="package")return t.jsx(fn,{session:s,pkg:i.pkg,readOnly:e.readOnly(),onNewModule:()=>e.onNewModule({workspaceId:i.pkg.workspaceId,packageId:i.pkg.id}),onOpenModule:v=>e.onReveal({kind:"module",module:{workspaceId:i.pkg.workspaceId,id:v}})});if(i.kind==="template"){const v=i.templateId?(c=s.templates)==null?void 0:c.find(S=>S.id===i.templateId):void 0;return t.jsx(vn,{session:s,template:v,locales:d,extraSchema:o.templateSchema,readOnly:e.readOnly(),onSaved:S=>{S.id!==i.templateId&&e.onScreen({kind:"template",templateId:S.id})},onDeleted:e.onBack},i.templateId??"new")}if(!n)return t.jsx("p",{className:"nice-development-studio__muted",children:m("devStudio.loading","Loading…")});switch(i.kind){case"manifest":{const v=n.documents.find(S=>S.kind.editor==="manifest");return v?t.jsx(Tt,{module:n,doc:v,preset:o,session:s,locales:d,readOnly:l,advanced:r,scriptRunner:e.scriptRunner}):t.jsx(he,{})}case"entity":{const v=fe(n,i.docKey),S=v?ie(n,v):void 0,g=Array.isArray(S)?S[i.index]:void 0;return!v||!S||!g?t.jsx(he,{}):t.jsx(at,{value:g,onChange:b=>s.setDraft(n.key,v.key,ut(S,i.index,b)),entityMetaSchema:(p=o.entities)==null?void 0:p.entityMetaSchema,fieldSchema:(u=o.entities)==null?void 0:u.fieldSchema,fieldsKey:(y=o.entities)==null?void 0:y.fieldsKey,readOnly:l,"data-testid":"studio-entity-form"})}case"item":return t.jsx(xn,{...e,screen:i,module:n});case"document":{const v=fe(n,i.docKey);return v?t.jsx(Tt,{module:n,doc:v,preset:o,session:s,locales:d,readOnly:l,advanced:r,scriptRunner:e.scriptRunner}):t.jsx(he,{})}case"panel":{const v=(f=e.modulePanels)==null?void 0:f.call(e,{module:n.key,files:n.working,dirty:n.dirty}).find(S=>S.key===i.panelKey);return v?t.jsx(t.Fragment,{children:v.content}):t.jsx(he,{})}case"file":return n.working.some(v=>v.path===i.path)?t.jsx(pn,{module:n,path:i.path,session:s,readOnly:l}):t.jsx(he,{});case"problems":return t.jsx(jn,{module:n,issues:e.issues(n.key),onReveal:e.onReveal});case"history":return t.jsx(Nn,{module:n,provider:a,session:s,readOnly:l})}}function xn({screen:e,module:i,session:n,preset:s,readOnlyHere:o,advanced:a,scriptRunner:d,scriptIo:r,previewDataSource:l,renderViewPreview:m,onScreen:c}){const{t:p}=h.useNiceTranslation();if(e.docKey===Oe){const b=lt(i).find(I=>I.key===e.itemKey);return b?t.jsxs("div",{className:"nice-development-studio__standard-source",children:[t.jsxs("div",{className:"nice-development-studio__note",children:[t.jsx("p",{children:p("devStudio.dataSources.standardNote","A standard source: every entity has it, nobody edits it. Duplicate it to start one of your own.")}),!o&&t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:t.jsx(h.NiceIcon,{name:"copy",size:14}),onClick:()=>{const I=Jt(i,s,n,{...b,key:`${b.key}Copy`,label:`${b.label??b.key} (${p("devStudio.dataSources.copy","copy")})`});I&&c(I)},"data-testid":"studio-duplicate-source",children:p("devStudio.dataSources.duplicate","Duplicate")})]}),t.jsx(h.NiceDataSourceEditor,{value:b,schemas:$.entitiesToSchemas(Ce(i)),onPreview:l?(I,_)=>l(i.key,I,_):void 0,readOnly:!0})]}):t.jsx(he,{})}const u=fe(i,e.docKey);if(!u)return t.jsx(he,{});if(e.group==="dataSources"){const b=ie(i,u)??[],I=de(i,u).findIndex(x=>x.key===e.itemKey),_=b[I];if(I<0)return t.jsx(he,{});const k=x=>n.setDraft(i.key,u.key,b.map((j,N)=>N===I?x:j));return h.isModuleDataSource(_)?t.jsx(h.NiceDataSourceEditor,{value:_,schemas:$.entitiesToSchemas(Ce(i)),extraSchemas:kn(i,n),sources:qi(i),onPreview:l?(x,j)=>l(i.key,x,j):void 0,readOnly:o,onChange:x=>{k(x),x.key!==_.key&&c({...e,itemKey:x.key})}}):t.jsxs("div",{className:"nice-development-studio__source",children:[t.jsx("p",{className:"nice-development-studio__muted",children:p("devStudio.items.rawReason","The editor does not know this shape, so it is edited as JSON.")}),t.jsx(Le,{value:_,readOnly:o,label:e.itemKey,height:"100%",onChange:k})]})}const y=de(i,u),f=y.find(b=>b.key===e.itemKey);if(!f)return t.jsx(he,{});const v=b=>{n.setDraft(i.key,u.key,mt(i,u,At(y,f.key,b))),b.key!==f.key&&c({...e,itemKey:b.key})},S=b=>v({...f,definition:b,label:b.name||f.label,key:b.id&&!y.some(I=>I!==f&&I.key===b.id)?b.id:f.key});if(f.definition===void 0)return a?t.jsxs("div",{className:"nice-development-studio__source",children:[t.jsxs("p",{className:"nice-development-studio__muted",children:[p("devStudio.items.rawReason","The editor does not know this shape, so it is edited as JSON."),f.rawReason?` (${f.rawReason})`:""]}),t.jsx(Le,{value:f.source,readOnly:o,label:f.label,height:"100%",onChange:b=>v({...f,source:b})})]}):t.jsx("p",{className:"nice-development-studio__muted",children:p("devStudio.preview.noDesigner","There is no designer for this kind of entry yet.")});if(e.group==="scripts")return t.jsx(an,{module:i,doc:u,item:f,preset:s,session:n,readOnly:o,scriptRunner:d,scriptIo:r==null?void 0:r(i.key),onRenamed:b=>c({...e,itemKey:b})});if(e.group==="workflows")return t.jsx(ui.NiceWorkflowDesigner,{workflow:f.definition,onChange:b=>S(b),readOnly:o});const g=t.jsx(h.NiceViewEditor,{value:f.definition,onChange:b=>S(b),entities:Ce(i),dataSourceOptions:i.documents.filter(b=>b.kind.editor==="dataSources").flatMap(b=>ie(i,b)??[]).filter(h.isModuleDataSource).map(b=>({key:b.key,label:b.label})),height:640});return m?t.jsx(h.NiceTabs,{tabs:[{id:"design",label:p("devStudio.view.design","Design"),content:g},{id:"preview",label:p("devStudio.view.hostPreview","Preview in the app"),content:m({module:i.key,item:f,files:i.working})}]}):g}function jn({module:e,issues:i,onReveal:n}){const{t:s}=h.useNiceTranslation();return i.length===0?t.jsx("p",{className:"nice-development-studio__muted",children:s("devStudio.overview.noProblems","No problems found.")}):t.jsx("ul",{className:"nice-development-studio__issues","data-testid":"studio-problems",children:i.map((o,a)=>t.jsxs("li",{className:`nice-development-studio__issue nice-development-studio__issue--${o.severity}`,children:[t.jsx(h.NiceIcon,{name:o.severity==="error"?"error":o.severity==="warning"?"warning":"info",size:14}),t.jsx("span",{children:ei(s,o)}),o.path&&t.jsx("span",{className:"nice-development-studio__muted",children:o.path}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",onClick:()=>n(Vt(e,o)),children:s("devStudio.problems.goTo","Go to")})]},a))})}function ei(e,i){return i.messageKey?Object.entries(i.params??{}).reduce((n,[s,o])=>n.replace(`{${s}}`,String(o)),e(i.messageKey,i.message)):i.message}function Nn({module:e,provider:i,session:n,readOnly:s}){const[o,a]=w.useState(null),d=e.key;return w.useEffect(()=>{let r=!0;return i!=null&&i.listRevisions&&i.listRevisions(d).then(l=>{r&&a(l.map(m=>({id:m.id,label:m.label,author:m.author,timestamp:m.timestamp,summary:m.summary})))}).catch(()=>a([])),()=>{r=!1}},[i,d,e.files]),t.jsx(h.NiceRevisionHistory,{revisions:o??[],language:"json",loadContent:i!=null&&i.readRevision?r=>i.readRevision(d,r):void 0,onRollback:i!=null&&i.rollback&&!s?async r=>{await i.rollback(d,r),await n.reload(d)}:void 0})}function wn({prompt:e,onClose:i}){const{t:n}=h.useNiceTranslation(),[s,o]=w.useState(e.initial),a=()=>{s.trim()&&(i(),e.onSubmit(s.trim()))};return t.jsx(h.NiceModal,{open:!0,onClose:i,title:e.title,footer:t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{variant:"ghost",onClick:i,children:n("devStudio.cancel","Cancel")}),t.jsx(h.NiceButton,{variant:"primary",disabled:!s.trim(),onClick:a,children:n("devStudio.ok","OK")})]}),children:t.jsx("div",{className:"nice-development-studio__form",children:t.jsx(h.NiceTextInput,{label:n("devStudio.package.label","Name"),value:s,onChange:o,onKeyDown:d=>{d.key==="Enter"&&a()},"data-testid":"studio-layout-name"})})})}function _n(e,i){const{t:n}=h.useNiceTranslation(),[s,o]=w.useState(null),a=w.useCallback((r,l)=>{var y;const m=e.modules[H(r)];if(!m)return;const c=$.studioLayoutPath(m.working),p=(y=m.working.find(f=>f.path===c))==null?void 0:y.text,u=l($.parseStudioLayout(p));if($.isEmptyStudioLayout(u)){p!==void 0&&e.deleteFile(r,c);return}e.setRaw(r,c,$.serializeStudioLayout(u,p))},[e]);return{menuFor:w.useCallback(r=>{const l=r.node,m=Me(l),c=m?e.modules[H(m)]:void 0;if(!m||!c||i(m))return;const p=Wt(c),u=(g,b,I)=>o({title:g,initial:b,onSubmit:I}),y=n("devStudio.layout.newFolder","New folder"),f=(g,b,I)=>({id:"new-folder",icon:"folder",label:y,onSelect:()=>u(y,"",_=>a(m,k=>$.addStudioFolder(k,{label:_,group:g,parent:b,section:I}).layout))}),v=[];switch(l.kind){case"module":v.push({id:"new-section",icon:"layers",label:n("devStudio.layout.newSection","New section"),onSelect:()=>u(n("devStudio.layout.newSection","New section"),"",g=>a(m,b=>$.addStudioSection(b,g).layout))});break;case"group":l.group!=="files"&&v.push(f(l.group,void 0,l.section));break;case"section":v.push({id:"rename",icon:"edit",label:n("devStudio.layout.renameSection","Rename section"),onSelect:()=>u(n("devStudio.layout.renameSection","Rename section"),r.label,g=>a(m,b=>$.renameStudioLayoutNode(b,{kind:"section",id:l.sectionId},g)))},{id:"delete",icon:"trash",danger:!0,label:n("devStudio.layout.deleteSection","Delete section"),onSelect:()=>a(m,g=>$.removeStudioLayoutNode(g,{kind:"section",id:l.sectionId}))});break;case"folder":{const g=p.folders.find(b=>b.id===l.folderId);v.push(f(l.group,l.folderId,g==null?void 0:g.section),{id:"rename",icon:"edit",label:n("devStudio.layout.renameFolder","Rename folder"),onSelect:()=>u(n("devStudio.layout.renameFolder","Rename folder"),r.label,b=>a(m,I=>$.renameStudioLayoutNode(I,{kind:"folder",id:l.folderId},b)))},{id:"delete",icon:"trash",danger:!0,label:n("devStudio.layout.deleteFolder","Delete folder"),onSelect:()=>a(m,b=>$.removeStudioLayoutNode(b,{kind:"folder",id:l.folderId}))});break}}const S=r.ref;if(S){const g=S.slice(0,S.indexOf(":")),b=p.placement[S],I=[{id:"move-new-folder",icon:"folder",label:n("devStudio.layout.moveToNewFolder","Move to a new folder…"),onSelect:()=>u(y,"",_=>a(m,k=>{const x=$.addStudioFolder(k,{label:_,group:g,section:b==null?void 0:b.section});return $.placeStudioEntry(x.layout,S,{folder:x.id})}))},...p.folders.filter(_=>_.group===g&&_.id!==(b==null?void 0:b.folder)).map(_=>({id:`move-folder-${_.id}`,icon:"folder",label:n("devStudio.layout.moveToFolder","Move to folder: {name}").replace("{name}",_.label),onSelect:()=>a(m,k=>$.placeStudioEntry(k,S,{folder:_.id}))})),...p.sections.filter(_=>_.id!==(b==null?void 0:b.section)||!!(b!=null&&b.folder)).map(_=>({id:`move-section-${_.id}`,icon:"layers",label:n("devStudio.layout.moveToSection","Move to section: {name}").replace("{name}",_.label),onSelect:()=>a(m,k=>$.placeStudioEntry(k,S,{section:_.id}))}))];(b!=null&&b.folder||b!=null&&b.section)&&I.push({id:"move-back",icon:"arrow-left",label:n("devStudio.layout.moveBack","Move back to its group"),onSelect:()=>a(m,_=>$.placeStudioEntry(_,S,{}))}),v.length&&v.push({id:"divider",divider:!0}),v.push(...I)}return v.length?v:void 0},[e.modules,i,a,n]),dialog:s?t.jsx(wn,{prompt:s,onClose:()=>o(null)}):null}}function ne({icon:e,title:i,subtitle:n,badges:s,actions:o,children:a}){return t.jsxs("section",{className:"nice-development-studio__preview","data-testid":"studio-preview",children:[t.jsxs("div",{className:"nice-development-studio__preview-info",children:[t.jsxs("header",{className:"nice-development-studio__preview-head",children:[t.jsx(h.NiceIcon,{name:e,size:20}),t.jsxs("div",{className:"nice-development-studio__preview-name",children:[t.jsx("h3",{className:"nice-development-studio__preview-title",children:i}),n&&t.jsx("span",{className:"nice-development-studio__muted",children:n})]})]}),s&&t.jsx("div",{className:"nice-development-studio__preview-badges",children:s}),a]}),o&&t.jsx("footer",{className:"nice-development-studio__preview-actions",children:o})]})}function ce({items:e}){const i=e.filter(([,n])=>n!=null&&n!=="");return i.length===0?null:t.jsx("dl",{className:"nice-development-studio__facts",children:i.map(([n,s])=>t.jsxs("div",{className:"nice-development-studio__fact",children:[t.jsx("dt",{children:n}),t.jsx("dd",{children:s})]},n))})}function je({rows:e,onSelect:i,limit:n=12}){const{t:s}=h.useNiceTranslation();return e.length===0?null:t.jsxs("ul",{className:"nice-development-studio__preview-list",children:[e.slice(0,n).map(o=>t.jsxs("li",{children:[t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:o.icon,size:14}),onClick:()=>i(o.id),children:o.label}),o.info&&t.jsx("span",{className:"nice-development-studio__muted",children:o.info})]},o.id)),e.length>n&&t.jsx("li",{className:"nice-development-studio__muted",children:s("devStudio.preview.more","…and {count} more").replace("{count}",String(e.length-n))})]})}const Fe=e=>Array.isArray(e)?e.length:void 0;function In(e){var p,u,y,f;const{row:i,session:n,advanced:s,onEdit:o}=e,{t:a}=h.useNiceTranslation();if(!i)return t.jsx("div",{className:"nice-development-studio__placeholder","data-testid":"studio-preview-empty",children:e.emptyText});const d=i.node,r=d.kind==="package"?qt(d.workspaceId,n.packagesByWs[d.workspaceId],n.modulesByWs[d.workspaceId]??[]):void 0,l=Qi(d,{modules:n.modules,packages:r,advanced:s}),m=l?t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:t.jsx(h.NiceIcon,{name:"edit",size:14}),onClick:()=>o(l),"data-testid":"studio-edit","data-tour":"devstudio-edit",children:d.kind==="module"?a("devStudio.preview.editSettings","Edit settings"):a("devStudio.preview.edit","Edit")}):null,c="module"in d?n.modules[H(d.module)]:void 0;if("module"in d&&!c)return t.jsx(ne,{icon:i.icon,title:i.label,children:t.jsx("p",{className:"nice-development-studio__muted",children:a("devStudio.loading","Loading…")})});switch(d.kind){case"workspace":return t.jsx(Cn,{...e,row:i,workspaceId:d.workspaceId});case"package":return t.jsx(Tn,{...e,row:i,workspaceId:d.workspaceId,packageId:d.packageId,editButton:m});case"module":return t.jsx(En,{...e,row:i,module:c,editButton:m});case"group":return t.jsx($n,{...e,row:i,module:c,group:d.group});case"entity":return t.jsx(Fn,{...e,row:i,module:c,docKey:d.docKey,index:d.index,editButton:m});case"item":return t.jsx(On,{...e,row:i,module:c,node:d,editButton:m});case"document":return t.jsx(zn,{...e,row:i,module:c,docKey:d.docKey,editButton:m});case"section":case"folder":return t.jsx(ne,{icon:i.icon,title:i.label,children:t.jsx(je,{rows:i.children??[],onSelect:e.onSelect})});case"panel":return t.jsx(ne,{icon:i.icon,title:i.label,actions:m});case"file":{const v=c.working.find(S=>S.path===d.path);return t.jsx(ne,{icon:"file",title:i.label,actions:m,children:t.jsx(ce,{items:[[a("devStudio.preview.size","Size"),v?`${new TextEncoder().encode(v.text).length} B`:void 0],[a("devStudio.preview.state","State"),i.dirty?a("devStudio.explorer.unsaved","Unsaved changes"):void 0]]})})}case"templates":return t.jsx(ne,{icon:"layers",title:i.label,actions:(p=e.provider)!=null&&p.saveTemplate&&!e.readOnly()?t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:e.onNewTemplate,children:a("devStudio.preview.newTemplate","New template")}):void 0,children:t.jsx(je,{rows:i.children??[],onSelect:e.onSelect})});case"category":return t.jsx(ne,{icon:"folder",title:i.label,children:t.jsx(je,{rows:i.children??[],onSelect:e.onSelect})});case"template":{const v=(u=n.templates)==null?void 0:u.find(g=>g.id===d.templateId),S=(v==null?void 0:v.translations.en)??Object.values((v==null?void 0:v.translations)??{})[0];return t.jsxs(ne,{icon:i.icon,title:i.label,subtitle:v==null?void 0:v.category,actions:m,children:[(S==null?void 0:S.description)&&t.jsx("p",{children:S.description}),t.jsx(ce,{items:[["Id",v==null?void 0:v.id],[a("devStudio.preview.modules","Modules"),String((v==null?void 0:v.modules.length)??0)],[a("devStudio.preview.tags","Tags"),(y=v==null?void 0:v.tags)==null?void 0:y.join(", ")]]}),t.jsx(je,{rows:i.children??[],onSelect:e.onSelect,limit:8})]})}case"templateModule":{const v=(f=n.templates)==null?void 0:f.find(g=>g.id===d.templateId),S=v==null?void 0:v.modules.find(g=>g.moduleId===d.moduleId);return t.jsxs(ne,{icon:"box",title:i.label,subtitle:d.moduleId,actions:d.target?t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:t.jsx(h.NiceIcon,{name:"arrow-right",size:14}),onClick:()=>e.onReveal({kind:"module",module:d.target}),children:a("devStudio.preview.goToModule","Go to the module")}):void 0,children:[t.jsx(ce,{items:[[a("devStudio.preview.required","Required"),S!=null&&S.required?a("devStudio.preview.yes","yes"):void 0],[a("devStudio.preview.condition","Condition"),S==null?void 0:S.condition],[a("devStudio.preview.description","Description"),S==null?void 0:S.description]]}),i.missing&&t.jsx("p",{className:"nice-development-studio__error",children:a("devStudio.preview.missingModule","No project has this module.")})]})}}}function Cn({row:e,workspaceId:i,session:n,provider:s,readOnly:o,canCreateModule:a,onSelect:d,onNewModule:r,onNewPackage:l}){var u;const{t:m}=h.useNiceTranslation(),c=n.workspaces.find(y=>y.id===i),p=!o()&&!(c!=null&&c.readOnly);return t.jsxs(ne,{icon:e.icon,title:e.label,badges:c!=null&&c.readOnly?t.jsx("span",{className:"nice-development-studio__tag",children:m("devStudio.explorer.readOnly","Read-only")}):void 0,actions:p&&(a||s!=null&&s.savePackage)?t.jsxs(t.Fragment,{children:[a&&t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:t.jsx(h.NiceIcon,{name:"box",size:14}),onClick:()=>r({workspaceId:i}),children:m("devStudio.preview.newModule","New module")}),(s==null?void 0:s.savePackage)&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"archive",size:14}),onClick:()=>l(i),children:m("devStudio.preview.newPackage","New package")})]}):void 0,children:[(c==null?void 0:c.description)&&t.jsx("p",{children:c.description}),t.jsx(ce,{items:[[m("devStudio.preview.packages","Packages"),String(((u=e.children)==null?void 0:u.length)??0)],[m("devStudio.preview.modules","Modules"),e.info]]}),t.jsx(je,{rows:e.children??[],onSelect:d})]})}function Tn({row:e,workspaceId:i,packageId:n,session:s,readOnly:o,canCreateModule:a,editButton:d,onSelect:r,onNewModule:l}){var y;const{t:m}=h.useNiceTranslation(),c=(y=s.packagesByWs[i])==null?void 0:y.find(f=>f.id===n),p=s.workspaces.find(f=>f.id===i),u=!o()&&!(p!=null&&p.readOnly);return t.jsxs(ne,{icon:e.icon,title:e.label,subtitle:n,actions:t.jsxs(t.Fragment,{children:[d,u&&a&&t.jsx(h.NiceButton,{size:"sm",variant:d?"ghost":"primary",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:()=>l({workspaceId:i,packageId:n}),children:m("devStudio.preview.newModuleHere","New module here")})]}),children:[(c==null?void 0:c.description)&&t.jsx("p",{children:c.description}),t.jsx(je,{rows:e.children??[],onSelect:r})]})}function En(e){var z;const{row:i,module:n,session:s,preset:o,provider:a,readOnly:d,editButton:r}=e,{t:l}=h.useNiceTranslation(),m=n.key,c=(z=s.modulesByWs[m.workspaceId])==null?void 0:z.find(O=>O.id===m.id),p=d(m),u=e.issues(m),y=(c==null?void 0:c.contents)==="manifest"&&t.jsx("span",{title:l("devStudio.preview.manifestOnly","This provider gives only the manifest"),children:"—"}),f=rt(n).length,v=n.documents.filter(O=>O.kind.editor==="views").reduce((O,M)=>O+de(n,M).length,0),S=new Set(n.documents.filter(O=>O.kind.editor==="i18n").flatMap(O=>Object.keys(ie(n,O)??{}))),g={key:m,files:n.working,documents:n.documents},b=o.newFile?o.kinds.filter(O=>O.editor!=="scriptList").map(O=>{var M;return{kind:O,file:(M=o.newFile)==null?void 0:M.call(o,O.id,g)}}).filter(O=>!!O.file&&!n.working.some(M=>M.path===O.file.path)):[],[I,_]=w.useState(!1),k=!p&&Xt(n,o),x=O=>t.jsx(h.NiceIcon,{name:O,size:14}),j=[...a!=null&&a.listRevisions?[{id:"history",icon:x("clock"),label:l("devStudio.overview.history","History"),onClick:()=>e.onEdit({kind:"history",module:m})}]:[],...e.canDuplicateModule&&!d()?[{id:"duplicate",icon:x("copy"),label:l("devStudio.explorer.duplicate","Duplicate"),onClick:()=>e.onModuleAction("duplicate",m)}]:[],...a!=null&&a.saveTemplate&&s.templates&&!d()?[{id:"addToTemplate",icon:x("layers"),label:l("devStudio.explorer.addToTemplate","Add to template"),onClick:()=>e.onModuleAction("addToTemplate",m)}]:[],...k?[{id:"addScript",icon:x("code"),label:l("devStudio.scripts.add","Add script"),onClick:()=>_(!0)}]:[],...p?[]:b.map(({kind:O,file:M})=>({id:`add:${O.id}`,icon:x(O.icon??"plus"),label:`${l("devStudio.preview.add","Add:")} ${O.labelKey?l(O.labelKey,O.label):O.label}`,onClick:()=>s.setRaw(m,M.path,M.text)})),...a!=null&&a.deleteModule&&!p?[{id:"sep",divider:!0},{id:"delete",icon:x("trash"),label:l("devStudio.delete","Delete"),danger:!0,onClick:()=>e.onModuleAction("delete",m)}]:[]],N=I&&t.jsx(Zt,{module:n,preset:o,onClose:()=>_(!1),onAdd:O=>{const M=Qt(n,o,s,O);M&&e.onEdit(M)}});return t.jsxs(t.Fragment,{children:[N,t.jsxs(ne,{icon:i.icon,title:i.label,subtitle:(c==null?void 0:c.location)??m.id,badges:t.jsxs(t.Fragment,{children:[(c==null?void 0:c.readOnly)&&t.jsx("span",{className:"nice-development-studio__tag",children:l("devStudio.explorer.readOnly","Read-only")}),(c==null?void 0:c.shadowedBy)&&t.jsx("span",{className:"nice-development-studio__tag",title:c.shadowedBy,children:l("devStudio.explorer.shadowed","shadowed")})]}),actions:t.jsxs(t.Fragment,{children:[r,n.dirty&&!p&&t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:x("save"),onClick:()=>e.onSave(m),"data-tour":"devstudio-save",children:l("devStudio.saveCount","Save ({count})").replace("{count}",String(n.changes.length))}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:x("undo"),onClick:()=>s.discard(m),children:l("devStudio.discard","Discard changes")})]}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:x("check"),onClick:()=>void s.validate(m),children:l("devStudio.validate","Validate")}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:x(u.length===0?"success":"warning"),onClick:()=>e.onEdit({kind:"problems",module:m}),children:`${l("devStudio.overview.problems","Problems")} (${u.length})`}),j.length>0&&t.jsx(h.NiceMenu,{className:"nice-development-studio__more",variant:"ghost",size:"sm",fullWidth:!0,items:[{id:"more",icon:x("more-horizontal"),label:l("devStudio.preview.more.actions","More actions"),children:j}]})]}),children:[(c==null?void 0:c.description)&&t.jsx("p",{children:c.description}),t.jsx(ce,{items:[["Id",m.id],[l("devStudio.preview.version","Version"),c==null?void 0:c.version],[l("devStudio.preview.entities","Entities"),y||String(f)],[l("devStudio.preview.views","Views"),y||String(v)],[l("devStudio.preview.languages","Languages"),y||[...S].join(", ")],[l("devStudio.preview.state","State"),n.dirty?l("devStudio.status.changed","{count} changed files").replace("{count}",String(n.changes.length)):void 0]]}),u.length>0&&t.jsxs("div",{className:"nice-development-studio__preview-issues",children:[t.jsx("ul",{className:"nice-development-studio__issues",children:u.slice(0,3).map((O,M)=>t.jsx("li",{className:`nice-development-studio__issue nice-development-studio__issue--${O.severity}`,children:t.jsxs("button",{type:"button",className:"nice-development-studio__issue-link",title:l("devStudio.problems.goTo","Go to"),onClick:()=>e.onReveal(Vt(n,O)),children:[t.jsx(h.NiceIcon,{name:O.severity==="error"?"error":O.severity==="warning"?"warning":"info",size:14}),t.jsx("span",{children:ei(l,O)})]})},M))}),u.length>3&&t.jsx("span",{className:"nice-development-studio__muted",children:l("devStudio.preview.more","…and {count} more").replace("{count}",String(u.length-3))})]})]})]})}function $n({row:e,module:i,group:n,preset:s,session:o,readOnly:a,onSelect:d,onEdit:r}){const{t:l}=h.useNiceTranslation(),[m,c]=w.useState(!1),p=a(i.key),u=n==="scripts"&&!p&&Xt(i,s),y=!p&&!u?Kn(n,i,s,o):void 0;return t.jsxs(ne,{icon:e.icon,title:e.label,actions:u?t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:()=>c(!0),"data-testid":"studio-add",children:l("devStudio.scripts.add","Add script")}):y?t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:()=>r(y.run()),"data-testid":"studio-add",children:y.label(l)}):void 0,children:[t.jsx(je,{rows:e.children??[],onSelect:d}),m&&t.jsx(Zt,{module:i,preset:s,onClose:()=>c(!1),onAdd:f=>{const v=Qt(i,s,o,f);v&&r(v)}})]})}function Kn(e,i,n,s){var c,p;if(e==="dataSources")return en(i,n)?{label:u=>u("devStudio.items.addDataSource","New data source"),run:()=>Jt(i,n,s,h.newModuleDataSource("query","source1"))??{kind:"manifest",module:i.key}}:void 0;const o=e==="entities"?"entities":e==="views"?"views":e==="workflows"?"workflows":e==="dataSources"?"dataSources":void 0,a=o?i.documents.find(u=>u.kind.editor===o&&u.model!==void 0):void 0;if(!a)return;const d=i.key;if(e==="entities"){const u=ie(i,a)??[],y=((c=n.entities)==null?void 0:c.nameKey)??"name",f=((p=n.entities)==null?void 0:p.fieldsKey)??"fields";return{label:v=>v("devStudio.preview.newEntity","New entity"),run:()=>(s.setDraft(d,a.key,[...u,{[y]:`Entity${u.length+1}`,[f]:[]}]),{kind:"entity",module:d,docKey:a.key,index:u.length})}}const r=de(i,a),l=r.length+1,m=e==="views"?{id:`view-${l}`,name:`View ${l}`,version:2,columns:12,rows:[],dataSources:[]}:{id:`workflow-${l}`,name:`Workflow ${l}`,entityType:"",version:1,states:[],transitions:[]};return{label:u=>e==="views"?u("devStudio.items.addView","New view"):u("devStudio.items.addWorkflow","New workflow"),run:()=>{const u={key:m.id,label:m.name,definition:m,source:m};return s.setDraft(d,a.key,[...r,u]),{kind:"item",module:d,group:e,docKey:a.key,itemKey:m.id}}}}const Mn=[["isPrimaryKey","PK","Primary key"],["isForeignKey","FK","Foreign key"],["isRequired","Req","Required"]];function Fn({row:e,module:i,docKey:n,index:s,preset:o,session:a,readOnly:d,editButton:r,onReveal:l}){var S;const{t:m}=h.useNiceTranslation(),c=fe(i,n),p=c?ie(i,c):void 0,u=Array.isArray(p)?p[s]:void 0;if(!c||!p||!u)return t.jsx(ne,{icon:"table",title:e.label,children:t.jsx("p",{className:"nice-development-studio__muted",children:m("devStudio.edit.gone","This is no longer in the module.")})});const y=((S=o.entities)==null?void 0:S.fieldsKey)??"fields",f=Array.isArray(u[y])?u[y]:[],v=d(i.key);return t.jsxs(ne,{icon:"table",title:ct(u)||e.label,subtitle:String(u.name??""),badges:t.jsxs(t.Fragment,{children:[!!u.isAudited&&t.jsx("span",{className:"nice-development-studio__tag",children:m("entityEditor.flag.audited.abbr","Audit")}),!!u.isSoftDeleteEnabled&&t.jsx("span",{className:"nice-development-studio__tag",children:m("entityEditor.flag.softDelete.abbr","Soft-del")})]}),actions:t.jsxs(t.Fragment,{children:[r,!v&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"trash",size:14}),onClick:()=>{a.setDraft(i.key,c.key,ut(p,s,null)),l({kind:"group",module:i.key,group:"entities"})},children:m("devStudio.delete","Delete")})]}),children:[typeof u.description=="string"&&u.description&&t.jsx("p",{children:u.description}),t.jsx(ce,{items:[[m("entityEditor.col.table","Table"),u.tableName],[m("entityEditor.col.fields","Fields"),String(f.length)]]}),f.length>0&&t.jsx("table",{className:"nice-development-studio__table nice-development-studio__preview-fields",children:t.jsx("tbody",{children:f.slice(0,8).map((g,b)=>t.jsxs("tr",{children:[t.jsx("td",{children:String(g.name??"")}),t.jsx("td",{className:"nice-development-studio__muted",children:String(g.dataType??g.type??"")}),t.jsx("td",{children:Mn.filter(([I])=>g[I]||I==="isRequired"&&g.required).map(([,I,_])=>t.jsx("span",{className:"nice-development-studio__tag",title:_,children:I},I))})]},b))})}),f.length>8&&t.jsx("span",{className:"nice-development-studio__muted",children:m("devStudio.preview.more","…and {count} more").replace("{count}",String(f.length-8))})]})}function On({row:e,module:i,node:n,advanced:s,renderViewPreview:o,editButton:a}){var f,v,S,g,b;const{t:d}=h.useNiceTranslation(),r=fe(i,n.docKey),l=n.docKey===Oe?lt(i).find(I=>I.key===n.itemKey):void 0,m=l?{key:l.key,label:l.label??l.key,definition:l,source:l}:r?de(i,r).find(I=>I.key===n.itemKey):void 0;if(!m)return t.jsx(ne,{icon:e.icon,title:e.label,children:t.jsx("p",{className:"nice-development-studio__muted",children:d("devStudio.edit.gone","This is no longer in the module.")})});const c=m.source??{},p=m.definition??{},u=n.group==="scripts"?m.definition:void 0,y=u?[[d("devStudio.scripts.name","Name"),u.name],[d("devStudio.scripts.kind","Kind"),ht(d,u.kind)],[d("devStudio.scripts.language","Language"),u.language],[d("devStudio.scripts.category","Category"),u.category],[d("devStudio.scripts.trigger","Runs on"),u.trigger],[d("devStudio.scripts.parameters","Parameters"),(f=u.parameters)==null?void 0:f.map(I=>I.name).join(", ")],[d("devStudio.scripts.returnType","Returns"),u.returnType],[d("devStudio.scripts.description","Description"),u.description]]:n.group==="views"?[["Id",m.key],[d("devStudio.preview.type","Type"),c.viewType??c.type??c.kind],[d("devStudio.preview.entity","Entity"),c.entityName??c.entity],[d("devStudio.preview.columns","Columns"),(v=Fe(c.columns))==null?void 0:v.toString()],[d("devStudio.preview.rows","Rows"),(S=Fe(p.rows))==null?void 0:S.toString()]]:n.group==="workflows"?[["Id",m.key],[d("devStudio.preview.states","States"),(g=Fe(p.states??c.states))==null?void 0:g.toString()],[d("devStudio.preview.transitions","Transitions"),(b=Fe(p.transitions??c.transitions))==null?void 0:b.toString()]]:[[d("devStudio.preview.key","Key"),m.key],[d("devStudio.preview.type","Type"),p.kind??void 0]];return t.jsxs(ne,{icon:e.icon,title:m.label||m.key,badges:m.definition===void 0?t.jsx("span",{className:"nice-development-studio__tag",children:d("devStudio.tree.noForm","no designer")}):void 0,actions:a,children:[t.jsx(ce,{items:y}),m.definition===void 0&&t.jsx("p",{className:"nice-development-studio__muted",children:s?d("devStudio.preview.noDesignerAdvanced","There is no designer for this kind of entry yet; edit its source."):d("devStudio.preview.noDesigner","There is no designer for this kind of entry yet.")}),n.group==="views"&&o&&t.jsx("div",{className:"nice-development-studio__preview-view",children:o({module:i.key,item:m,files:i.working})})]})}function zn({row:e,module:i,docKey:n,advanced:s,editButton:o}){var m;const{t:a}=h.useNiceTranslation(),d=fe(i,n);if(!d)return t.jsx(ne,{icon:e.icon,title:e.label,children:t.jsx("p",{className:"nice-development-studio__muted",children:a("devStudio.edit.gone","This is no longer in the module.")})});const r=ie(i,d);let l=null;if(d.model===void 0)l=t.jsxs("p",{className:"nice-development-studio__error",role:"alert",children:[s?a("devStudio.doc.unreadable","This file could not be read as its kind; edit its source."):a("devStudio.preview.unreadable","This file does not read; saving leaves it as it is. Fix it in the advanced mode.")," ",d.error]});else if(d.kind.editor==="i18n"){const c=r??{},p=Math.max(0,...Object.values(c).map(u=>Object.keys(u??{}).length));l=t.jsx(ce,{items:Object.entries(c).map(([u,y])=>{const f=Object.keys(y??{}).length;return[u,f<p?a("devStudio.preview.keysMissing","{count} keys, {missing} missing").replace("{count}",String(f)).replace("{missing}",String(p-f)):a("devStudio.preview.keys","{count} keys").replace("{count}",String(f))]})})}else if(d.kind.editor==="permissions"){const c=r??{permissions:[],groups:[]};l=t.jsx(ce,{items:[[a("devStudio.permissions.codes","Permissions"),String(c.permissions.length)],[a("devStudio.permissions.groups","Groups"),String(c.groups.length)]]})}else if(d.kind.editor==="seeds"){const c=r??{seeds:{}};l=t.jsx(ce,{items:Object.entries(c.seeds??{}).map(([p,u])=>[p,a("devStudio.preview.rowsCount","{count} rows").replace("{count}",String(u.length))])})}else d.kind.editor==="hooks"?l=t.jsx(ce,{items:[[a("devStudio.preview.bindings","Bindings"),(m=Fe(r))==null?void 0:m.toString()]]}):d.kind.editor==="script"&&(l=t.jsx(ce,{items:[[a("devStudio.preview.lines","Lines"),String(String(r??"").split(`
|
|
8
|
-
`).length)]]}));return t.jsx(ne,{icon:e.icon,title:e.label,subtitle:d.paths.join(", "),actions:o,children:l})}function Dn({tree:e,selected:i,expanded:n,onExpandedChange:s,onSelect:o,loadModule:a,newItems:d,actions:r,onRefresh:l,tutorialButton:m,emptyText:c,minWidth:p,contextMenuItems:u}){const{t:y}=h.useNiceTranslation(),f=w.useMemo(()=>[{field:"label",header:y("devStudio.explorer.name","Name"),render:(S,g)=>t.jsxs("span",{className:"nice-development-studio__tree-name",style:{maxWidth:`calc(100% - ${(g.depth??0)*20+28}px)`},children:[t.jsx(h.NiceIcon,{name:g.icon,size:14}),t.jsx("span",{className:`nice-development-studio__tree-label${g.missing?" nice-development-studio__missing":""}`,title:g.label,children:g.label}),g.dirty&&t.jsx("span",{className:"nice-development-studio__dot",title:y("devStudio.explorer.unsaved","Unsaved changes"),children:t.jsx(h.NiceIcon,{name:"circle",size:8})}),!!g.issues&&t.jsx("span",{className:"nice-development-studio__badge",title:y("devStudio.explorer.problems","Problems"),children:g.issues}),g.readOnly&&t.jsx("span",{title:y("devStudio.explorer.readOnly","Read-only"),children:t.jsx(h.NiceIcon,{name:"lock",size:12})}),g.noForm&&t.jsx("span",{className:"nice-development-studio__tag",children:y("devStudio.tree.noForm","no designer")}),g.shadowedBy&&t.jsx("span",{className:"nice-development-studio__tag",title:g.shadowedBy,children:y("devStudio.explorer.shadowed","shadowed")}),g.missing&&t.jsx("span",{className:"nice-development-studio__tag",children:y("devStudio.explorer.missing","missing")})]})},{field:"info",header:"",width:56,align:"right"}],[y]),v=t.jsxs("div",{className:"nice-development-studio__tree-actions",children:[d.length>0&&t.jsx(h.NiceMenu,{variant:"ghost",size:"sm",items:[{id:"new",label:y("devStudio.tree.new","New"),icon:t.jsx(h.NiceIcon,{name:"plus",size:14}),children:d}],"data-testid":"studio-new-menu"}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",ariaLabel:y("devStudio.refresh","Refresh"),onClick:l,children:t.jsx(h.NiceIcon,{name:"refresh",size:14})}),r==null?void 0:r.map(S=>t.jsx(h.NiceButton,{size:"sm",variant:"ghost",disabled:S.disabled,leftIcon:S.icon?t.jsx(h.NiceIcon,{name:S.icon,size:14}):void 0,onClick:S.onSelect,children:S.label},S.key)),m&&t.jsx("span",{className:"nice-development-studio__spacer"}),m]});return t.jsx("div",{className:"nice-development-studio__tree","data-tour":"devstudio-explorer",style:{minWidth:p},children:t.jsx(h.NiceTreeGrid,{data:e.rows,nested:!0,keyField:"id",childrenField:"children",columns:f,sortable:!1,compact:!0,searchable:!0,searchFields:["label","search"],searchPlaceholder:y("devStudio.tree.search","Search modules, entities and views"),toolbar:v,toolbarActions:["collapseAll"],expandedKeys:n,onExpandedChange:s,hasChildren:S=>S.node.kind==="module"&&!S.children,loadChildren:async S=>(S.node.kind==="module"&&await a(S.node.module),[]),onRowClick:o,contextMenuItems:u,rowClassName:S=>S.id===i?"nice-development-studio__tree-row--selected":void 0,emptyText:c,"aria-label":y("devStudio.explorer.modules","Modules"),"data-testid":"studio-tree"})})}const Pn=[{target:".nice-development-studio",titleKey:"tutorial.devStudio.intro.title",title:"Development studio",contentKey:"tutorial.devStudio.intro.content",content:"Design whole modules: their settings, entities, views, workflows, translations, permissions, data sources and seed data. Saving writes back only what changed.",placement:"auto"},{target:'[data-tour="devstudio-explorer"]',titleKey:"tutorial.devStudio.explorer.title",title:"Projects, packages and modules",contentKey:"tutorial.devStudio.explorer.content",content:"Browse projects, their packages and modules. Open a module to see its entities, views, translations and the rest; under Templates are the module sets installed together.",placement:"right"},{target:'[data-testid="studio-preview"]',titleKey:"tutorial.devStudio.preview.title",title:"A short preview",contentKey:"tutorial.devStudio.preview.content",content:"Pick a row in the tree to see a short preview of it here.",placement:"left"},{target:'[data-tour="devstudio-edit"]',titleKey:"tutorial.devStudio.edit.title",title:"Edit on the whole screen",contentKey:"tutorial.devStudio.edit.content",content:"Edit opens the form of what you picked on the whole studio. Back, or a step of the trail, brings you back to the tree.",placement:"bottom"},{target:'[data-tour="devstudio-save"]',titleKey:"tutorial.devStudio.save.title",title:"Validate and save",contentKey:"tutorial.devStudio.save.content",content:"Check the module, review the changed files and save them — only the bytes you changed are written.",placement:"bottom"}],Ln=["en","pl","de","fr","es","uk"],Rn=w.forwardRef(function(i,n){var St,kt;const{provider:s,preset:o,defaultModule:a,defaultExplorerTab:d="modules",displayMode:r="standard",actions:l,onModuleOpen:m,onSaved:c,onError:p,reviewBeforeSave:u=!0,scriptRunner:y,scriptIo:f,previewDataSource:v,renderViewPreview:S,modulePanels:g,readOnly:b=!1,height:I=720,explorerWidth:_=320,previewWidth:k=260,tutorial:x,className:j,style:N,id:z,testId:O,"data-testid":M}=i,{t:D}=h.useNiceTranslation(),te=w.useRef(null);w.useImperativeHandle(n,()=>te.current);const J=r==="advanced",Y=w.useMemo(()=>typeof o=="function"?o(D):o??$.nativeStudioPreset,[o,D]),L=w.useMemo(()=>Y.locales??Ln,[Y]),E=Li(s,Y,{locales:L,onError:p,t:D}),{openModule:A}=E,[Q,G]=w.useState(""),[U,ee]=w.useState([]),[Z,le]=w.useState(null),[we,F]=w.useState(null),[T,K]=w.useState(null),R=w.useCallback(C=>{var P;return(P=E.modulesByWs[C.workspaceId])==null?void 0:P.find(q=>q.id===C.id)},[E.modulesByWs]),B=C=>{var P;return((P=R(C))==null?void 0:P.label)??C.id},W=w.useMemo(()=>{const C={};for(const[P,q]of Object.entries(E.modules))C[P]=[...zt(q,Y),...E.serverIssues[P]??[]];return C},[E.modules,E.serverIssues,Y]),X=w.useCallback(C=>W[H(C)]??[],[W]),V=w.useMemo(()=>Object.fromEntries(Object.entries(W).map(([C,P])=>[C,P.filter(q=>q.severity==="error").length])),[W]),se=w.useCallback(C=>{var q;if(b)return!0;if(!C)return!1;const P=E.workspaces.find(Se=>Se.id===C.workspaceId);return!!(P!=null&&P.readOnly)||!!((q=R(C))!=null&&q.readOnly)},[b,E.workspaces,R]),_e=_n(E,se),oe=w.useMemo(()=>Yi({workspaces:E.workspaces,modulesByWs:E.modulesByWs,packagesByWs:E.packagesByWs,templates:E.templates,modules:E.modules,issueCounts:V,panels:g?C=>g({module:C.key,files:C.working,dirty:C.dirty}):void 0,advanced:J,groups:Y.groups,t:D}),[Y.groups,E.workspaces,E.modulesByWs,E.packagesByWs,E.templates,E.modules,V,g,J,D]),ae=w.useRef(!1);w.useEffect(()=>{if(!ae.current&&E.workspaces.length>0){ae.current=!0;const C=E.workspaces.map(P=>`w:${P.id}`);d==="templates"&&(C.push(Re),G(Re)),ee(P=>[...new Set([...P,...C])])}},[E.workspaces,d]);const me=w.useCallback(C=>{const P=It(oe,C).map(q=>q.id);ee(q=>[...new Set([...q,...P])]),G(C)},[oe]),ue=w.useCallback(C=>{le(null);const P=Me(C);P&&!E.modules[H(P)]&&A(P),F(C)},[E.modules,A]);w.useEffect(()=>{if(!we)return;const C=et(oe,we);if(C){me(C),F(null);return}const P=Me(we);if(P&&E.modules[H(P)]){const q=et(oe,{kind:"module",module:P});q&&me(q),F(null)}},[we,oe,me,E.modules]);const Ee=w.useCallback(C=>{G(C.id);const P=Me(C.node);P&&!E.modules[H(P)]&&A(P),C.node.kind==="module"&&(m==null||m(C.node.module))},[E.modules,A,m]),ti=w.useCallback(C=>{const P=oe.byId.get(C);P&&(Ee(P),me(C))},[oe,Ee,me]),vt=w.useRef(!1);w.useEffect(()=>{a&&!vt.current&&E.modulesByWs[a.workspaceId]&&(vt.current=!0,A(a).then(()=>m==null?void 0:m(a)),F({kind:"module",module:a}))},[a,E.modulesByWs,A,m]);const Ie=oe.byId.get(Q),pe=Z?"module"in Z?Z.module:void 0:Ie?Me(Ie.node):void 0,qe=w.useCallback(async C=>{const P=E.modules[H(C)];if(!(P!=null&&P.dirty)||se(C))return;if(u){K({kind:"review",module:C});return}const q=await E.save(C);q&&!q.ok?K({kind:"review",module:C,conflict:q}):q!=null&&q.ok&&(c==null||c(C,q))},[E,se,u,c]),ft=w.useRef(()=>{});ft.current=()=>{pe&&qe(pe)},w.useEffect(()=>{const C=te.current;if(!C)return;const P=q=>{(q.ctrlKey||q.metaKey)&&!q.altKey&&q.key.toLowerCase()==="s"&&(q.preventDefault(),ft.current())};return C.addEventListener("keydown",P),()=>C.removeEventListener("keydown",P)},[]);const ii=()=>{const C=Z?Ct(Z):void 0;C?ue(C):le(null)},ni=w.useMemo(()=>{if(!Z)return[];const C=Ct(Z),P=C?et(oe,C):void 0,q=P?It(oe,P):[],Se=Z.kind==="manifest"?D("devStudio.edit.settings","Settings"):Z.kind==="problems"?D("devStudio.overview.problems","Problems"):Z.kind==="history"?D("devStudio.overview.history","History"):Z.kind==="template"&&!Z.templateId?D("devStudio.template.new","New template"):void 0,ke=q.map(bt=>({label:bt.label,onClick:()=>{le(null),me(bt.id)}}));return Se?ke.push({label:Se}):ke.length>0&&(ke[ke.length-1]={label:ke[ke.length-1].label}),ke},[Z,oe,me,D]),gt=!!(s!=null&&s.createModule)&&!!Y.generateModule,si=!!(s!=null&&s.createModule)&&!!Y.duplicateModule,$e=E.workspaces.filter(C=>!C.readOnly).map(C=>({id:C.id,label:C.label})),re=Ie==null?void 0:Ie.node,We=re&&"workspaceId"in re?re.workspaceId:re&&"module"in re?re.module.workspaceId:void 0,oi=(re==null?void 0:re.kind)==="package"?re.packageId:re&&"module"in re?(St=R(re.module))==null?void 0:St.packageId:void 0,Ke=$e.some(C=>C.id===We)?We:(kt=$e[0])==null?void 0:kt.id,ai=b?[]:[...gt&&Ke?[{id:"module",label:D("devStudio.tree.newModule","Module…"),icon:t.jsx(h.NiceIcon,{name:"box",size:14}),onClick:()=>K({kind:"wizard",prefill:{workspaceId:Ke,packageId:Ke===We?oi:void 0}})}]:[],...s!=null&&s.savePackage&&Ke?[{id:"package",label:D("devStudio.tree.newPackage","Package…"),icon:t.jsx(h.NiceIcon,{name:"archive",size:14}),onClick:()=>K({kind:"package",workspaceId:Ke})}]:[],...s!=null&&s.saveTemplate&&E.templates?[{id:"template",label:D("devStudio.tree.newTemplate","Template"),icon:t.jsx(h.NiceIcon,{name:"layers",size:14}),onClick:()=>le({kind:"template",templateId:null})}]:[]],di=(C,P)=>{K(C==="delete"?{kind:"delete",module:P}:C==="duplicate"?{kind:"duplicate",module:P}:{kind:"templates",module:P})},yt=x?t.jsx(h.NiceTutorialButton,{steps:h.resolveTutorial(x,Pn)}):void 0,ze=pe?E.modules[H(pe)]:void 0,Ve=pe?X(pe):[],Je=E.logs[E.logs.length-1],ri=t.jsxs("div",{className:"nice-development-studio__statusbar",role:"status",children:[pe&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:B(pe)}),t.jsx("span",{children:ze!=null&&ze.dirty?D("devStudio.status.changed","{count} changed files").replace("{count}",String(ze.changes.length)):D("devStudio.status.saved","Saved")}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:Ve.length===0?"check":"warning",size:12}),onClick:()=>le({kind:"problems",module:pe}),children:Ve.length===0?D("devStudio.status.valid","No problems"):D("devStudio.status.problems","{count} problems").replace("{count}",String(Ve.length))})]}),t.jsx("span",{className:"nice-development-studio__spacer"}),E.busy?t.jsx("span",{children:D("devStudio.loading","Loading…")}):Je&&t.jsx("span",{className:`nice-development-studio__status-message nice-development-studio__status-message--${Je.level}`,children:Je.message})]}),Ue=(T==null?void 0:T.kind)==="review"?E.modules[H(T.module)]:void 0,ci=`nice-development-studio${j?` ${j}`:""}`,li=s?D("devStudio.preview.empty","Pick a module, an entity or a view in the tree."):D("devStudio.noProvider","Connect a provider to browse modules.");return t.jsxs("div",{ref:te,id:z,className:ci,style:{height:I,...N},"data-testid":M??O,children:[t.jsx(h.NiceAppShell,{className:"nice-development-studio__shell",height:"100%",rightSidebar:Z?void 0:t.jsx(In,{row:Ie,tree:oe,session:E,preset:Y,provider:s,readOnly:se,advanced:J,issues:X,canCreateModule:gt,canDuplicateModule:si,renderViewPreview:S,emptyText:li,onSelect:ti,onEdit:le,onReveal:ue,onSave:C=>void qe(C),onNewModule:C=>K({kind:"wizard",prefill:C}),onNewPackage:C=>K({kind:"package",workspaceId:C}),onNewTemplate:()=>le({kind:"template",templateId:null}),onModuleAction:di}),rightSidebarWidth:k,statusBar:ri,bottomPanel:J?t.jsx("div",{"data-tour":"devstudio-output",className:"nice-development-studio__output",children:t.jsx(h.NiceLogConsole,{title:D("devStudio.output","Output"),entries:E.logs,onClear:E.clearLogs,maxHeight:"100%"})}):void 0,bottomPanelHeight:J?140:void 0,children:Z?t.jsx(yn,{screen:Z,crumbs:ni,session:E,preset:Y,provider:s,locales:L,readOnly:se,advanced:J,issues:X,scriptRunner:y,scriptIo:f,previewDataSource:v,renderViewPreview:S,modulePanels:g,tutorialButton:yt,onBack:ii,onSave:C=>void qe(C),onReveal:ue,onScreen:le,onNewModule:C=>K({kind:"wizard",prefill:C})}):t.jsx(Dn,{tree:oe,selected:Q,expanded:U,onExpandedChange:ee,onSelect:Ee,loadModule:async C=>{await A(C)},newItems:ai,actions:l,onRefresh:()=>void E.refresh(),tutorialButton:yt,minWidth:_,contextMenuItems:_e.menuFor,emptyText:s?D("devStudio.explorer.empty","No modules."):D("devStudio.noProvider","Connect a provider to browse modules.")})}),(T==null?void 0:T.kind)==="wizard"&&t.jsx(Fi,{open:!0,onClose:()=>K(null),session:E,preset:Y,locales:L,prefill:T.prefill,onCreated:C=>{m==null||m(C),ue({kind:"module",module:C})}}),(T==null?void 0:T.kind)==="review"&&Ue&&t.jsx(Oi,{open:!0,moduleLabel:B(T.module),changes:Ue.changes,original:C=>{var P;return((P=Ue.files.find(q=>q.path===C))==null?void 0:P.text)??""},conflict:T.conflict,onClose:()=>K(null),onSave:async()=>{const C=await E.save(T.module);C!=null&&C.ok?(K(null),c==null||c(T.module,C)):C&&K({...T,conflict:C})},onOverwrite:async()=>{const C=await E.save(T.module,{force:!0});C!=null&&C.ok&&(K(null),c==null||c(T.module,C))},onReload:async()=>{await E.reload(T.module),K(null)}}),(T==null?void 0:T.kind)==="delete"&&t.jsx(h.NiceConfirmDialog,{visible:!0,variant:"warning",header:D("devStudio.delete.title","Delete module"),message:D("devStudio.delete.message","Delete {module} and all its files?").replace("{module}",B(T.module)),acceptLabel:D("devStudio.delete","Delete"),rejectLabel:D("devStudio.cancel","Cancel"),onReject:()=>K(null),onAccept:async()=>{const C=T.module;K(null),await E.deleteModule(C)&&(le(null),G(`w:${C.workspaceId}`))}}),_e.dialog,(T==null?void 0:T.kind)==="duplicate"&&t.jsx(wt,{open:!0,title:D("devStudio.duplicate.title","Duplicate {module}").replace("{module}",B(T.module)),workspaces:$e,workspaceId:$e.some(C=>C.id===T.module.workspaceId)?T.module.workspaceId:void 0,idLabel:D("devStudio.duplicate.id","New module id"),initialId:`${T.module.id}Copy`,onClose:()=>K(null),onSubmit:async C=>{var Se;const P=T.module;K(null);const q=await E.duplicateModule(P,{workspaceId:C.workspaceId,id:C.id,packageId:(Se=R(P))==null?void 0:Se.packageId});q&&ue({kind:"module",module:{workspaceId:q.workspaceId,id:q.id}})}}),(T==null?void 0:T.kind)==="package"&&t.jsx(wt,{open:!0,title:D("devStudio.package.new","New package"),workspaces:$e,workspaceId:T.workspaceId,idLabel:D("devStudio.package.id","Id"),withLabel:!0,onClose:()=>K(null),onSubmit:async C=>{K(null);const P=await E.savePackage({id:C.id,workspaceId:C.workspaceId,label:C.label});P&&ue({kind:"package",workspaceId:P.workspaceId,packageId:P.id})}}),(T==null?void 0:T.kind)==="templates"&&E.templates&&t.jsx(zi,{open:!0,moduleId:T.module.id,templates:E.templates,onClose:()=>K(null),onApply:async C=>{K(null);for(const P of C)await E.saveTemplate(P,P.id)}})]})});exports.NICE_STUDIO_SCRIPT_KINDS=$.NICE_STUDIO_SCRIPT_KINDS;exports.NICE_STUDIO_SCRIPT_PHASES=$.NICE_STUDIO_SCRIPT_PHASES;exports.addStudioFolder=$.addStudioFolder;exports.addStudioSection=$.addStudioSection;exports.arrayFileKind=$.arrayFileKind;exports.buildDocuments=$.buildDocuments;exports.createMemoryStudioProvider=$.createMemoryStudioProvider;exports.defineManifestSection=$.defineManifestSection;exports.deriveDefaultRbac=$.deriveDefaultRbac;exports.detectJsonTextFormat=$.detectJsonTextFormat;exports.emptyStudioLayout=$.emptyStudioLayout;exports.encodeDocument=$.encodeDocument;exports.endsWithAny=$.endsWithAny;exports.entitiesToSchemas=$.entitiesToSchemas;exports.fileName=$.fileName;exports.fitManifestSection=$.fitManifestSection;exports.fromStudioScriptItem=$.fromStudioScriptItem;exports.i18nFileKind=$.i18nFileKind;exports.inferStudioScriptKind=$.inferStudioScriptKind;exports.isEmptyStudioLayout=$.isEmptyStudioLayout;exports.isStudioLayoutPath=$.isStudioLayoutPath;exports.itemsFileKind=$.itemsFileKind;exports.jsonFallbackKind=$.jsonFallbackKind;exports.jsonFileKind=$.jsonFileKind;exports.jsonValueFitsSchema=$.jsonValueFitsSchema;exports.jsonValuesEqual=$.jsonValuesEqual;exports.keepTextFormat=$.keepTextFormat;exports.manifestSectionKeys=$.manifestSectionKeys;exports.modulePrefix=$.modulePrefix;exports.nativeDataSourcesKind=$.nativeDataSourcesKind;exports.nativeEntitiesKind=$.nativeEntitiesKind;exports.nativeFileKinds=$.nativeFileKinds;exports.nativeHooksKind=$.nativeHooksKind;exports.nativeI18nKind=$.nativeI18nKind;exports.nativeManifestKind=$.nativeManifestKind;exports.nativeRbacKind=$.nativeRbacKind;exports.nativeScriptsKind=$.nativeScriptsKind;exports.nativeStudioPreset=$.nativeStudioPreset;exports.nativeViewsKind=$.nativeViewsKind;exports.nativeWorkflowsKind=$.nativeWorkflowsKind;exports.newStudioScript=$.newStudioScript;exports.objectFileKind=$.objectFileKind;exports.parseJsonText=$.parseJsonText;exports.parseStudioLayout=$.parseStudioLayout;exports.patchJsonText=$.patchJsonText;exports.patchJsonTextDetailed=$.patchJsonTextDetailed;exports.placeStudioEntry=$.placeStudioEntry;exports.readTranslations=$.readTranslations;exports.removeStudioLayoutNode=$.removeStudioLayoutNode;exports.renameStudioEntryRef=$.renameStudioEntryRef;exports.renameStudioLayoutNode=$.renameStudioLayoutNode;exports.resolveFileKind=$.resolveFileKind;exports.safeJson=$.safeJson;exports.scriptsFileKind=$.scriptsFileKind;exports.serializeStudioLayout=$.serializeStudioLayout;exports.slugifyModuleId=$.slugifyModuleId;exports.stringifyJsonText=$.stringifyJsonText;exports.studioEntryRef=$.studioEntryRef;exports.studioLayoutPath=$.studioLayoutPath;exports.studioScriptIdentifier=$.studioScriptIdentifier;exports.studioScriptLanguages=$.studioScriptLanguages;exports.textFallbackKind=$.textFallbackKind;exports.toStudioScriptItem=$.toStudioScriptItem;exports.writeTranslations=$.writeTranslations;exports.NiceArrayField=ot;exports.NiceDevelopmentStudio=Rn;exports.NiceEntityEditor=Ft;exports.NiceEntityForm=at;exports.NiceI18nEditor=pt;exports.NiceSchemaForm=Te;exports.aiFormConfigToFormFields=fi;exports.aiFormFieldType=$t;exports.formBuilderSchemaToNiceFormItems=mi;exports.formFieldsToFormItems=nt;exports.formSchemaToJsonSchema=ki;exports.jsonSchemaToFormItems=it;exports.schemaToFormItems=pi;exports.validateAgainstJsonSchema=st;exports.validateFormSchema=hi;
|
|
5
|
+
`]},d))})}function zi({open:e,onClose:i,session:n,preset:s,locales:o,prefill:a,onCreated:d}){var I,w,k,x;const{t:r}=h.useNiceTranslation(),u=n.workspaces.filter(j=>!j.readOnly),m=s.requiredLocales??[],[c,p]=_.useState(()=>{var j;return{workspaceId:a.workspaceId&&u.some(N=>N.id===a.workspaceId)?a.workspaceId:((j=u[0])==null?void 0:j.id)??"",packageId:a.packageId,name:"",entities:[{name:"Item",fields:[{name:"Id",dataType:"Guid",isPrimaryKey:!0,isRequired:!0},{name:"Name",dataType:"string",isRequired:!0,maxLength:200}]}],locales:[...new Set([...m,...o.slice(0,2)])],views:!0,permissions:!0}}),[l,g]=_.useState(null),[f,v]=_.useState(!1),S=_.useMemo(()=>[...new Set((n.modulesByWs[c.workspaceId]??[]).map(j=>j.packageId).filter(Boolean))].sort(),[n.modulesByWs,c.workspaceId]);if(!e)return null;const y=new Set(Object.values(n.modulesByWs).flatMap(j=>j.map(N=>N.id))),b=async()=>{s.generateModule&&c.name.trim()&&g(await s.generateModule({...c,name:c.name.trim()},{existingIds:y}))};return t.jsx(h.NiceModal,{open:e,onClose:i,title:r("devStudio.wizard.title","New module"),size:"xl","data-testid":"studio-module-wizard",children:t.jsx(h.NiceWizard,{finishLabel:r("devStudio.wizard.create","Create module"),onCancel:i,onStepChange:j=>{j===3&&b()},onComplete:async()=>{if(f)return;v(!0);const j=await n.createModule({...c,name:c.name.trim()});v(!1),j&&(d({workspaceId:j.workspaceId,id:j.id}),i())},steps:[{id:"identity",title:r("devStudio.wizard.identity","Name and place"),validate:()=>c.name.trim()&&c.workspaceId?!0:r("devStudio.wizard.needName","Give the module a name."),content:t.jsxs("div",{className:"nice-development-studio__form",children:[t.jsx(h.NiceSelect,{label:r("devStudio.wizard.workspace","Project"),value:c.workspaceId,options:u.map(j=>({value:j.id,label:j.label})),onChange:j=>p({...c,workspaceId:String(j)})}),t.jsx(h.NiceTextInput,{label:r("devStudio.wizard.package","Package"),value:c.packageId??"",placeholder:S.join(", "),onChange:j=>p({...c,packageId:j||void 0})}),t.jsx(h.NiceTextInput,{label:r("devStudio.wizard.name","Name"),value:c.name,placeholder:r("devStudio.wizard.namePlaceholder","e.g. Bike rental"),onChange:j=>p({...c,name:j})}),t.jsx(h.NiceTextInput,{label:r("devStudio.wizard.description","Description"),value:c.description??"",onChange:j=>p({...c,description:j||void 0})})]})},{id:"entities",title:r("devStudio.wizard.entities","Entities"),content:t.jsx(zt,{value:c.entities,onChange:j=>p({...c,entities:j}),entityMetaSchema:(I=s.entities)==null?void 0:I.entityMetaSchema,fieldSchema:(w=s.entities)==null?void 0:w.fieldSchema,fieldsKey:(k=s.entities)==null?void 0:k.fieldsKey,nameKey:(x=s.entities)==null?void 0:x.nameKey})},{id:"options",title:r("devStudio.wizard.options","Options"),content:t.jsxs("div",{className:"nice-development-studio__form",children:[t.jsxs("fieldset",{className:"nice-development-studio__fieldset",children:[t.jsx("legend",{children:r("devStudio.wizard.locales","Languages")}),[...new Set([...m,...o])].map(j=>t.jsx(h.NiceCheckbox,{label:j,checked:c.locales.includes(j),disabled:m.includes(j),onChange:N=>p({...c,locales:N?[...c.locales,j]:c.locales.filter(P=>P!==j)})},j))]}),t.jsx(h.NiceCheckbox,{label:r("devStudio.wizard.views","A list and a form view per entity"),checked:!!c.views,onChange:j=>p({...c,views:j})}),t.jsx(h.NiceCheckbox,{label:r("devStudio.wizard.permissions","Viewer, editor and admin permissions"),checked:!!c.permissions,onChange:j=>p({...c,permissions:j})})]})},{id:"review",title:r("devStudio.wizard.review","Review"),content:l?t.jsxs("div",{children:[t.jsx("p",{children:r("devStudio.wizard.willCreate","Module {id} with these files:").replace("{id}",l.id)}),t.jsx("ul",{className:"nice-development-studio__list",children:l.files.map(j=>t.jsxs("li",{children:[t.jsx(h.NiceIcon,{name:"file",size:12})," ",j.path]},j.path))})]}):t.jsx("p",{className:"nice-development-studio__muted",children:r("devStudio.wizard.generating","Generating…")})}]})})}function Di({open:e,moduleLabel:i,changes:n,original:s,conflict:o,onSave:a,onOverwrite:d,onReload:r,onClose:u}){const{t:m}=h.useNiceTranslation();return e?t.jsxs(h.NiceModal,{open:e,onClose:u,size:"xl",title:m("devStudio.review.title","Save {module}").replace("{module}",i),"data-testid":"studio-review",footer:o?t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{variant:"ghost",onClick:u,children:m("devStudio.cancel","Cancel")}),t.jsx(h.NiceButton,{variant:"secondary",onClick:r,children:m("devStudio.review.reload","Reload theirs (drop mine)")}),t.jsx(h.NiceButton,{variant:"danger",onClick:d,children:m("devStudio.review.overwrite","Overwrite with mine")})]}):t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{variant:"ghost",onClick:u,children:m("devStudio.cancel","Cancel")}),t.jsx(h.NiceButton,{variant:"primary",onClick:a,children:m("devStudio.review.save","Save {count} files").replace("{count}",String(n.length))})]}),children:[o&&t.jsxs("p",{className:"nice-development-studio__error",role:"alert",children:[m("devStudio.review.conflict","These files changed since you opened them:")," ",o.conflicts.map(c=>c.path).join(", ")]}),n.map(c=>t.jsxs("section",{className:"nice-development-studio__source",children:[t.jsx("h4",{className:"nice-development-studio__source-title",children:c.type==="delete"?m("devStudio.change.delete","Delete {path}").replace("{path}",c.path):c.baseVersion===void 0&&!s(c.path)?m("devStudio.change.new","New file {path}").replace("{path}",c.path):c.path}),t.jsx(Dt,{before:s(c.path),after:c.type==="write"?c.text:""})]},c.path))]}):null}function Pi({open:e,moduleId:i,templates:n,onApply:s,onClose:o}){const{t:a}=h.useNiceTranslation(),d=_.useMemo(()=>n.filter(p=>p.modules.some(l=>l.moduleId===i)).map(p=>p.id),[n,i]),[r,u]=_.useState(d);if(!e)return null;const m=n.map(p=>{var l,g;return{id:p.id,label:((l=p.translations.en)==null?void 0:l.name)??((g=Object.values(p.translations)[0])==null?void 0:g.name)??p.id}}),c=[{field:"label",header:a("devStudio.explorer.name","Name")}];return t.jsx(h.NiceModal,{open:e,onClose:o,title:a("devStudio.picker.title","Templates with {module}").replace("{module}",i),"data-testid":"studio-template-picker",footer:t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{variant:"ghost",onClick:o,children:a("devStudio.cancel","Cancel")}),t.jsx(h.NiceButton,{variant:"primary",onClick:()=>{const p=n.filter(l=>r.includes(l.id)!==d.includes(l.id)).map(l=>({...l,modules:r.includes(l.id)?[...l.modules,{moduleId:i}]:l.modules.filter(g=>g.moduleId!==i)}));s(p)},children:a("devStudio.apply","Apply")})]}),children:t.jsx(h.NiceTreeGrid,{data:m,columns:c,keyField:"id",sortable:!1,compact:!0,checkable:!0,checkedKeys:r,onCheckedChange:u,searchable:!0,"aria-label":a("devStudio.explorer.templates","Templates")})})}function It({open:e,title:i,workspaces:n,workspaceId:s,idLabel:o,initialId:a="",withLabel:d,onSubmit:r,onClose:u}){var S;const{t:m}=h.useNiceTranslation(),[c,p]=_.useState(s??((S=n[0])==null?void 0:S.id)??""),[l,g]=_.useState(a),[f,v]=_.useState("");return e?t.jsx(h.NiceModal,{open:e,onClose:u,title:i,footer:t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{variant:"ghost",onClick:u,children:m("devStudio.cancel","Cancel")}),t.jsx(h.NiceButton,{variant:"primary",disabled:!l.trim()||!c,onClick:()=>r({workspaceId:c,id:l.trim(),label:f.trim()||l.trim()}),children:m("devStudio.ok","OK")})]}),children:t.jsxs("div",{className:"nice-development-studio__form",children:[t.jsx(h.NiceSelect,{label:m("devStudio.wizard.workspace","Project"),value:c,options:n.map(y=>({value:y.id,label:y.label})),onChange:y=>p(String(y))}),t.jsx(h.NiceTextInput,{label:o,value:l,onChange:g}),d&&t.jsx(h.NiceTextInput,{label:m("devStudio.package.label","Name"),value:f,onChange:v})]})}):null}const Ct=e=>JSON.stringify(e??null,null,2);function Re({value:e,onChange:i,readOnly:n,height:s=320,label:o}){const{t:a}=h.useNiceTranslation(),[d,r]=_.useState(()=>Ct(e)),[u,m]=_.useState(null),c=_.useRef(e);return _.useEffect(()=>{c.current!==e&&(c.current=e,r(Ct(e)),m(null))},[e]),t.jsxs("div",{className:"nice-development-studio__json",role:"group","aria-label":o,children:[t.jsx(h.NiceSimpleCodeEditor,{value:d,language:"json",height:s,readOnly:n,lineNumbers:!0,onChange:p=>{r(p);try{const l=JSON.parse(p);m(null),c.current=l,i==null||i(l)}catch(l){m(l instanceof Error?l.message:String(l))}}}),u&&t.jsxs("p",{className:"nice-development-studio__error",role:"alert",children:[a("devStudio.json.invalid","Not valid JSON:")," ",u]})]})}const Y=e=>`${e.workspaceId}/${e.id}`;function et(e,i,n){const s=new Set(e.deleted),o=new Map;for(const l of e.files)s.has(l.path)||o.set(l.path,e.raw[l.path]!==void 0?{...l,text:e.raw[l.path]}:l);for(const[l,g]of Object.entries(e.raw))!o.has(l)&&!s.has(l)&&o.set(l,{path:l,text:g});const a=[...o.values()],d={moduleId:e.key.id,files:a,locales:n},r=T.buildDocuments(i.kinds,a,d),u=new Map(a.map(l=>[l.path,l.text])),m={};for(const l of r)if(l.key in e.drafts)try{const g=l.kind.encode(e.drafts[l.key],a.filter(f=>l.paths.includes(f.path)),d);for(const f of g.files)u.set(f.path,f.text),s.delete(f.path);for(const f of g.deleted??[])u.delete(f),s.add(f)}catch(g){m[l.key]=g instanceof Error?g.message:String(g)}const c=new Map(e.files.map(l=>[l.path,l])),p=[];for(const[l,g]of u){const f=c.get(l);(!f||f.text!==g)&&p.push({type:"write",path:l,text:g,baseVersion:f==null?void 0:f.version})}for(const l of s){const g=c.get(l);g&&p.push({type:"delete",path:l,baseVersion:g.version})}return{...e,working:a,documents:r,changes:p,pending:u,encodeErrors:m,dirty:p.length>0}}function Pt(e,i){const n=[];for(const s of e.documents){if(s.error&&n.push({severity:"error",code:"file.unreadable",message:`${s.paths[0]} cannot be read: ${s.error}`,messageKey:"devStudio.issue.unreadable",params:{path:s.paths[0]},moduleId:e.key.id,path:s.paths[0]}),s.kind.editor!=="manifest"||!i.manifestSections)continue;const o=e.drafts[s.key]??s.model??{};for(const a of i.manifestSections){const{section:d}=T.fitManifestSection(a,o);if(d.schema)for(const r of at(o,d.schema))n.push({severity:"error",code:"manifest.schema",message:`${d.title}: ${r.field} — ${r.message}`,moduleId:e.key.id,path:s.paths[0],pointer:`/${r.field.replace(/\./g,"/")}`})}}for(const[s,o]of Object.entries(e.encodeErrors))n.push({severity:"error",code:"document.encode",message:`${s}: ${o}`,moduleId:e.key.id});if(i.validateModule){const s=[...e.pending.entries()].map(([o,a])=>({path:o,text:a}));n.push(...i.validateModule({key:e.key,files:s,documents:e.documents,contents:e.contents}).map(o=>({...o,moduleId:o.moduleId??e.key.id})))}return n}const Li=(e,i={})=>Object.entries(i).reduce((n,[s,o])=>n.split(`{${s}}`).join(String(o)),e),Ri=e=>e instanceof Error?e.message:String(e);function Bi(e,i,n){const[s,o]=_.useState([]),[a,d]=_.useState({}),r=_.useRef(a);r.current=a;const[u,m]=_.useState({}),[c,p]=_.useState(null),[l,g]=_.useState({}),[f,v]=_.useState({}),[S,y]=_.useState(0),[b,I]=_.useState([]),w=_.useRef({provider:e,preset:i,options:n});w.current={provider:e,preset:i,options:n};const k=_.useCallback(($,O,z)=>{var E,D;return Li(((D=(E=w.current.options).t)==null?void 0:D.call(E,$,O))??O,z)},[]),x=_.useCallback(($,O,z)=>{I(E=>[...E,{level:$,message:O,data:z,timestamp:Date.now()}].slice(-300))},[]),j=_.useCallback(async($,O)=>{var z,E;y(D=>D+1);try{return await O()}catch(D){x("error",`${$}: ${Ri(D)}`),(E=(z=w.current.options).onError)==null||E.call(z,D,$);return}finally{y(D=>D-1)}},[x]),N=_.useCallback(async()=>{const $=w.current.provider;$&&await j(k("devStudio.log.list","List"),async()=>{const O=await $.listWorkspaces();o(O);const z=await Promise.all(O.map(async E=>{const[D,J]=await Promise.all([$.listModules(E.id),$.listPackages?$.listPackages(E.id):Promise.resolve(void 0)]);return[E.id,D,J]}));d(Object.fromEntries(z.map(([E,D])=>[E,D]))),m(Object.fromEntries(z.filter(([,,E])=>E).map(([E,,D])=>[E,D]))),p($.listTemplates?await $.listTemplates():null)})},[j,k]);_.useEffect(()=>{N()},[e,N]);const P=_.useMemo(()=>{const $={};for(const[O,z]of Object.entries(l))$[O]=et(z,i,n.locales);return $},[l,i,n.locales]),F=_.useCallback(async $=>{var Q,V;const O=Y($),z=w.current.provider;if(!z)return;const E=await j(k("devStudio.log.open","Open {id}",{id:$.id}),()=>z.readModule($));if(!E)return;const D=(V=(Q=r.current[$.workspaceId])==null?void 0:Q.find(oe=>oe.id===$.id))==null?void 0:V.contents,J={key:$,files:E,raw:{},deleted:[],drafts:{},contents:D};return g(oe=>oe[O]?oe:{...oe,[O]:J}),x("info",k("devStudio.log.opened","Opened {id} ({count} files)",{id:$.id,count:E.length})),et(J,w.current.preset,w.current.options.locales)},[j,x,k]),K=_.useCallback(($,O)=>{const z=Y($);g(E=>E[z]?{...E,[z]:O(E[z])}:E)},[]),G=_.useCallback(($,O,z)=>K($,E=>({...E,drafts:{...E.drafts,[O]:z}})),[K]),ee=_.useCallback(($,O,z,E=[])=>K($,D=>{const J={...D.raw};z===null?delete J[O]:J[O]=z;const Q={...D.drafts};for(const V of E)delete Q[V];return{...D,raw:J,drafts:Q,deleted:D.deleted.filter(V=>V!==O)}}),[K]),B=_.useCallback(($,O)=>K($,z=>{const E={...z.raw};delete E[O];const D=!z.files.some(J=>J.path===O);return{...z,raw:E,deleted:D?z.deleted:[...new Set([...z.deleted,O])]}}),[K]),ne=_.useCallback($=>K($,O=>({...O,raw:{},deleted:[],drafts:{}})),[K]),L=_.useCallback(async $=>{const O=w.current.provider;if(!O)return;const z=await j(k("devStudio.log.reload","Reload {id}",{id:$.id}),()=>O.readModule($));z&&(K($,E=>({key:$,files:z,raw:{},deleted:[],drafts:{},contents:E.contents})),x("info",k("devStudio.log.reloaded","Reloaded {id}",{id:$.id})))},[j,K,x,k]),A=_.useCallback($=>{const O=Y($);g(z=>{const E={...z};return delete E[O],E})},[]),q=_.useCallback(async($,O={})=>{var ve;const z=w.current.provider,E=Y($),D=l[E];if(!z||!D)return;const J=et(D,w.current.preset,w.current.options.locales);if(J.changes.length===0)return{ok:!0};const Q=O.force?J.changes.map(ae=>({...ae,baseVersion:void 0})):J.changes,V=await j(k("devStudio.log.save","Save {id}",{id:$.id}),()=>z.writeModule($,Q));if(!V)return;if(!V.ok)return x("warn",k("devStudio.log.conflicts","{id}: {count} file(s) changed meanwhile",{id:$.id,count:V.conflicts.length})),V;const oe=[];for(const[ae,se]of J.pending){const Se=D.files.find(le=>le.path===ae);oe.push({...Se,path:ae,text:se,version:((ve=V.versions)==null?void 0:ve[ae])??(Se==null?void 0:Se.version)})}K($,ae=>({key:$,files:oe,raw:{},deleted:[],drafts:{},contents:ae.contents}));const _e=Q.map(ae=>ae.type==="delete"?k("devStudio.log.changeDelete","delete {path}",{path:ae.path}):k("devStudio.log.changeWrite","write {path}",{path:ae.path})).join(", ");return x("info",k("devStudio.log.saved","Saved {id}: {changes}",{id:$.id,changes:_e})),V},[l,j,K,x,k]),M=_.useCallback(async $=>{const O=Y($),z=P[O];if(!z)return[];const E=Pt(z,i),D=w.current.provider;let J=[];if(D!=null&&D.validate){const V=[...z.pending.entries()].map(([oe,_e])=>({path:oe,text:_e}));J=await j(k("devStudio.log.validate","Validate {id}",{id:$.id}),()=>D.validate($,V))??[]}v(V=>({...V,[O]:J}));const Q=[...E,...J];x(Q.some(V=>V.severity==="error")?"warn":"info",Q.length===0?k("devStudio.log.noProblems","{id}: no problems",{id:$.id}):k("devStudio.log.problems","{id}: {count} problem(s)",{id:$.id,count:Q.length}));for(const V of Q)x(V.severity==="error"?"error":V.severity==="warning"?"warn":"info",`${V.path?`${V.path}: `:""}${V.messageKey?k(V.messageKey,V.message,V.params):V.message}`);return Q},[P,i,j,x,k]),H=_.useCallback(async $=>{const{provider:O,preset:z}=w.current;if(!(O!=null&&O.createModule)||!z.generateModule)return;const E=new Set(Object.values(a).flatMap(Q=>Q.map(V=>V.id))),D=await j(k("devStudio.log.generate","Generate module"),()=>z.generateModule($,{existingIds:E}));if(!D)return;const J=await j(k("devStudio.log.create","Create {id}",{id:D.id}),()=>O.createModule({workspaceId:$.workspaceId,packageId:D.packageId??$.packageId,id:D.id,files:D.files}));return J&&(x("info",k("devStudio.log.created","Created {id}",{id:J.id})),await N()),J},[a,j,x,N,k]),U=_.useCallback(async($,O)=>{const{provider:z,preset:E}=w.current;if(!(z!=null&&z.createModule)||!E.duplicateModule)return;const D=await j(k("devStudio.log.read","Read {id}",{id:$.id}),()=>z.readModule($));if(!D)return;const J=await j(k("devStudio.log.duplicate","Duplicate"),()=>E.duplicateModule(D,O));if(!J)return;const Q=await j(k("devStudio.log.create","Create {id}",{id:J.id}),()=>z.createModule({workspaceId:O.workspaceId,packageId:J.packageId??O.packageId,id:J.id,files:J.files}));return Q&&(x("info",k("devStudio.log.duplicated","Duplicated {id} as {copy}",{id:$.id,copy:Q.id})),await N()),Q},[j,x,N,k]),X=_.useCallback(async $=>{const O=w.current.provider;if(!(O!=null&&O.deleteModule))return!1;const z=await j(k("devStudio.log.delete","Delete {id}",{id:$.id}),async()=>(await O.deleteModule($),!0));return z&&(A($),x("info",k("devStudio.log.deleted","Deleted {id}",{id:$.id})),await N()),!!z},[j,A,x,N,k]),ye=_.useCallback(async $=>{const O=w.current.provider;if(!(O!=null&&O.savePackage))return;const z=await j(k("devStudio.log.savePackage","Save package {id}",{id:$.id}),()=>O.savePackage($));return z&&(x("info",k("devStudio.log.savedPackage","Saved package {id}",{id:z.id})),await N()),z},[j,x,N,k]),$e=_.useCallback(async($,O)=>{const z=w.current.provider;if(!(z!=null&&z.saveTemplate))return;const E=await j(k("devStudio.log.saveTemplate","Save template {id}",{id:$.id}),()=>z.saveTemplate($,O?{previousId:O}:void 0));return E&&z.listTemplates&&(p(await z.listTemplates()),x("info",k("devStudio.log.savedTemplate","Saved template {id}",{id:E.id}))),E},[j,x,k]),te=_.useCallback(async $=>{const O=w.current.provider;if(!(O!=null&&O.deleteTemplate))return!1;const z=await j(k("devStudio.log.deleteTemplate","Delete template {id}",{id:$}),async()=>(await O.deleteTemplate($),!0));return z&&O.listTemplates&&(p(await O.listTemplates()),x("info",k("devStudio.log.deletedTemplate","Deleted template {id}",{id:$}))),!!z},[j,x,k]);return{workspaces:s,modulesByWs:a,packagesByWs:u,templates:c,modules:P,serverIssues:f,busy:S>0,logs:b,clearLogs:()=>I([]),log:x,refresh:N,openModule:F,close:A,setDraft:G,setRaw:ee,deleteFile:B,discard:ne,reload:L,save:q,validate:M,createModule:H,duplicateModule:U,deleteModule:X,savePackage:ye,saveTemplate:$e,deleteTemplate:te}}const pe="__none",Be="t:",Ai={entities:"entities",views:"views",workflows:"workflows",i18n:"translations",permissions:"permissions",rbac:"access",dataSources:"dataSources",seeds:"seeds",hooks:"hooks",script:"scripts",scriptList:"scripts",integrations:"integrations",environments:"integrations"},qi=["entities","views","workflows","translations","permissions","access","dataSources","seeds","hooks","scripts","integrations"],ct={entities:"database",views:"grid",workflows:"git-branch",translations:"globe",permissions:"shield",access:"users",dataSources:"server",seeds:"list",hooks:"zap",scripts:"code",integrations:"plug",files:"folder"},Lt={views:"grid",workflows:"git-branch",dataSources:"server",scripts:"code"},Rt={frontend:"code",backend:"server",noCode:"list",sql:"database"},Bt=e=>e.kind.treeGroup??Ai[e.kind.editor],At=e=>e==="views"||e==="workflows"||e==="dataSources",we=(e,i)=>i.kind.editor==="scriptList"?Z(e,i):void 0,qe=e=>Object.prototype.hasOwnProperty.call(ct,e),fe=(e,i)=>qe(e)?ct[e]:(i==null?void 0:i.icon)??"folder";function ge(e,i,n,s){const o=(a,d)=>e(a,d).replace("{count}",String(n??0));if(!qe(i)){const a=s?e(s.labelKey??`devStudio.group.${i}`,s.label):i;return n===void 0?a:`${a}: ${n}`}switch(i){case"entities":return o("devStudio.group.entities","Entities: {count}");case"views":return o("devStudio.group.views","Views: {count}");case"workflows":return o("devStudio.group.workflows","Workflows: {count}");case"dataSources":return o("devStudio.group.dataSources","Data sources: {count}");case"scripts":return o("devStudio.group.scripts","Scripts: {count}");case"files":return o("devStudio.group.files","Files: {count}");case"translations":return e("devStudio.group.translations","Translations");case"permissions":return e("devStudio.group.permissions","Permissions");case"access":return e("devStudio.group.access","Access");case"seeds":return e("devStudio.group.seeds","Seed data");case"hooks":return e("devStudio.group.hooks","Lifecycle hooks");case"integrations":return e("devStudio.group.integrations","Integrations")}}function qt(e){switch(e.kind){case"workspace":return`w|${e.workspaceId}`;case"package":return`p|${e.workspaceId}|${e.packageId??pe}`;case"module":return`m|${Y(e.module)}`;case"group":return`g|${Y(e.module)}|${e.group}${e.section?`|${e.section}`:""}`;case"section":return`s|${Y(e.module)}|${e.sectionId}`;case"folder":return`fo|${Y(e.module)}|${e.folderId}`;case"entity":return`e|${Y(e.module)}|${e.docKey}|${e.index}`;case"item":return`i|${Y(e.module)}|${e.group}|${e.docKey}|${e.itemKey}`;case"document":return`d|${Y(e.module)}|${e.docKey}`;case"panel":return`x|${Y(e.module)}|${e.panelKey}`;case"file":return`f|${Y(e.module)}|${e.path}`;case"templates":return"t";case"category":return`c|${e.category}`;case"template":return`t|${e.templateId}`;case"templateModule":return`tm|${e.templateId}|${e.moduleId}`}}const Z=(e,i)=>e.drafts[i.key]??i.model,he=(e,i)=>e.documents.find(n=>n.key===i),je=(e,i)=>e.changes.some(n=>i.paths.includes(n.path));function lt(e){const i=[];for(const n of e.documents){if(n.kind.editor!=="entities")continue;const s=Z(e,n);Array.isArray(s)&&s.forEach((o,a)=>i.push({docKey:n.key,index:a,entity:o}))}return i}const Te=e=>lt(e).map(i=>i.entity),ut=(e,i="name")=>String(e.displayName||e[i]||"");function de(e,i){var s;if(i.kind.editor==="scriptList"){const o=(s=we(e,i))==null?void 0:s.scripts;return Array.isArray(o)?o:[]}const n=Z(e,i);return Array.isArray(n)?i.kind.editor==="dataSources"?n.map((o,a)=>{const d=o??{},r=typeof d.key=="string"&&d.key?d.key:typeof d.name=="string"&&d.name?d.name:`#${a}`,u=h.isModuleDataSource(o);return{key:r,label:typeof d.label=="string"&&d.label||r,...u?{definition:o}:{rawReason:"not a data source the editor knows"},source:o}}):n:[]}const ze="__standard",mt=e=>h.standardDataSources(T.entitiesToSchemas(Te(e))),Wi=(e,i)=>(i.shape==="object"?e("devStudio.dataSources.byId","{entity}: one by Id"):e("devStudio.dataSources.all","{entity}: all rows")).replace("{entity}",i.label??i.key);function Vi(e){return e.documents.filter(i=>i.kind.editor==="dataSources").flatMap(i=>Z(e,i)??[]).filter(h.isModuleDataSource)}function pt(e,i,n){return n===null?e.filter((s,o)=>o!==i):e.map((s,o)=>o===i?n:s)}function ht(e,i,n){return i.kind.editor==="scriptList"?{...we(e,i)??{scripts:[]},scripts:n}:n}function Wt(e,i,n){return n===null?e.filter(s=>s.key!==i):e.map(s=>s.key===i?n:s)}function Vt(e,i,n){const s=new Map((i??[]).map(o=>[o.id,o]));for(const o of n){const a=o.packageId??pe;s.has(a)||s.set(a,{id:a,workspaceId:e,label:o.packageId??"",derived:!0})}return[...s.values()].sort((o,a)=>o.id===pe?1:a.id===pe?-1:o.label.localeCompare(a.label))}const Pe=(e,i)=>e&&/^[a-z0-9-]+$/.test(e)?e:i,Ae=e=>e.slice(e.lastIndexOf("/")+1);function Jt(e){var n;const i=T.studioLayoutPath(e.working);return T.parseStudioLayout((n=e.working.find(s=>s.path===i))==null?void 0:n.text)}function Ji(e){const i=[...qi],n=[...e??[]].filter(o=>!i.includes(o.id)).sort((o,a)=>(o.order??1e3)-(a.order??1e3)),s=[...i];for(const o of n){const a=o.order===void 0?s.length:Math.min(s.length,Math.max(0,Math.floor(o.order/10)));s.splice(a,0,o.id)}return s}function Ui(e,i,n){var p;const{t:s}=n,o=i.key,a=l=>{var g;return(g=n.groups)==null?void 0:g.find(f=>f.id===l)},d=new Map;for(const l of i.documents){const g=Bt(l);g&&d.set(g,[...d.get(g)??[],l])}const r=(l,g)=>({id:`${g}/d:${l.key}`,node:{kind:"document",module:o,docKey:l.key},label:Ae(l.paths[0]??l.label),icon:"warning",noForm:!0,dirty:je(i,l)}),u=[],m=mt(i);for(const l of Ji(n.groups)){const g=d.get(l)??(l==="dataSources"&&m.length?[]:void 0);if(!g)continue;const f=a(l),v=`${e}/g:${l}`,S={kind:"group",module:o,group:l};if(l==="entities"){const y=[];for(const I of g){const w=Z(i,I);if(!Array.isArray(w)){y.push(r(I,v));continue}const k=je(i,I);w.forEach((x,j)=>{const N=x.fields;y.push({id:`${v}/e:${I.key}#${j}`,node:{kind:"entity",module:o,docKey:I.key,index:j},label:ut(x)||`#${j+1}`,icon:"table",info:Array.isArray(N)?String(N.length):void 0,dirty:k,search:String(x.name??""),ref:`entities:${String(x.name??`#${j}`)}`})})}const b=y.filter(I=>I.node.kind==="entity").length;u.push({id:v,node:S,label:ge(s,l,b),icon:fe(l,f),children:y});continue}if(l==="scripts"){u.push({id:v,node:S,icon:fe(l,f),...Gi(v,i,g,s)});continue}if(At(l)){const y=[];for(const I of g){if(I.model===void 0){y.push(r(I,v));continue}const w=je(i,I);for(const k of de(i,I))y.push({id:`${v}/i:${I.key}#${k.key}`,node:{kind:"item",module:o,group:l,docKey:I.key,itemKey:k.key},label:k.label||k.key,icon:Lt[l],noForm:k.definition===void 0,dirty:w,search:k.key,ref:`${l}:${k.key}`})}const b=y.filter(I=>I.node.kind==="item").length;if(l==="dataSources")for(const I of m)y.push({id:`${v}/std:${I.key}`,node:{kind:"item",module:o,group:l,docKey:ze,itemKey:I.key},label:Wi(s,I),icon:"lock",info:s("devStudio.dataSources.standard","standard"),readOnly:!0,search:I.key});u.push({id:v,node:S,label:ge(s,l,b),icon:fe(l,f),children:y});continue}if(!qe(l)){u.push({id:v,node:S,label:ge(s,l,g.length,f),icon:fe(l,f),children:g.map(y=>({id:`${v}/d:${y.key}`,node:{kind:"document",module:o,docKey:y.key},label:Ae(y.paths[0]??y.label),icon:y.kind.icon??fe(l,f),noForm:y.model===void 0,dirty:je(i,y),search:y.paths.join(" "),ref:`${l}:${y.paths[0]??y.key}`}))});continue}if(g.length===1){const y=g[0];u.push({id:v,node:{kind:"document",module:o,docKey:y.key},label:ge(s,l),icon:fe(l,f),noForm:y.model===void 0,dirty:je(i,y)});continue}u.push({id:v,node:S,label:ge(s,l),icon:fe(l,f),children:g.map(y=>({id:`${v}/d:${y.key}`,node:{kind:"document",module:o,docKey:y.key},label:y.label,icon:fe(l,f),noForm:y.model===void 0,dirty:je(i,y),search:y.paths.join(" ")}))})}const c=Yi(e,i,u,Jt(i),(l,g)=>ge(s,l,g,a(l)));for(const l of((p=n.panels)==null?void 0:p.call(n,i))??[])c.push({id:`${e}/x:${l.key}`,node:{kind:"panel",module:o,panelKey:l.key},label:l.label,icon:"puzzle"});if(n.advanced){const l=new Set(i.changes.map(f=>f.path)),g=[...i.working].sort((f,v)=>f.path.localeCompare(v.path));c.push({id:`${e}/g:files`,node:{kind:"group",module:o,group:"files"},label:ge(s,"files",g.length),icon:ct.files,children:g.map(f=>({id:`${e}/g:files/f:${f.path}`,node:{kind:"file",module:o,path:f.path},label:f.path,icon:"file",dirty:l.has(f.path)}))})}return c}function Gi(e,i,n,s){const o=i.key,a=n.filter(r=>r.kind.editor==="scriptList").length,d=[];for(const r of n){const u=je(i,r),m=r.paths[0]??r.key,c=we(i,r);if(r.kind.editor!=="scriptList"||r.model===void 0||!c){d.push({id:`${e}/d:${r.key}`,node:{kind:"document",module:o,docKey:r.key},label:Ae(m),icon:r.model===void 0?"warning":"code",noForm:r.model===void 0,dirty:u,search:r.paths.join(" "),ref:`scripts:${m}`});continue}for(const p of c.scripts){const l=p.definition;d.push({id:`${e}/i:${r.key}#${p.key}`,node:{kind:"item",module:o,group:"scripts",docKey:r.key,itemKey:p.key},label:p.label||p.key,icon:l?Rt[l.kind]:Lt.scripts,info:l==null?void 0:l.category,noForm:l===void 0,dirty:u,search:`${p.key} ${(l==null?void 0:l.category)??""}`,ref:`scripts:${p.key}`})}if(c.holds==="phases"||Object.keys(c.phases??{}).length>0){const p=s("devStudio.scripts.database","Database scripts");d.push({id:`${e}/d:${r.key}`,node:{kind:"document",module:o,docKey:r.key},label:a>1?`${p} (${Ae(m)})`:p,icon:"database",info:String(Object.values(c.phases??{}).reduce((l,g)=>l+g.length,0)),dirty:u,search:r.paths.join(" "),ref:`scripts:${m}`})}}return{label:ge(s,"scripts",d.length),children:d}}const Hi=new Set(["entities","views","workflows","dataSources","scripts"]),Le=e=>e.reduce((i,n)=>i+(n.node.kind==="folder"?Le(n.children??[]):n.ref?1:0),0);function Yi(e,i,n,s,o){var g;if(T.isEmptyStudioLayout(s))return n;const a=i.key,d=new Set(s.sections.map(f=>f.id)),r=f=>{var v;return(f.ref?(v=s.placement[f.ref])==null?void 0:v.order:void 0)??Number.MAX_SAFE_INTEGER},u=f=>f.some(v=>{var S;return v.ref&&((S=s.placement[v.ref])==null?void 0:S.order)!==void 0})?[...f].sort((v,S)=>r(v)-r(S)):f,m=(f,v,S,y,b)=>{var P;const I=s.folders.filter(F=>F.group===S&&(F.section&&d.has(F.section)?F.section:void 0)===y),w=new Set(I.map(F=>F.id)),k=F=>K=>({...K,id:`${F}${K.id.startsWith(v)?K.id.slice(v.length):`/${K.id}`}`}),x=new Map,j=[];for(const F of b){const K=F.ref?(P=s.placement[F.ref])==null?void 0:P.folder:void 0;K&&w.has(K)?x.set(K,[...x.get(K)??[],F]):j.push(F)}const N=(F,K)=>I.filter(G=>(G.parent&&w.has(G.parent)?G.parent:void 0)===F).map(G=>{const ee=`${K}/fo:${G.id}`,B=[...N(G.id,ee),...u(x.get(G.id)??[]).map(k(ee))];return{id:ee,node:{kind:"folder",module:a,folderId:G.id,group:S},label:G.label,icon:"folder",info:String(Le(B)),children:B}});return[...N(void 0,f),...u(j).map(k(f))]},c=[],p=new Map(s.sections.map(f=>[f.id,[]]));for(const f of n){if(f.node.kind!=="group"||!f.children){c.push(f);continue}const v=f.node.group,S=new Map;for(const b of f.children){const I=b.ref?(g=s.placement[b.ref])==null?void 0:g.section:void 0,w=I&&d.has(I)?I:void 0;S.set(w,[...S.get(w)??[],b])}const y=m(f.id,f.id,v,void 0,S.get(void 0)??[]);c.push({...f,label:l(f,v,y),children:y});for(const b of s.sections){const I=S.get(b.id)??[],w=s.folders.some(j=>j.group===v&&j.section===b.id);if(I.length===0&&!w)continue;const k=`${e}/s:${b.id}/g:${v}`,x=m(k,f.id,v,b.id,I);p.get(b.id).push({...f,id:k,node:{kind:"group",module:a,group:v,section:b.id},label:l(f,v,x),children:x})}}for(const f of s.sections){const v=p.get(f.id)??[];c.push({id:`${e}/s:${f.id}`,node:{kind:"section",module:a,sectionId:f.id},label:f.label,icon:"layers",info:String(v.reduce((S,y)=>S+Le(y.children??[]),0)),children:v})}return c;function l(f,v,S){return Hi.has(v)||!qe(v)?o(v,Le(S)):f.label}}function nt(e){const i=e.label||e.id;return i===e.id&&e.id.includes("/")?e.id.slice(e.id.lastIndexOf("/")+1):i}const tt=e=>e.parentId??(e.id.includes("/")?e.id.slice(0,e.id.lastIndexOf("/")):void 0);function Qi(e,i,n,s){const o=new Map(n.map(m=>[m.id,m]));for(const m of n){let c=tt(m);for(;c&&!o.has(c);){const p={id:c,workspaceId:e,label:"",derived:!0};o.set(c,p),c=tt(p)}}const a=[...o.values()],d=m=>{const c=tt(m);return c&&o.has(c)&&c!==m.id?c:void 0},r=m=>m.sort((c,p)=>c.id===pe?1:p.id===pe?-1:nt(c).localeCompare(nt(p))),u=(m,c)=>r(a.filter(p=>d(p)===m)).map(p=>{const l=`${c}/p:${p.id}`;return s(p,l,u(p.id,l))});return u(void 0,i)}function Xi(e){const{t:i}=e,n=i("devStudio.explorer.noPackage","No package"),s=e.workspaces.map(u=>{const m=e.modulesByWs[u.id]??[],c=`w:${u.id}`;return{id:c,node:{kind:"workspace",workspaceId:u.id},label:u.label,icon:Pe(u.icon,"folder"),info:String(m.length),readOnly:u.readOnly,search:u.id,children:Qi(u.id,c,Vt(u.id,e.packagesByWs[u.id],m),(p,l,g)=>{const f=m.filter(v=>(v.packageId??pe)===p.id).sort((v,S)=>v.label.localeCompare(S.label));return{id:l,node:{kind:"package",workspaceId:u.id,packageId:p.id===pe?void 0:p.id},label:p.id===pe?n:nt(p),icon:Pe(p.icon,"archive"),info:String(f.length),search:p.id,children:[...g,...f.map(v=>{var k;const S=Y(v),y=e.modules[S],b=`${l}/m:${v.id}`,I=y?Ui(b,y,e):void 0,w=y?[...lt(y).map(x=>`${x.entity.name??""} ${ut(x.entity)}`),...y.documents.filter(x=>x.kind.editor==="views").flatMap(x=>de(y,x).map(j=>`${j.key} ${j.label}`))]:[];return{id:b,node:{kind:"module",module:{workspaceId:v.workspaceId,id:v.id}},label:v.label,icon:Pe(v.icon,"box"),info:v.version,readOnly:v.readOnly,shadowedBy:v.shadowedBy,dirty:y==null?void 0:y.dirty,issues:(k=e.issueCounts)==null?void 0:k[S],search:[v.id,v.description??"",v.search??"",...w].join(" "),children:I}})]}})}});if(e.templates){const u=new Map;for(const p of e.workspaces)for(const l of e.modulesByWs[p.id]??[])u.has(l.id)||u.set(l.id,l);const m=new Map;for(const p of e.templates){const l=p.category??"";m.set(l,[...m.get(l)??[],p])}const c=p=>{var l,g;return((l=p.translations.en)==null?void 0:l.name)??((g=Object.values(p.translations)[0])==null?void 0:g.name)??p.id};s.push({id:Be,node:{kind:"templates"},label:i("devStudio.tree.templates","Templates"),icon:"layers",info:String(e.templates.length),children:[...m.entries()].sort(([p],[l])=>p.localeCompare(l)).map(([p,l])=>{const g=`${Be}/c:${p}`;return{id:g,node:{kind:"category",category:p},label:p||i("devStudio.explorer.noCategory","Other"),icon:"folder",info:String(l.length),children:[...l].sort((f,v)=>(f.sortOrder??0)-(v.sortOrder??0)||c(f).localeCompare(c(v))).map(f=>{const v=`${g}/t:${f.id}`;return{id:v,node:{kind:"template",templateId:f.id},label:c(f),icon:Pe(f.icon,"layers"),info:String(f.modules.length),readOnly:f.readOnly,search:`${f.id} ${(f.tags??[]).join(" ")}`,children:f.modules.map(S=>{const y=u.get(S.moduleId);return{id:`${v}/m:${S.moduleId}`,node:{kind:"templateModule",templateId:f.id,moduleId:S.moduleId,target:y?{workspaceId:y.workspaceId,id:y.id}:void 0},label:(y==null?void 0:y.label)??S.moduleId,icon:"box",info:S.required?i("devStudio.template.required","required"):void 0,missing:!y,search:S.moduleId}})}})}})})}const o=new Map,a=new Map,d=new Map,r=(u,m,c=0)=>{for(const p of u){p.depth=c,o.set(p.id,p),m&&a.set(p.id,m);const l=qt(p.node);d.has(l)||d.set(l,p.id),p.children&&r(p.children,p.id,c+1)}};return r(s),{rows:s,byId:o,parentOf:a,rowOfNode:d}}function Tt(e,i){const n=[];let s=i;for(;s;){const o=e.byId.get(s);if(!o)break;n.unshift(o),s=e.parentOf.get(s)}return n}const it=(e,i)=>e.rowOfNode.get(qt(i));function Fe(e){return"module"in e?e.module:void 0}function Zi(e,i){var s;const n="module"in e?i.modules[Y(e.module)]:void 0;switch(e.kind){case"module":return n!=null&&n.documents.some(o=>o.kind.editor==="manifest")?{kind:"manifest",module:e.module}:void 0;case"entity":return{kind:"entity",module:e.module,docKey:e.docKey,index:e.index};case"item":{if(e.docKey===ze)return{...e};const o=n&&he(n,e.docKey),a=o&&de(n,o).find(d=>d.key===e.itemKey);return(a==null?void 0:a.definition)!==void 0||i.advanced?{...e}:void 0}case"document":{const o=n&&he(n,e.docKey);return(o==null?void 0:o.model)!==void 0?{kind:"document",module:e.module,docKey:e.docKey}:o&&i.advanced?{kind:"file",module:e.module,path:o.paths[0]}:void 0}case"panel":return{kind:"panel",module:e.module,panelKey:e.panelKey};case"file":return{kind:"file",module:e.module,path:e.path};case"package":{const o=(s=i.packages)==null?void 0:s.find(a=>a.id===e.packageId);return o&&!o.derived?{kind:"package",pkg:o}:void 0}case"template":return{kind:"template",templateId:e.templateId};default:return}}function Et(e){switch(e.kind){case"manifest":case"problems":case"history":return{kind:"module",module:e.module};case"entity":return{kind:"entity",module:e.module,docKey:e.docKey,index:e.index};case"item":return{...e};case"document":return{kind:"document",module:e.module,docKey:e.docKey};case"panel":return{kind:"panel",module:e.module,panelKey:e.panelKey};case"file":return{kind:"file",module:e.module,path:e.path};case"package":return{kind:"package",workspaceId:e.pkg.workspaceId,packageId:e.pkg.id};case"template":return e.templateId?{kind:"template",templateId:e.templateId}:void 0}}const en=/^\/(?:[A-Za-z]+\/)?(\d+)(?:\/|$)/;function Ut(e,i){const n=e.key,s=i.path?e.documents.find(r=>r.paths.includes(i.path)):void 0;if(!s)return{kind:"module",module:n};const o=Bt(s),a=s.paths.length===1?en.exec(i.pointer??""):null,d=a?Number(a[1]):-1;if(o==="entities"){const r=Z(e,s);return Array.isArray(r)&&d>=0&&d<r.length?{kind:"entity",module:n,docKey:s.key,index:d}:{kind:"group",module:n,group:o}}if(o==="scripts"&&s.kind.editor==="scriptList"){const r=d>=0?de(e,s)[d]:void 0;return r?{kind:"item",module:n,group:"scripts",docKey:s.key,itemKey:r.key}:{kind:"document",module:n,docKey:s.key}}if(At(o)){const r=d>=0?de(e,s)[d]:void 0;return r?{kind:"item",module:n,group:o,docKey:s.key,itemKey:r.key}:{kind:"group",module:n,group:o}}return o?{kind:"document",module:n,docKey:s.key}:s.kind.editor==="manifest"?{kind:"module",module:n}:{kind:"file",module:n,path:s.paths[0]}}function tn(e,i){const n=new Set(e.documents.filter(o=>o.kind.editor==="dataSources").flatMap(o=>de(e,o).map(a=>a.key)));let s=i;for(let o=2;n.has(s);o++)s=`${i}${o}`;return s}function Gt(e,i,n,s){var p,l,g;const o=e.key,a={...s,key:tn(e,s.key)},d=f=>({kind:"item",module:o,group:"dataSources",docKey:f,itemKey:a.key}),r=e.documents.find(f=>f.kind.editor==="dataSources"&&Array.isArray(Z(e,f)));if(r)return n.setDraft(o,r.key,[...Z(e,r)??[],a]),d(r.key);const u=i.kinds.find(f=>f.editor==="dataSources"),m=u&&((p=i.newFile)==null?void 0:p.call(i,u.id,{key:o,files:e.working,documents:e.documents}));if(!u||!m||e.working.some(f=>f.path===m.path))return;const c={moduleId:o.id,files:e.working,locales:i.locales??[]};try{const f=u.decode([m],c),v=(l=u.encode([...Array.isArray(f)?f:[],a],[m],c).files.find(S=>S.path===m.path))==null?void 0:l.text;return v===void 0?void 0:(n.setRaw(o,m.path,v),d(`${u.id}:${((g=u.group)==null?void 0:g.call(u,m.path))??m.path}`))}catch{return}}function nn(e,i){var o;if(e.documents.some(a=>a.kind.editor==="dataSources"&&a.model!==void 0))return!0;const n=i.kinds.find(a=>a.editor==="dataSources"),s=n&&((o=i.newFile)==null?void 0:o.call(i,n.id,{key:e.key,files:e.working,documents:e.documents}));return!!s&&!e.working.some(a=>a.path===s.path)}const sn=[{target:".nice-i18n-editor",titleKey:"tutorial.i18nEditor.intro.title",title:"Translations",contentKey:"tutorial.i18nEditor.intro.content",content:"Edit translations as a keys × locales grid. Add keys and locales; amber cells mark missing translations.",placement:"auto"},{target:'[data-tour="i18n-grid"]',titleKey:"tutorial.i18nEditor.grid.title",title:"Keys × locales",contentKey:"tutorial.i18nEditor.grid.content",content:"Each row is a translation key and each column a locale. Edit a cell to set a translation; amber cells are still missing.",placement:"top"},{target:'[data-tour="i18n-add"]',titleKey:"tutorial.i18nEditor.add.title",title:"Add keys & locales",contentKey:"tutorial.i18nEditor.add.content",content:"Add a new translation key or a new locale column here; new cells start empty and are flagged as missing.",placement:"top"}],vt=_.forwardRef(function(i,n){const{value:s,defaultValue:o,onChange:a,locales:d,allowEditLocales:r=!0,allowEditKeys:u=!0,highlightMissing:m=!0,readOnly:c=!1,tutorial:p,className:l,style:g,id:f,"data-testid":v}=i,{t:S}=xe.useNiceTranslation(),[y,b]=xe.useControllableState({value:s,defaultValue:o,fallbackValue:{},onChange:a,componentName:"NiceI18nEditor"}),[I,w]=_.useState(""),[k,x]=_.useState(""),j=_.useMemo(()=>d??Object.keys(y),[d,y]),N=_.useMemo(()=>{const L=new Set;for(const A of Object.keys(y))for(const q of Object.keys(y[A]??{}))L.add(q);return[...L].sort()},[y]),P=(L,A,q)=>{b({...y,[L]:{...y[L]??{},[A]:q}})},F=(L,A)=>{if(!A||A===L)return;const q={};for(const M of Object.keys(y)){const H={...y[M]??{}};L in H&&(H[A]=H[L],delete H[L]),q[M]=H}b(q)},K=L=>{const A={};for(const q of Object.keys(y)){const M={...y[q]??{}};delete M[L],A[q]=M}b(A)},G=()=>{const L=I.trim();if(!L||N.includes(L))return;const A={};for(const q of j)A[q]={...y[q]??{},[L]:""};for(const q of Object.keys(y))A[q]||(A[q]=y[q]);b(A),w("")},ee=()=>{const L=k.trim();if(!L||y[L])return;const A={};for(const q of N)A[q]="";b({...y,[L]:A}),x("")},B=L=>{const A={...y};delete A[L],b(A)},ne="nice-i18n-editor"+(l?` ${l}`:"");return t.jsxs("div",{ref:n,id:f,className:ne,style:g,"data-testid":v,children:[p&&t.jsx("div",{className:"nice-i18n-editor__tutorial",children:t.jsx(xe.NiceTutorialButton,{steps:xe.resolveTutorial(p,sn)})}),t.jsx("div",{className:"nice-i18n-editor__scroll","data-tour":"i18n-grid",children:t.jsxs("table",{className:"nice-i18n-editor__table",children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{className:"nice-i18n-editor__key-head",children:S("i18nEditor.keyHead","Key")}),j.map(L=>t.jsxs("th",{className:"nice-i18n-editor__locale-head",children:[t.jsx("span",{children:L}),r&&!c&&t.jsx("button",{type:"button",className:"nice-i18n-editor__locale-remove","aria-label":`${S("i18nEditor.removeLocale","Remove locale")} ${L}`,onClick:()=>B(L),children:t.jsx(xe.NiceIcon,{name:"close",size:12})})]},L))]})}),t.jsxs("tbody",{children:[N.map(L=>t.jsxs("tr",{children:[t.jsxs("td",{className:"nice-i18n-editor__key-cell",children:[u&&!c?t.jsx("input",{className:"nice-i18n-editor__key-input",defaultValue:L,onBlur:A=>F(L,A.target.value.trim()),"aria-label":S("i18nEditor.keyAria","Translation key")}):t.jsx("span",{className:"nice-i18n-editor__key-text",children:L}),u&&!c&&t.jsx("button",{type:"button",className:"nice-i18n-editor__key-remove","aria-label":`${S("i18nEditor.removeKey","Remove key")} ${L}`,onClick:()=>K(L),children:t.jsx(xe.NiceIcon,{name:"close",size:12})})]}),j.map(A=>{var H;const q=((H=y[A])==null?void 0:H[L])??"",M=m&&q==="";return t.jsx("td",{className:"nice-i18n-editor__cell",children:t.jsx("input",{className:"nice-i18n-editor__cell-input"+(M?" nice-i18n-editor__cell-input--missing":""),value:q,readOnly:c,onChange:U=>P(A,L,U.target.value),"aria-label":`${L} (${A})`})},A)})]},L)),N.length===0&&t.jsx("tr",{children:t.jsx("td",{className:"nice-i18n-editor__empty",colSpan:j.length+1,children:S("i18nEditor.empty","No translation keys yet.")})})]})]})}),!c&&(u||r)&&t.jsxs("div",{className:"nice-i18n-editor__toolbar","data-tour":"i18n-add",children:[u&&t.jsxs("div",{className:"nice-i18n-editor__add",children:[t.jsx("input",{className:"nice-i18n-editor__add-input",placeholder:S("i18nEditor.newKeyPlaceholder","new.key"),value:I,onChange:L=>w(L.target.value),onKeyDown:L=>{L.key==="Enter"&&G()},"aria-label":S("i18nEditor.newKeyAria","New key")}),t.jsxs("button",{type:"button",onClick:G,children:["+ ",S("i18nEditor.addKey","Key")]})]}),r&&t.jsxs("div",{className:"nice-i18n-editor__add",children:[t.jsx("input",{className:"nice-i18n-editor__add-input",placeholder:S("i18nEditor.newLocalePlaceholder","locale (e.g. de)"),value:k,onChange:L=>x(L.target.value),onKeyDown:L=>{L.key==="Enter"&&ee()},"aria-label":S("i18nEditor.newLocaleAria","New locale")}),t.jsxs("button",{type:"button",onClick:ee,children:["+ ",S("i18nEditor.addLocale","Locale")]})]})]})]})});function ft(e,i){switch(i){case"frontend":return e("devStudio.scripts.kind.frontend","Frontend");case"backend":return e("devStudio.scripts.kind.backend","Backend");case"noCode":return e("devStudio.scripts.kind.noCode","No-code");case"sql":return e("devStudio.scripts.kind.sql","SQL")}}const on=(e,i)=>{switch(i){case"frontend":return e("devStudio.scripts.hint.frontend","TypeScript or JavaScript run in the browser.");case"backend":return e("devStudio.scripts.hint.backend","C# or JavaScript run on the server.");case"noCode":return e("devStudio.scripts.hint.noCode","Steps over the app data, set up without code.");case"sql":return e("devStudio.scripts.hint.sql","A query or procedure run in the database.")}},Ht={typescript:"TypeScript",javascript:"JavaScript",csharp:"C#",sql:"SQL"},an=e=>{const i=(e??"").toLowerCase();return i.startsWith("csharp")||i==="c#"?"csharp":i.endsWith("sql")?"sql":i==="typescript"||i==="javascript"?i:"plaintext"};function Yt(e,i){var s;const n=e.documents.flatMap(o=>{var a;return(((a=we(e,o))==null?void 0:a.scripts)??[]).map(d=>{var r;return(r=d.definition)==null?void 0:r.category})});return[...new Set([...((s=i.scripts)==null?void 0:s.categories)??[],...n])].filter(o=>!!o).sort((o,a)=>o.localeCompare(a))}function Qt({value:e,onChange:i,categories:n,readOnly:s,testId:o}){const{t:a}=h.useNiceTranslation(),d=n.filter(r=>r!==e).slice(0,12);return t.jsxs("div",{className:"nice-development-studio__script-category",children:[t.jsx(h.NiceTextInput,{label:a("devStudio.scripts.category","Category"),value:e,onChange:i,readOnly:s,size:"sm","data-testid":o}),!s&&d.length>0&&t.jsx("div",{className:"nice-development-studio__chips",children:d.map(r=>t.jsx(h.NiceButton,{size:"xs",variant:"ghost",onClick:()=>i(r),children:r},r))})]})}function dn({value:e,onChange:i,readOnly:n}){const{t:s}=h.useNiceTranslation(),o=(a,d)=>i(e.map((r,u)=>u===a?{...r,...d}:r));return t.jsxs("fieldset",{className:"nice-development-studio__script-params",children:[t.jsx("legend",{children:s("devStudio.scripts.parameters","Parameters")}),e.map((a,d)=>t.jsxs("div",{className:"nice-development-studio__script-param",children:[t.jsx(h.NiceTextInput,{label:s("devStudio.scripts.param.name","Name"),labelPlacement:"inside",value:a.name,onChange:r=>o(d,{name:r}),readOnly:n,size:"sm"}),t.jsx(h.NiceTextInput,{label:s("devStudio.scripts.param.type","Type"),labelPlacement:"inside",value:a.type??"",onChange:r=>o(d,{type:r||void 0}),readOnly:n,size:"sm"}),t.jsx(h.NiceTextInput,{label:s("devStudio.scripts.param.description","Description"),labelPlacement:"inside",value:a.description??"",onChange:r=>o(d,{description:r||void 0}),readOnly:n,size:"sm"}),!n&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost","aria-label":s("devStudio.scripts.param.remove","Remove parameter"),onClick:()=>i(e.filter((r,u)=>u!==d)),children:t.jsx(h.NiceIcon,{name:"trash",size:14})})]},d)),!n&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:()=>i([...e,{name:`arg${e.length+1}`,type:"string"}]),children:s("devStudio.scripts.param.add","Add parameter")})]})}function rn({module:e,doc:i,item:n,preset:s,session:o,readOnly:a,scriptRunner:d,scriptIo:r,onRenamed:u}){var x,j;const{t:m}=h.useNiceTranslation(),c=n.definition,p=_.useMemo(()=>Yt(e,s),[e,s]);if(!c)return null;const l=de(e,i),g=N=>{const P={...c,...N},F=P.name&&!l.some(G=>G!==n&&G.key===P.name)?P.name:n.key,K={...n,key:F,label:P.displayName||P.name||n.label,definition:P};o.setDraft(e.key,i.key,ht(e,i,l.map(G=>G.key===n.key?K:G))),F!==n.key&&u(F)},f=N=>{if(N===c.kind)return;const P=T.studioScriptLanguages(N),F=c.language&&P.includes(c.language)?c.language:P[0],K=T.newStudioScript({kind:N,name:c.name,language:F});g({kind:N,language:F,steps:N==="noCode"?c.steps??[]:void 0,source:N==="noCode"?void 0:c.source??K.source})},v=((x=s.scripts)==null?void 0:x.kinds)??T.NICE_STUDIO_SCRIPT_KINDS,S=T.studioScriptLanguages(c.kind),y=(j=s.scripts)==null?void 0:j.triggers,b=e.documents.flatMap(N=>{var P;return((P=we(e,N))==null?void 0:P.scripts)??[]}).map(N=>N.key).filter(N=>N!==n.key),I=e.documents.filter(N=>N.kind.editor==="dataSources").flatMap(N=>Z(e,N)??[]).map(N=>N.key),w=c.sourcePath?e.documents.find(N=>N.paths.includes(c.sourcePath)):void 0;let k;return c.kind==="noCode"?k=t.jsx(h.NiceNoCodeScriptEditor,{value:{parameters:c.parameters,steps:c.steps??[]},onChange:N=>g({steps:N.steps}),dataSources:I,scripts:b,io:r,readOnly:a}):c.sourcePath&&c.source===void 0?k=t.jsxs("p",{className:"nice-development-studio__muted",children:[m("devStudio.scripts.sourcePath","The code is in {path}.").replace("{path}",c.sourcePath),w?"":` ${m("devStudio.scripts.sourceMissing","The module has no such file.")}`]}):d&&c.kind==="frontend"&&c.language==="javascript"?k=t.jsx(h.NiceScriptRunner,{...d,value:c.source??"",onChange:N=>g({source:N})}):k=t.jsx(h.NiceSimpleCodeEditor,{value:c.source??"",onChange:N=>g({source:N}),language:an(c.language),height:"100%",lineNumbers:!0,readOnly:a}),t.jsxs("div",{className:"nice-development-studio__script","data-testid":"studio-script-editor",children:[t.jsxs("div",{className:"nice-development-studio__script-meta",children:[t.jsx(h.NiceTextInput,{label:m("devStudio.scripts.name","Name"),value:c.name,onChange:N=>g({name:N}),readOnly:a,size:"sm","data-testid":"studio-script-name"}),t.jsx(h.NiceTextInput,{label:m("devStudio.scripts.displayName","Display name"),value:c.displayName??"",onChange:N=>g({displayName:N||void 0}),readOnly:a,size:"sm"}),t.jsx(h.NiceSelect,{label:m("devStudio.scripts.kind","Kind"),value:c.kind,options:v.map(N=>({value:N,label:ft(m,N)})),onChange:N=>f(String(N)),disabled:a,size:"sm"}),S.length>0&&t.jsx(h.NiceSelect,{label:m("devStudio.scripts.language","Language"),value:c.language??S[0],options:[...new Set([...S,...c.language?[c.language]:[]])].map(N=>({value:N,label:Ht[N]??N})),onChange:N=>g({language:String(N)}),disabled:a,size:"sm"}),t.jsx(Qt,{value:c.category??"",onChange:N=>g({category:N||void 0}),categories:p,readOnly:a}),y&&y.length>0?t.jsx(h.NiceSelect,{label:m("devStudio.scripts.trigger","Runs on"),value:c.trigger??"",options:[{value:"",label:m("devStudio.scripts.trigger.none","When called")},...y.map(N=>({value:N.id,label:N.label}))],onChange:N=>g({trigger:String(N)||void 0}),disabled:a,size:"sm"}):t.jsx(h.NiceTextInput,{label:m("devStudio.scripts.trigger","Runs on"),value:c.trigger??"",onChange:N=>g({trigger:N||void 0}),readOnly:a,size:"sm"}),c.kind!=="noCode"&&t.jsx(h.NiceTextInput,{label:m("devStudio.scripts.returnType","Returns"),value:c.returnType??"",onChange:N=>g({returnType:N||void 0}),readOnly:a,size:"sm"}),t.jsx(h.NiceTextArea,{label:m("devStudio.scripts.description","Description"),value:c.description??"",onChange:N=>g({description:N||void 0}),readOnly:a,rows:3}),t.jsx(dn,{value:c.parameters??[],onChange:N=>g({parameters:N}),readOnly:a})]}),t.jsx("div",{className:"nice-development-studio__script-body",children:k})]})}function cn({value:e,onChange:i,preset:n,readOnly:s}){var f;const{t:o}=h.useNiceTranslation(),a=e.phases??{},d=Object.keys(a),[r,u]=_.useState(d[0]??""),m=d.includes(r)?r:d[0]??"",c=(((f=n.scripts)==null?void 0:f.phases)??T.NICE_STUDIO_SCRIPT_PHASES).filter(v=>!d.includes(v)),p=v=>i({...e,phases:v}),l=a[m]??[],g=v=>p({...a,[m]:v});return e.holds==="scripts"?t.jsx("p",{className:"nice-development-studio__muted",children:o("devStudio.scripts.noPhases","This file holds named scripts only.")}):t.jsxs("div",{className:"nice-development-studio__phases","data-testid":"studio-script-phases",children:[t.jsxs("div",{className:"nice-development-studio__phases-bar",children:[d.map(v=>t.jsx(h.NiceButton,{size:"sm",variant:v===m?"primary":"ghost","aria-pressed":v===m,onClick:()=>u(v),children:`${v} (${a[v].length})`},v)),!s&&c.length>0&&t.jsx(h.NiceSelect,{"aria-label":o("devStudio.scripts.addPhase","Add phase"),placeholder:o("devStudio.scripts.addPhase","Add phase"),value:"",options:c,onChange:v=>{const S=String(v);S&&(p({...a,[S]:[]}),u(S))},size:"sm"}),!s&&m&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"trash",size:14}),onClick:()=>{const v={...a};delete v[m],p(v)},children:o("devStudio.scripts.removePhase","Remove phase")})]}),m?t.jsx("ol",{className:"nice-development-studio__statements",children:l.map((v,S)=>t.jsxs("li",{className:"nice-development-studio__statement",children:[t.jsx(h.NiceSimpleCodeEditor,{value:v,onChange:y=>g(l.map((b,I)=>I===S?y:b)),language:"sql",height:Math.min(240,28+20*(v.split(`
|
|
6
|
+
`).length||1)),readOnly:s}),!s&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost","aria-label":o("devStudio.scripts.removeStatement","Remove statement"),onClick:()=>g(l.filter((y,b)=>b!==S)),children:t.jsx(h.NiceIcon,{name:"trash",size:14})})]},S))}):t.jsx("p",{className:"nice-development-studio__muted",children:o("devStudio.scripts.noPhase","No phases yet: add one to run SQL when the module is installed.")}),!s&&m&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:()=>g([...l,""]),children:o("devStudio.scripts.addStatement","Add statement")})]})}function Xt(e,i){var a;const n=i.kinds.find(d=>d.editor==="scriptList"),s=n&&((a=i.newFile)==null?void 0:a.call(i,n.id,{key:e.key,files:e.working,documents:e.documents}));if(!n||!s||e.working.some(d=>d.path===s.path))return;const o={moduleId:e.key.id,files:e.working,locales:i.locales??[]};try{return{kind:n,file:s,model:n.decode([s],o),ctx:o}}catch{return}}function Zt(e,i,n,s){var g,f,v;const o=e.key,a=s.choice==="phase",d=S=>!!S&&(a?S.holds!=="scripts":S.holds!=="phases"),r=e.documents.find(S=>S.kind.editor==="scriptList"&&S.model!==void 0&&d(we(e,S))),u=S=>{if(a){const k=s.phase||"postInstall",x={...S.phases??{}};x[k]=[...x[k]??[],s.name?`-- ${s.name}
|
|
7
|
+
`:""];const j=S.holds==="scripts"&&S.scripts.length===0?"phases":S.holds;return{model:{...S,phases:x,...j?{holds:j}:{}},screen:N=>({kind:"document",module:o,docKey:N})}}const y=T.newStudioScript({kind:s.choice,name:s.name,language:s.language,category:s.category,trigger:s.trigger});let b=y.name;for(let k=2;S.scripts.some(x=>x.key===b);k++)b=`${y.name}${k}`;const I={...y,name:b},w={key:b,label:I.displayName||b,definition:I,source:{}};return{model:{...S,scripts:[...S.scripts,w]},screen:k=>({kind:"item",module:o,group:"scripts",docKey:k,itemKey:b})}};if(r){const S=u(we(e,r)??{scripts:[]});return n.setDraft(o,r.key,S.model),S.screen(r.key)}const m=Xt(e,i);if(!m)return;const c=u(m.model),{path:p}=m.file,l=(g=m.kind.encode(c.model,[m.file],m.ctx).files.find(S=>S.path===p))==null?void 0:g.text;if(l!==void 0)return n.setRaw(o,p,l),c.screen(`${m.kind.id}:${((v=(f=m.kind).group)==null?void 0:v.call(f,p))??p}`)}function ei(e,i){return e.documents.some(n=>n.kind.editor==="scriptList"&&n.model!==void 0)||Xt(e,i)!==void 0}function ti({module:e,preset:i,onAdd:n,onClose:s}){var N,P,F;const{t:o}=h.useNiceTranslation(),a=((N=i.scripts)==null?void 0:N.kinds)??T.NICE_STUDIO_SCRIPT_KINDS,d=((P=i.scripts)==null?void 0:P.phases)??T.NICE_STUDIO_SCRIPT_PHASES,[r,u]=_.useState(a[0]??"frontend"),[m,c]=_.useState(""),[p,l]=_.useState(""),[g,f]=_.useState(""),[v,S]=_.useState(void 0),[y,b]=_.useState(d.includes("postInstall")?"postInstall":d[0]),I=_.useMemo(()=>Yt(e,i),[e,i]),w=r==="phase"?[]:T.studioScriptLanguages(r),k=r==="phase"||!!m.trim(),x=()=>{k&&(s(),n({choice:r,name:m.trim(),category:p.trim()||void 0,trigger:g||void 0,language:v&&w.includes(v)?v:void 0,phase:y}))},j=[...a.map(K=>({id:K,icon:Rt[K],label:ft(o,K),hint:on(o,K)})),{id:"phase",icon:"database",label:o("devStudio.scripts.kind.phase","Database script"),hint:o("devStudio.scripts.hint.phase","SQL run when the module is installed or removed.")}];return t.jsx(h.NiceModal,{open:!0,onClose:s,title:o("devStudio.scripts.add","Add script"),footer:t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{variant:"ghost",onClick:s,children:o("devStudio.cancel","Cancel")}),t.jsx(h.NiceButton,{variant:"primary",disabled:!k,onClick:x,"data-testid":"studio-script-add-ok",children:o("devStudio.scripts.create","Create")})]}),children:t.jsxs("div",{className:"nice-development-studio__form",children:[t.jsx("div",{className:"nice-development-studio__script-kinds",children:j.map(K=>t.jsxs("button",{type:"button","aria-pressed":K.id===r,className:`nice-development-studio__script-kind${K.id===r?" nice-development-studio__script-kind--active":""}`,onClick:()=>u(K.id),"data-testid":`studio-script-kind-${K.id}`,children:[t.jsx(h.NiceIcon,{name:K.icon,size:20}),t.jsx("strong",{children:K.label}),t.jsx("span",{children:K.hint})]},K.id))}),r==="phase"?t.jsxs(t.Fragment,{children:[t.jsx(h.NiceSelect,{label:o("devStudio.scripts.phase","Phase"),value:y,options:[...d],onChange:K=>b(String(K)),size:"sm"}),t.jsx(h.NiceTextInput,{label:o("devStudio.scripts.comment","What it does"),value:m,onChange:c,size:"sm"})]}):t.jsxs(t.Fragment,{children:[t.jsx(h.NiceTextInput,{label:o("devStudio.scripts.name","Name"),value:m,onChange:c,onKeyDown:K=>{K.key==="Enter"&&x()},size:"sm","data-testid":"studio-script-add-name"}),w.length>1&&t.jsx(h.NiceSelect,{label:o("devStudio.scripts.language","Language"),value:v&&w.includes(v)?v:w[0],options:w.map(K=>({value:K,label:Ht[K]??K})),onChange:K=>S(String(K)),size:"sm"}),t.jsx(Qt,{value:p,onChange:l,categories:I}),((F=i.scripts)==null?void 0:F.triggers)&&i.scripts.triggers.length>0&&t.jsx(h.NiceSelect,{label:o("devStudio.scripts.trigger","Runs on"),value:g,options:[{value:"",label:o("devStudio.scripts.trigger.none","When called")},...i.scripts.triggers.map(K=>({value:K.id,label:K.label}))],onChange:K=>f(String(K)),size:"sm"})]})]})})}function $t(e){var m,c,p;const{module:i,doc:n,preset:s,session:o,locales:a,readOnly:d}=e,r=Z(i,n),u=l=>o.setDraft(i.key,n.key,l);switch(n.kind.editor){case"manifest":return t.jsx(ln,{...e});case"i18n":{const l=r??{};return t.jsx(vt,{value:l,onChange:u,locales:[...new Set([...a,...Object.keys(l)])],allowEditLocales:!0,allowEditKeys:!0,highlightMissing:!0,readOnly:d})}case"permissions":return t.jsx(un,{value:r??{permissions:[],groups:[]},onChange:u,readOnly:d});case"seeds":return t.jsx(hn,{value:r??{seeds:{}},onChange:u,entities:Te(i),readOnly:d});case"rbac":return t.jsx(h.NiceAccessManager,{value:r,onChange:u,readOnly:d});case"hooks":return t.jsx(h.NiceLifecycleHooksEditor,{triggers:((m=s.hooks)==null?void 0:m.triggers)??[],handlers:(c=s.hooks)==null?void 0:c.handlers,bindings:r??[],onChange:u,groupByTrigger:!0,allowCondition:!0,readOnly:d});case"script":return e.scriptRunner?t.jsx(h.NiceScriptRunner,{...e.scriptRunner,value:String(r??""),onChange:u}):t.jsx(h.NiceSimpleCodeEditor,{value:String(r??""),onChange:u,language:"javascript",height:"100%",lineNumbers:!0,readOnly:d});case"scriptList":return t.jsx(cn,{value:r??{scripts:[]},onChange:u,preset:s,readOnly:d});case"text":return t.jsx(h.NiceSimpleCodeEditor,{value:String(r??""),onChange:u,height:"100%",lineNumbers:!0,readOnly:d});default:{const l=(p=e.editors)==null?void 0:p[n.kind.editor];return l?t.jsx("div",{className:"nice-development-studio__plugin",children:l.render({value:r,onChange:u,readOnly:d,module:{workspaceId:i.key.workspaceId,id:i.key.id,label:i.key.id},files:i.working,services:e.editorServices??{}})}):t.jsx(Re,{value:r,onChange:u,readOnly:d,height:"100%",label:n.label})}}}function ln({module:e,doc:i,preset:n,session:s,readOnly:o,advanced:a}){var I;const{t:d}=h.useNiceTranslation(),r=Z(e,i),u=_.useMemo(()=>r??{},[r]),m=w=>s.setDraft(e.key,i.key,w),c=n.manifestSections,p=_.useMemo(()=>(c??[]).map(w=>T.fitManifestSection(w,u)),[c,u]),l=c??[],g=_.useMemo(()=>new Set(p.flatMap(w=>w.keys)),[p]),f=Object.keys(u).filter(w=>!g.has(w)),[v,S]=_.useState(((I=p[0])==null?void 0:I.section.id)??"__other"),y=p.find(w=>w.section.id===v),b=a?t.jsx(Re,{value:Object.fromEntries(f.map(w=>[w,u[w]])),readOnly:o,label:d("devStudio.manifest.other","Other properties"),onChange:w=>{if(w&&typeof w=="object"&&!Array.isArray(w)){const k=Object.fromEntries(Object.entries(u).filter(([x])=>g.has(x)));m({...k,...w})}}}):t.jsxs("div",{className:"nice-development-studio__note",children:[t.jsx("p",{children:d("devStudio.manifest.kept","These properties have no form here. Saving keeps them exactly as they are; switch to the advanced mode to edit them.")}),t.jsx("ul",{className:"nice-development-studio__chips",children:f.map(w=>t.jsx("li",{className:"nice-development-studio__tag",children:w},w))})]});return t.jsxs("div",{className:"nice-development-studio__sections","data-testid":"studio-manifest-form",children:[t.jsxs("nav",{className:"nice-development-studio__section-nav","aria-label":d("devStudio.manifest.sections","Sections"),children:[p.map(({section:w})=>t.jsx(h.NiceButton,{size:"sm",variant:v===w.id?"primary":"ghost","aria-pressed":v===w.id,onClick:()=>S(w.id),children:w.title},w.id)),f.length>0&&t.jsx(h.NiceButton,{size:"sm",variant:v==="__other"?"primary":"ghost","aria-pressed":v==="__other",onClick:()=>S("__other"),children:`${d("devStudio.manifest.other","Other properties")} (${f.length})`})]}),t.jsx("div",{className:"nice-development-studio__section-body",children:y?t.jsx(Ee,{schema:y.section.schema,fields:y.section.fields,uiSchema:y.section.uiSchema,value:Object.fromEntries(y.keys.filter(w=>w in u).map(w=>[w,u[w]])),onChange:w=>{const k={...u};for(const x of y.keys)w[x]===void 0?delete k[x]:k[x]=w[x];m(k)},readOnly:o}):f.length>0||l.length===0?b:null})]})}function un({value:e,onChange:i,readOnly:n}){const{t:s}=h.useNiceTranslation(),o={code:s("devStudio.permissions.code","Code"),name:s("devStudio.permissions.name","Name"),description:s("devStudio.permissions.description","Description")},a=_.useMemo(()=>{const r={};for(const u of e.groups)for(const m of u.permissions)r[`${u.id}:${m}`]=!0;return r},[e.groups]),d=(r,u)=>{const m=e.permissions[r],c={...m,...u};i({permissions:e.permissions.map((p,l)=>l===r?c:p),groups:u.code!==void 0&&u.code!==m.code?e.groups.map(p=>({...p,permissions:p.permissions.map(l=>l===m.code?c.code:l)})):e.groups})};return t.jsxs("div",{className:"nice-development-studio__permissions",children:[t.jsx("h4",{children:s("devStudio.permissions.codes","Permissions")}),t.jsxs("table",{className:"nice-development-studio__table",children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:o.code}),t.jsx("th",{children:o.name}),t.jsx("th",{children:o.description}),!n&&t.jsx("th",{"aria-label":s("devStudio.delete","Delete")})]})}),t.jsx("tbody",{children:e.permissions.map((r,u)=>t.jsxs("tr",{children:[["code","name","description"].map(m=>t.jsx("td",{children:t.jsx("input",{className:"nice-development-studio__cell",value:r[m]??"",readOnly:n,"aria-label":`${o[m]} ${r.code}`,onChange:c=>d(u,{[m]:c.target.value})})},m)),!n&&t.jsx("td",{children:t.jsx(h.NiceButton,{size:"sm",variant:"ghost",ariaLabel:`${s("devStudio.delete","Delete")} ${r.code}`,onClick:()=>i({permissions:e.permissions.filter((m,c)=>c!==u),groups:e.groups.map(m=>({...m,permissions:m.permissions.filter(c=>c!==r.code)}))}),children:t.jsx(h.NiceIcon,{name:"trash",size:14})})})]},u))})]}),!n&&t.jsxs("div",{className:"nice-development-studio__row",children:[t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:()=>i({...e,permissions:[...e.permissions,{code:`New.Permission${e.permissions.length+1}`}]}),children:s("devStudio.permissions.addCode","New permission")}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:()=>i({...e,groups:[...e.groups,{id:`group${e.groups.length+1}`,label:s("devStudio.permissions.newGroup","Group {n}").replace("{n}",String(e.groups.length+1)),permissions:[]}]}),children:s("devStudio.permissions.addGroup","New group")})]}),t.jsx("h4",{children:s("devStudio.permissions.groups","Groups")}),t.jsx(h.NicePermissionMatrix,{roles:e.groups.map(r=>({id:r.id,label:r.label})),actions:e.permissions.map(r=>({id:r.code,label:r.name||r.code})),value:a,readOnly:n,showBulkActions:!0,onChange:r=>i({...e,groups:e.groups.map(u=>({...u,permissions:e.permissions.map(m=>m.code).filter(m=>r[`${u.id}:${m}`]===!0)}))})})]})}const Kt=e=>e===null||typeof e!="object";function mn(e){const i=e.toLowerCase();return/(int|long|decimal|double|float|number|money)/.test(i)?"number":/bool/.test(i)?"boolean":"string"}function pn(e,i){const n={},s=Array.isArray(i==null?void 0:i.fields)?i.fields:[];for(const o of s){const a=String(o.name??"");a&&e.every(d=>Kt(d[a]))&&(n[a]={type:mn(String(o.dataType??o.type??"string")),title:String(o.displayName||a)})}for(const o of e)for(const[a,d]of Object.entries(o))!(a in n)&&e.every(r=>Kt(r[a]))&&(n[a]={type:typeof d=="number"?"number":typeof d=="boolean"?"boolean":"string",title:a});return{type:"object",properties:n}}function hn({value:e,onChange:i,entities:n,readOnly:s}){const{t:o}=h.useNiceTranslation(),a=r=>n.find(u=>u.name===r||u.tableName===r),d=r=>{const u=e[r]??{},m=Object.keys(u);return m.length===0?t.jsx("p",{className:"nice-development-studio__muted",children:o("devStudio.seeds.empty","No rows.")}):t.jsx(h.NiceTabs,{tabs:m.map(c=>{const p=u[c];return{id:c,label:`${c} (${p.length})`,content:t.jsx(dt,{value:p,itemSchema:pn(p,a(c)),title:c,readOnly:s,onChange:l=>{const g=l.length===p.length?l.map((f,v)=>f===p[v]?f:{...p[v],...f}):l;i({...e,[r]:{...u,[c]:g}})}})}})})};return t.jsx(h.NiceTabs,{tabs:[{id:"seeds",label:o("devStudio.seeds.data","Data"),content:d("seeds")},{id:"demo",label:o("devStudio.seeds.demo","Demo data"),content:d("demoSeeds")}]})}function vn({module:e,path:i,session:n,readOnly:s}){var c;const{t:o}=h.useNiceTranslation(),[a,d]=_.useState("source"),r=e.changes.find(p=>p.path===i),u=e.documents.filter(p=>p.paths.includes(i)).map(p=>p.key),m=((c=e.files.find(p=>p.path===i))==null?void 0:c.text)??"";return t.jsxs("div",{className:"nice-development-studio__source","data-testid":"studio-file-source",children:[t.jsx("div",{className:"nice-development-studio__row",children:t.jsxs("div",{className:"nice-development-studio__segmented",role:"group","aria-label":o("devStudio.doc.mode","Show"),children:[t.jsx(h.NiceButton,{size:"sm",variant:a==="source"?"primary":"ghost","aria-pressed":a==="source",onClick:()=>d("source"),children:o("devStudio.doc.source","Source")}),t.jsx(h.NiceButton,{size:"sm",variant:a==="changes"?"primary":"ghost","aria-pressed":a==="changes",onClick:()=>d("changes"),children:`${o("devStudio.doc.changes","Changes")}${r?" (1)":""}`})]})}),a==="source"?t.jsx(h.NiceSimpleCodeEditor,{value:e.pending.get(i)??"",language:i.endsWith(".json")?"json":i.endsWith(".js")?"javascript":"plaintext",height:"100%",lineNumbers:!0,readOnly:s,onChange:p=>n.setRaw(e.key,i,T.keepTextFormat(p,e.pending.get(i)),u)}):r?t.jsx(Dt,{before:m,after:r.type==="write"?r.text:""}):t.jsx("p",{className:"nice-development-studio__muted",children:o("devStudio.diff.none","No changes.")})]})}const fn=e=>({type:"object",required:["id"],properties:{id:{type:"string",title:e("devStudio.template.id","Id (slug)")},category:{type:"string",title:e("devStudio.template.category","Category")},subCategory:{type:"string",title:e("devStudio.template.subCategory","Subcategory")},parentId:{type:"string",title:e("devStudio.template.parent","Parent template")},icon:{type:"string",title:e("devStudio.template.icon","Icon")},sortOrder:{type:"number",title:e("devStudio.template.sortOrder","Order")},tags:{type:"array",items:{type:"string"},title:e("devStudio.template.tags","Tags")}}});function gn({session:e,template:i,locales:n,extraSchema:s,readOnly:o,onSaved:a,onDeleted:d}){var w;const{t:r}=h.useNiceTranslation(),[u,m]=_.useState(()=>i??{id:"",translations:{[n[0]??"en"]:{name:""}},modules:[]}),[c,p]=_.useState(null),l=o||!!(i!=null&&i.readOnly),g={id:u.id,category:u.category,subCategory:u.subCategory,parentId:u.parentId,icon:u.icon,sortOrder:u.sortOrder,tags:u.tags},f=Object.fromEntries(Object.entries(u.translations).map(([k,x])=>[k,{name:x.name,description:x.description??""}])),v=_.useMemo(()=>e.workspaces.map(k=>{const x=e.modulesByWs[k.id]??[],j=[...new Set(x.map(N=>N.packageId??""))].sort();return{id:`w:${k.id}`,label:k.label,kind:"workspace",children:j.map(N=>({id:`w:${k.id}/p:${N}`,label:N||r("devStudio.explorer.noPackage","No package"),kind:"package",children:x.filter(P=>(P.packageId??"")===N).map(P=>({id:`m:${P.id}`,label:P.label,kind:"module"}))}))}}),[e.workspaces,e.modulesByWs,r]),S=_.useMemo(()=>{const k=new Map;for(const x of Object.values(e.modulesByWs))for(const j of x)k.set(j.id,j.label);return k},[e.modulesByWs]),y=k=>m({...u,modules:k}),b=(k,x)=>{const j=[...u.modules],[N]=j.splice(k,1);j.splice(k+x,0,N),y(j)},I=[{field:"label",header:r("devStudio.explorer.name","Name")}];return t.jsxs("div",{className:"nice-development-studio__template","data-testid":"studio-template-editor",children:[t.jsxs("div",{className:"nice-development-studio__doc-bar",children:[t.jsx(h.NiceIcon,{name:"layers",size:14}),t.jsx("strong",{className:"nice-development-studio__doc-title",children:i?((w=u.translations.en)==null?void 0:w.name)||u.id:r("devStudio.template.new","New template")}),t.jsx("span",{className:"nice-development-studio__spacer"}),!l&&t.jsx(h.NiceButton,{size:"sm",variant:"primary",disabled:!u.id.trim(),onClick:async()=>{p(null);const k=await e.saveTemplate({...u,id:u.id.trim()},i==null?void 0:i.id);k?a==null||a(k):p(r("devStudio.template.saveFailed","The template could not be saved; see the output panel."))},children:r("devStudio.save","Save")}),!l&&i&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"trash",size:14}),onClick:async()=>{await e.deleteTemplate(i.id)&&(d==null||d())},children:r("devStudio.delete","Delete")})]}),c&&t.jsx("p",{className:"nice-development-studio__error",role:"alert",children:c}),t.jsxs("div",{className:"nice-development-studio__columns",children:[t.jsxs("section",{children:[t.jsx("h4",{children:r("devStudio.template.basics","Template")}),t.jsx(Ee,{schema:fn(r),value:g,readOnly:l,onChange:k=>m({...u,id:String(k.id??""),category:k.category||void 0,subCategory:k.subCategory||void 0,parentId:k.parentId||void 0,icon:k.icon||void 0,sortOrder:typeof k.sortOrder=="number"?k.sortOrder:void 0,tags:Array.isArray(k.tags)?k.tags:void 0})}),s&&t.jsx(Ee,{schema:s,value:u.extra??{},readOnly:l,onChange:k=>m({...u,extra:k})}),t.jsx("h4",{children:r("devStudio.template.translations","Name and description")}),t.jsx(vt,{value:f,locales:[...new Set([...n,...Object.keys(f)])],allowEditLocales:!0,readOnly:l,onChange:k=>m({...u,translations:Object.fromEntries(Object.entries(k).map(([x,j])=>[x,{name:j.name??"",...j.description?{description:j.description}:{}}]))})})]}),t.jsxs("section",{children:[t.jsx("h4",{children:r("devStudio.template.modules","Modules")}),t.jsx(h.NiceTreeGrid,{data:v,nested:!0,keyField:"id",childrenField:"children",columns:I,sortable:!1,compact:!0,checkable:!0,checkStrategy:"leaves",isRowCheckable:k=>k.kind!=="workspace",isRowDisabled:()=>l,checkedKeys:u.modules.map(k=>`m:${k.moduleId}`),onCheckedChange:k=>{const x=k.filter(P=>P.startsWith("m:")).map(P=>P.slice(2)),j=u.modules.filter(P=>x.includes(P.moduleId)),N=x.filter(P=>!j.some(F=>F.moduleId===P)).map(P=>({moduleId:P}));y([...j,...N])},checkedSummary:k=>r("devStudio.template.summary","{count} modules · {required} required").replace("{count}",String(k.checked)).replace("{required}",String(u.modules.filter(x=>x.required).length)),searchable:!0,searchFields:["label"],virtualScroll:!0,height:320,"aria-label":r("devStudio.template.modules","Modules")}),t.jsxs("table",{className:"nice-development-studio__table",children:[t.jsx("thead",{children:t.jsxs("tr",{children:[t.jsx("th",{children:r("devStudio.template.module","Module")}),t.jsx("th",{children:r("devStudio.template.required","required")}),t.jsx("th",{children:r("devStudio.template.condition","Condition")}),!l&&t.jsx("th",{"aria-label":r("devStudio.template.order","Order")})]})}),t.jsx("tbody",{children:u.modules.map((k,x)=>t.jsxs("tr",{children:[t.jsx("td",{children:S.get(k.moduleId)??k.moduleId}),t.jsx("td",{children:t.jsx("input",{type:"checkbox",checked:!!k.required,disabled:l,"aria-label":`${r("devStudio.template.required","required")} ${k.moduleId}`,onChange:j=>y(u.modules.map((N,P)=>P===x?{...N,required:j.target.checked}:N))})}),t.jsx("td",{children:t.jsx("input",{className:"nice-development-studio__cell",value:k.condition??"",readOnly:l,"aria-label":`${r("devStudio.template.condition","Condition")} ${k.moduleId}`,onChange:j=>y(u.modules.map((N,P)=>P===x?{...N,condition:j.target.value||void 0}:N))})}),!l&&t.jsxs("td",{className:"nice-development-studio__nowrap",children:[t.jsx(h.NiceButton,{size:"sm",variant:"ghost",disabled:x===0,ariaLabel:r("devStudio.template.up","Move up"),onClick:()=>b(x,-1),children:t.jsx(h.NiceIcon,{name:"chevron-up",size:12})}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",disabled:x===u.modules.length-1,ariaLabel:r("devStudio.template.down","Move down"),onClick:()=>b(x,1),children:t.jsx(h.NiceIcon,{name:"chevron-down",size:12})})]})]},k.moduleId))})]})]})]})]})}function yn({session:e,pkg:i,readOnly:n,onNewModule:s,onOpenModule:o}){const{t:a}=h.useNiceTranslation(),[d,r]=_.useState({id:i.id,label:i.label,description:i.description,icon:i.icon}),u=(e.modulesByWs[i.workspaceId]??[]).filter(c=>c.packageId===i.id),m=!n&&!i.derived&&!i.readOnly;return t.jsxs("div",{className:"nice-development-studio__template","data-testid":"studio-package-editor",children:[t.jsxs("div",{className:"nice-development-studio__doc-bar",children:[t.jsx(h.NiceIcon,{name:"archive",size:14}),t.jsx("strong",{className:"nice-development-studio__doc-title",children:i.label||i.id}),t.jsx("span",{className:"nice-development-studio__spacer"}),!n&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:s,children:a("devStudio.package.newModule","New module here")}),m&&t.jsx(h.NiceButton,{size:"sm",variant:"primary",onClick:()=>void e.savePackage({...i,id:String(d.id??i.id),label:String(d.label??""),description:d.description||void 0,icon:d.icon||void 0}),children:a("devStudio.save","Save")})]}),i.derived?t.jsx("p",{className:"nice-development-studio__muted",children:a("devStudio.package.derived","This package comes from the modules themselves (their category); rename it by changing their manifests.")}):t.jsx(Ee,{schema:{type:"object",required:["id","label"],properties:{id:{type:"string",title:a("devStudio.package.id","Id")},label:{type:"string",title:a("devStudio.package.label","Name")},description:{type:"string",title:a("devStudio.package.description","Description")},icon:{type:"string",title:a("devStudio.template.icon","Icon")}}},value:d,readOnly:!m,onChange:c=>r(c)}),t.jsx("h4",{children:a("devStudio.template.modules","Modules")}),t.jsxs("ul",{className:"nice-development-studio__list",children:[u.map(c=>t.jsxs("li",{children:[t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"box",size:14}),onClick:()=>o(c.id),children:c.label}),c.description&&t.jsx("span",{className:"nice-development-studio__muted",children:c.description})]},c.id)),u.length===0&&t.jsx("li",{className:"nice-development-studio__muted",children:a("devStudio.explorer.empty","No modules.")})]})]})}const Sn=e=>"module"in e?e.module:void 0;function kn(e){const{screen:i,crumbs:n,session:s,readOnly:o,tutorialButton:a,onBack:d,onSave:r}=e,{t:u}=h.useNiceTranslation(),m=Sn(i),c=m?s.modules[Y(m)]:void 0,p=o(m),l=bn(i,c,s);return t.jsxs("div",{className:"nice-development-studio__edit","data-testid":"studio-edit-screen",children:[t.jsxs("header",{className:"nice-development-studio__edit-header",children:[t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"arrow-left",size:14}),onClick:d,"data-testid":"studio-back",children:u("devStudio.edit.back","Back")}),t.jsx(h.NiceBreadcrumb,{className:"nice-development-studio__crumbs",size:"sm",separator:"›",items:n}),t.jsx("span",{className:"nice-development-studio__spacer"}),l&&!p&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"trash",size:14}),onClick:()=>{l(),d()},children:u("devStudio.delete","Delete")}),c&&t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"check",size:14}),onClick:()=>void s.validate(c.key),children:u("devStudio.validate","Validate")}),!p&&t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{size:"sm",variant:"ghost",disabled:!c.dirty,onClick:()=>s.discard(c.key),children:u("devStudio.discard","Discard changes")}),t.jsx(h.NiceButton,{size:"sm",variant:"primary",disabled:!c.dirty,onClick:()=>r(c.key),"data-tour":"devstudio-save",children:c.dirty?u("devStudio.saveCount","Save ({count})").replace("{count}",String(c.changes.length)):u("devStudio.save","Save")})]})]}),a]}),t.jsx("div",{className:"nice-development-studio__edit-body",children:t.jsx(jn,{...e,module:c,readOnlyHere:p})})]})}function bn(e,i,n){if(!i||e.kind!=="entity"&&e.kind!=="item"||e.kind==="item"&&e.docKey===ze)return;const s=he(i,e.docKey);if(!s)return;if(e.kind==="entity"){const a=Z(i,s);return Array.isArray(a)?()=>n.setDraft(i.key,s.key,pt(a,e.index,null)):void 0}if(e.group==="dataSources"){const a=Z(i,s)??[],d=de(i,s).findIndex(r=>r.key===e.itemKey);return d<0?void 0:()=>n.setDraft(i.key,s.key,a.filter((r,u)=>u!==d))}const o=de(i,s);return()=>n.setDraft(i.key,s.key,ht(i,s,Wt(o,e.itemKey,null)))}function xn(e,i){return Object.values(i.modules).filter(n=>Y(n.key)!==Y(e.key)).flatMap(n=>T.entitiesToSchemas(Te(n)).map(s=>({...s,schema:n.key.id})))}function me(){const{t:e}=h.useNiceTranslation();return t.jsx("p",{className:"nice-development-studio__muted",children:e("devStudio.edit.gone","This is no longer in the module.")})}function jn(e){var c,p,l,g,f;const{screen:i,module:n,session:s,preset:o,provider:a,locales:d,advanced:r,readOnlyHere:u}=e,{t:m}=h.useNiceTranslation();if(i.kind==="package")return t.jsx(yn,{session:s,pkg:i.pkg,readOnly:e.readOnly(),onNewModule:()=>e.onNewModule({workspaceId:i.pkg.workspaceId,packageId:i.pkg.id}),onOpenModule:v=>e.onReveal({kind:"module",module:{workspaceId:i.pkg.workspaceId,id:v}})});if(i.kind==="template"){const v=i.templateId?(c=s.templates)==null?void 0:c.find(S=>S.id===i.templateId):void 0;return t.jsx(gn,{session:s,template:v,locales:d,extraSchema:o.templateSchema,readOnly:e.readOnly(),onSaved:S=>{S.id!==i.templateId&&e.onScreen({kind:"template",templateId:S.id})},onDeleted:e.onBack},i.templateId??"new")}if(!n)return t.jsx("p",{className:"nice-development-studio__muted",children:m("devStudio.loading","Loading…")});switch(i.kind){case"manifest":{const v=n.documents.find(S=>S.kind.editor==="manifest");return v?t.jsx($t,{module:n,doc:v,preset:o,session:s,locales:d,readOnly:u,advanced:r,scriptRunner:e.scriptRunner,editors:e.editors,editorServices:e.editorServices}):t.jsx(me,{})}case"entity":{const v=he(n,i.docKey),S=v?Z(n,v):void 0,y=Array.isArray(S)?S[i.index]:void 0;return!v||!S||!y?t.jsx(me,{}):t.jsx(rt,{value:y,onChange:b=>s.setDraft(n.key,v.key,pt(S,i.index,b)),entityMetaSchema:(p=o.entities)==null?void 0:p.entityMetaSchema,fieldSchema:(l=o.entities)==null?void 0:l.fieldSchema,fieldsKey:(g=o.entities)==null?void 0:g.fieldsKey,readOnly:u,"data-testid":"studio-entity-form"})}case"item":return t.jsx(Nn,{...e,screen:i,module:n});case"document":{const v=he(n,i.docKey);return v?t.jsx($t,{module:n,doc:v,preset:o,session:s,locales:d,readOnly:u,advanced:r,scriptRunner:e.scriptRunner,editors:e.editors,editorServices:e.editorServices}):t.jsx(me,{})}case"panel":{const v=(f=e.modulePanels)==null?void 0:f.call(e,{module:n.key,files:n.working,dirty:n.dirty}).find(S=>S.key===i.panelKey);return v?t.jsx(t.Fragment,{children:v.content}):t.jsx(me,{})}case"file":return n.working.some(v=>v.path===i.path)?t.jsx(vn,{module:n,path:i.path,session:s,readOnly:u}):t.jsx(me,{});case"problems":return t.jsx(wn,{module:n,issues:e.issues(n.key),onReveal:e.onReveal});case"history":return t.jsx(_n,{module:n,provider:a,session:s,readOnly:u})}}function Nn({screen:e,module:i,session:n,preset:s,readOnlyHere:o,advanced:a,scriptRunner:d,scriptIo:r,previewDataSource:u,renderViewPreview:m,onScreen:c}){const{t:p}=h.useNiceTranslation();if(e.docKey===ze){const b=mt(i).find(I=>I.key===e.itemKey);return b?t.jsxs("div",{className:"nice-development-studio__standard-source",children:[t.jsxs("div",{className:"nice-development-studio__note",children:[t.jsx("p",{children:p("devStudio.dataSources.standardNote","A standard source: every entity has it, nobody edits it. Duplicate it to start one of your own.")}),!o&&t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:t.jsx(h.NiceIcon,{name:"copy",size:14}),onClick:()=>{const I=Gt(i,s,n,{...b,key:`${b.key}Copy`,label:`${b.label??b.key} (${p("devStudio.dataSources.copy","copy")})`});I&&c(I)},"data-testid":"studio-duplicate-source",children:p("devStudio.dataSources.duplicate","Duplicate")})]}),t.jsx(h.NiceDataSourceEditor,{value:b,schemas:T.entitiesToSchemas(Te(i)),onPreview:u?(I,w)=>u(i.key,I,w):void 0,readOnly:!0})]}):t.jsx(me,{})}const l=he(i,e.docKey);if(!l)return t.jsx(me,{});if(e.group==="dataSources"){const b=Z(i,l)??[],I=de(i,l).findIndex(x=>x.key===e.itemKey),w=b[I];if(I<0)return t.jsx(me,{});const k=x=>n.setDraft(i.key,l.key,b.map((j,N)=>N===I?x:j));return h.isModuleDataSource(w)?t.jsx(h.NiceDataSourceEditor,{value:w,schemas:T.entitiesToSchemas(Te(i)),extraSchemas:xn(i,n),sources:Vi(i),onPreview:u?(x,j)=>u(i.key,x,j):void 0,readOnly:o,onChange:x=>{k(x),x.key!==w.key&&c({...e,itemKey:x.key})}}):t.jsxs("div",{className:"nice-development-studio__source",children:[t.jsx("p",{className:"nice-development-studio__muted",children:p("devStudio.items.rawReason","The editor does not know this shape, so it is edited as JSON.")}),t.jsx(Re,{value:w,readOnly:o,label:e.itemKey,height:"100%",onChange:k})]})}const g=de(i,l),f=g.find(b=>b.key===e.itemKey);if(!f)return t.jsx(me,{});const v=b=>{n.setDraft(i.key,l.key,ht(i,l,Wt(g,f.key,b))),b.key!==f.key&&c({...e,itemKey:b.key})},S=b=>v({...f,definition:b,label:b.name||f.label,key:b.id&&!g.some(I=>I!==f&&I.key===b.id)?b.id:f.key});if(f.definition===void 0)return a?t.jsxs("div",{className:"nice-development-studio__source",children:[t.jsxs("p",{className:"nice-development-studio__muted",children:[p("devStudio.items.rawReason","The editor does not know this shape, so it is edited as JSON."),f.rawReason?` (${f.rawReason})`:""]}),t.jsx(Re,{value:f.source,readOnly:o,label:f.label,height:"100%",onChange:b=>v({...f,source:b})})]}):t.jsx("p",{className:"nice-development-studio__muted",children:p("devStudio.preview.noDesigner","There is no designer for this kind of entry yet.")});if(e.group==="scripts")return t.jsx(rn,{module:i,doc:l,item:f,preset:s,session:n,readOnly:o,scriptRunner:d,scriptIo:r==null?void 0:r(i.key),onRenamed:b=>c({...e,itemKey:b})});if(e.group==="workflows")return t.jsx(pi.NiceWorkflowDesigner,{workflow:f.definition,onChange:b=>S(b),readOnly:o});const y=t.jsx(h.NiceViewEditor,{value:f.definition,onChange:b=>S(b),entities:Te(i),dataSourceOptions:i.documents.filter(b=>b.kind.editor==="dataSources").flatMap(b=>Z(i,b)??[]).filter(h.isModuleDataSource).map(b=>({key:b.key,label:b.label})),height:640});return m?t.jsx(h.NiceTabs,{tabs:[{id:"design",label:p("devStudio.view.design","Design"),content:y},{id:"preview",label:p("devStudio.view.hostPreview","Preview in the app"),content:m({module:i.key,item:f,files:i.working})}]}):y}function wn({module:e,issues:i,onReveal:n}){const{t:s}=h.useNiceTranslation();return i.length===0?t.jsx("p",{className:"nice-development-studio__muted",children:s("devStudio.overview.noProblems","No problems found.")}):t.jsx("ul",{className:"nice-development-studio__issues","data-testid":"studio-problems",children:i.map((o,a)=>t.jsxs("li",{className:`nice-development-studio__issue nice-development-studio__issue--${o.severity}`,children:[t.jsx(h.NiceIcon,{name:o.severity==="error"?"error":o.severity==="warning"?"warning":"info",size:14}),t.jsx("span",{children:ii(s,o)}),o.path&&t.jsx("span",{className:"nice-development-studio__muted",children:o.path}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",onClick:()=>n(Ut(e,o)),children:s("devStudio.problems.goTo","Go to")})]},a))})}function ii(e,i){return i.messageKey?Object.entries(i.params??{}).reduce((n,[s,o])=>n.replace(`{${s}}`,String(o)),e(i.messageKey,i.message)):i.message}function _n({module:e,provider:i,session:n,readOnly:s}){const[o,a]=_.useState(null),d=e.key;return _.useEffect(()=>{let r=!0;return i!=null&&i.listRevisions&&i.listRevisions(d).then(u=>{r&&a(u.map(m=>({id:m.id,label:m.label,author:m.author,timestamp:m.timestamp,summary:m.summary})))}).catch(()=>a([])),()=>{r=!1}},[i,d,e.files]),t.jsx(h.NiceRevisionHistory,{revisions:o??[],language:"json",loadContent:i!=null&&i.readRevision?r=>i.readRevision(d,r):void 0,onRollback:i!=null&&i.rollback&&!s?async r=>{await i.rollback(d,r),await n.reload(d)}:void 0})}function In({prompt:e,onClose:i}){const{t:n}=h.useNiceTranslation(),[s,o]=_.useState(e.initial),a=()=>{s.trim()&&(i(),e.onSubmit(s.trim()))};return t.jsx(h.NiceModal,{open:!0,onClose:i,title:e.title,footer:t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{variant:"ghost",onClick:i,children:n("devStudio.cancel","Cancel")}),t.jsx(h.NiceButton,{variant:"primary",disabled:!s.trim(),onClick:a,children:n("devStudio.ok","OK")})]}),children:t.jsx("div",{className:"nice-development-studio__form",children:t.jsx(h.NiceTextInput,{label:n("devStudio.package.label","Name"),value:s,onChange:o,onKeyDown:d=>{d.key==="Enter"&&a()},"data-testid":"studio-layout-name"})})})}function Cn(e,i){const{t:n}=h.useNiceTranslation(),[s,o]=_.useState(null),a=_.useCallback((r,u)=>{var g;const m=e.modules[Y(r)];if(!m)return;const c=T.studioLayoutPath(m.working),p=(g=m.working.find(f=>f.path===c))==null?void 0:g.text,l=u(T.parseStudioLayout(p));if(T.isEmptyStudioLayout(l)){p!==void 0&&e.deleteFile(r,c);return}e.setRaw(r,c,T.serializeStudioLayout(l,p))},[e]);return{menuFor:_.useCallback(r=>{const u=r.node,m=Fe(u),c=m?e.modules[Y(m)]:void 0;if(!m||!c||i(m))return;const p=Jt(c),l=(y,b,I)=>o({title:y,initial:b,onSubmit:I}),g=n("devStudio.layout.newFolder","New folder"),f=(y,b,I)=>({id:"new-folder",icon:"folder",label:g,onSelect:()=>l(g,"",w=>a(m,k=>T.addStudioFolder(k,{label:w,group:y,parent:b,section:I}).layout))}),v=[];switch(u.kind){case"module":v.push({id:"new-section",icon:"layers",label:n("devStudio.layout.newSection","New section"),onSelect:()=>l(n("devStudio.layout.newSection","New section"),"",y=>a(m,b=>T.addStudioSection(b,y).layout))});break;case"group":u.group!=="files"&&v.push(f(u.group,void 0,u.section));break;case"section":v.push({id:"rename",icon:"edit",label:n("devStudio.layout.renameSection","Rename section"),onSelect:()=>l(n("devStudio.layout.renameSection","Rename section"),r.label,y=>a(m,b=>T.renameStudioLayoutNode(b,{kind:"section",id:u.sectionId},y)))},{id:"delete",icon:"trash",danger:!0,label:n("devStudio.layout.deleteSection","Delete section"),onSelect:()=>a(m,y=>T.removeStudioLayoutNode(y,{kind:"section",id:u.sectionId}))});break;case"folder":{const y=p.folders.find(b=>b.id===u.folderId);v.push(f(u.group,u.folderId,y==null?void 0:y.section),{id:"rename",icon:"edit",label:n("devStudio.layout.renameFolder","Rename folder"),onSelect:()=>l(n("devStudio.layout.renameFolder","Rename folder"),r.label,b=>a(m,I=>T.renameStudioLayoutNode(I,{kind:"folder",id:u.folderId},b)))},{id:"delete",icon:"trash",danger:!0,label:n("devStudio.layout.deleteFolder","Delete folder"),onSelect:()=>a(m,b=>T.removeStudioLayoutNode(b,{kind:"folder",id:u.folderId}))});break}}const S=r.ref;if(S){const y=S.slice(0,S.indexOf(":")),b=p.placement[S],I=[{id:"move-new-folder",icon:"folder",label:n("devStudio.layout.moveToNewFolder","Move to a new folder…"),onSelect:()=>l(g,"",w=>a(m,k=>{const x=T.addStudioFolder(k,{label:w,group:y,section:b==null?void 0:b.section});return T.placeStudioEntry(x.layout,S,{folder:x.id})}))},...p.folders.filter(w=>w.group===y&&w.id!==(b==null?void 0:b.folder)).map(w=>({id:`move-folder-${w.id}`,icon:"folder",label:n("devStudio.layout.moveToFolder","Move to folder: {name}").replace("{name}",w.label),onSelect:()=>a(m,k=>T.placeStudioEntry(k,S,{folder:w.id}))})),...p.sections.filter(w=>w.id!==(b==null?void 0:b.section)||!!(b!=null&&b.folder)).map(w=>({id:`move-section-${w.id}`,icon:"layers",label:n("devStudio.layout.moveToSection","Move to section: {name}").replace("{name}",w.label),onSelect:()=>a(m,k=>T.placeStudioEntry(k,S,{section:w.id}))}))];(b!=null&&b.folder||b!=null&&b.section)&&I.push({id:"move-back",icon:"arrow-left",label:n("devStudio.layout.moveBack","Move back to its group"),onSelect:()=>a(m,w=>T.placeStudioEntry(w,S,{}))}),v.length&&v.push({id:"divider",divider:!0}),v.push(...I)}return v.length?v:void 0},[e.modules,i,a,n]),dialog:s?t.jsx(In,{prompt:s,onClose:()=>o(null)}):null}}function ie({icon:e,title:i,subtitle:n,badges:s,actions:o,children:a}){return t.jsxs("section",{className:"nice-development-studio__preview","data-testid":"studio-preview",children:[t.jsxs("div",{className:"nice-development-studio__preview-info",children:[t.jsxs("header",{className:"nice-development-studio__preview-head",children:[t.jsx(h.NiceIcon,{name:e,size:20}),t.jsxs("div",{className:"nice-development-studio__preview-name",children:[t.jsx("h3",{className:"nice-development-studio__preview-title",children:i}),n&&t.jsx("span",{className:"nice-development-studio__muted",children:n})]})]}),s&&t.jsx("div",{className:"nice-development-studio__preview-badges",children:s}),a]}),o&&t.jsx("footer",{className:"nice-development-studio__preview-actions",children:o})]})}function ce({items:e}){const i=e.filter(([,n])=>n!=null&&n!=="");return i.length===0?null:t.jsx("dl",{className:"nice-development-studio__facts",children:i.map(([n,s])=>t.jsxs("div",{className:"nice-development-studio__fact",children:[t.jsx("dt",{children:n}),t.jsx("dd",{children:s})]},n))})}function Ne({rows:e,onSelect:i,limit:n=12}){const{t:s}=h.useNiceTranslation();return e.length===0?null:t.jsxs("ul",{className:"nice-development-studio__preview-list",children:[e.slice(0,n).map(o=>t.jsxs("li",{children:[t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:o.icon,size:14}),onClick:()=>i(o.id),children:o.label}),o.info&&t.jsx("span",{className:"nice-development-studio__muted",children:o.info})]},o.id)),e.length>n&&t.jsx("li",{className:"nice-development-studio__muted",children:s("devStudio.preview.more","…and {count} more").replace("{count}",String(e.length-n))})]})}const Oe=e=>Array.isArray(e)?e.length:void 0;function Tn(e){var p,l,g,f;const{row:i,session:n,advanced:s,onEdit:o}=e,{t:a}=h.useNiceTranslation();if(!i)return t.jsx("div",{className:"nice-development-studio__placeholder","data-testid":"studio-preview-empty",children:e.emptyText});const d=i.node,r=d.kind==="package"?Vt(d.workspaceId,n.packagesByWs[d.workspaceId],n.modulesByWs[d.workspaceId]??[]):void 0,u=Zi(d,{modules:n.modules,packages:r,advanced:s}),m=u?t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:t.jsx(h.NiceIcon,{name:"edit",size:14}),onClick:()=>o(u),"data-testid":"studio-edit","data-tour":"devstudio-edit",children:d.kind==="module"?a("devStudio.preview.editSettings","Edit settings"):a("devStudio.preview.edit","Edit")}):null,c="module"in d?n.modules[Y(d.module)]:void 0;if("module"in d&&!c)return t.jsx(ie,{icon:i.icon,title:i.label,children:t.jsx("p",{className:"nice-development-studio__muted",children:a("devStudio.loading","Loading…")})});switch(d.kind){case"workspace":return t.jsx(En,{...e,row:i,workspaceId:d.workspaceId});case"package":return t.jsx($n,{...e,row:i,workspaceId:d.workspaceId,packageId:d.packageId,editButton:m});case"module":return t.jsx(Kn,{...e,row:i,module:c,editButton:m});case"group":return t.jsx(Mn,{...e,row:i,module:c,group:d.group});case"entity":return t.jsx(zn,{...e,row:i,module:c,docKey:d.docKey,index:d.index,editButton:m});case"item":return t.jsx(Dn,{...e,row:i,module:c,node:d,editButton:m});case"document":return t.jsx(Pn,{...e,row:i,module:c,docKey:d.docKey,editButton:m});case"section":case"folder":return t.jsx(ie,{icon:i.icon,title:i.label,children:t.jsx(Ne,{rows:i.children??[],onSelect:e.onSelect})});case"panel":return t.jsx(ie,{icon:i.icon,title:i.label,actions:m});case"file":{const v=c.working.find(S=>S.path===d.path);return t.jsx(ie,{icon:"file",title:i.label,actions:m,children:t.jsx(ce,{items:[[a("devStudio.preview.size","Size"),v?`${new TextEncoder().encode(v.text).length} B`:void 0],[a("devStudio.preview.state","State"),i.dirty?a("devStudio.explorer.unsaved","Unsaved changes"):void 0]]})})}case"templates":return t.jsx(ie,{icon:"layers",title:i.label,actions:(p=e.provider)!=null&&p.saveTemplate&&!e.readOnly()?t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:e.onNewTemplate,children:a("devStudio.preview.newTemplate","New template")}):void 0,children:t.jsx(Ne,{rows:i.children??[],onSelect:e.onSelect})});case"category":return t.jsx(ie,{icon:"folder",title:i.label,children:t.jsx(Ne,{rows:i.children??[],onSelect:e.onSelect})});case"template":{const v=(l=n.templates)==null?void 0:l.find(y=>y.id===d.templateId),S=(v==null?void 0:v.translations.en)??Object.values((v==null?void 0:v.translations)??{})[0];return t.jsxs(ie,{icon:i.icon,title:i.label,subtitle:v==null?void 0:v.category,actions:m,children:[(S==null?void 0:S.description)&&t.jsx("p",{children:S.description}),t.jsx(ce,{items:[["Id",v==null?void 0:v.id],[a("devStudio.preview.modules","Modules"),String((v==null?void 0:v.modules.length)??0)],[a("devStudio.preview.tags","Tags"),(g=v==null?void 0:v.tags)==null?void 0:g.join(", ")]]}),t.jsx(Ne,{rows:i.children??[],onSelect:e.onSelect,limit:8})]})}case"templateModule":{const v=(f=n.templates)==null?void 0:f.find(y=>y.id===d.templateId),S=v==null?void 0:v.modules.find(y=>y.moduleId===d.moduleId);return t.jsxs(ie,{icon:"box",title:i.label,subtitle:d.moduleId,actions:d.target?t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:t.jsx(h.NiceIcon,{name:"arrow-right",size:14}),onClick:()=>e.onReveal({kind:"module",module:d.target}),children:a("devStudio.preview.goToModule","Go to the module")}):void 0,children:[t.jsx(ce,{items:[[a("devStudio.preview.required","Required"),S!=null&&S.required?a("devStudio.preview.yes","yes"):void 0],[a("devStudio.preview.condition","Condition"),S==null?void 0:S.condition],[a("devStudio.preview.description","Description"),S==null?void 0:S.description]]}),i.missing&&t.jsx("p",{className:"nice-development-studio__error",children:a("devStudio.preview.missingModule","No project has this module.")})]})}}}function En({row:e,workspaceId:i,session:n,provider:s,readOnly:o,canCreateModule:a,onSelect:d,onNewModule:r,onNewPackage:u}){var l;const{t:m}=h.useNiceTranslation(),c=n.workspaces.find(g=>g.id===i),p=!o()&&!(c!=null&&c.readOnly);return t.jsxs(ie,{icon:e.icon,title:e.label,badges:c!=null&&c.readOnly?t.jsx("span",{className:"nice-development-studio__tag",children:m("devStudio.explorer.readOnly","Read-only")}):void 0,actions:p&&(a||s!=null&&s.savePackage)?t.jsxs(t.Fragment,{children:[a&&t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:t.jsx(h.NiceIcon,{name:"box",size:14}),onClick:()=>r({workspaceId:i}),children:m("devStudio.preview.newModule","New module")}),(s==null?void 0:s.savePackage)&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"archive",size:14}),onClick:()=>u(i),children:m("devStudio.preview.newPackage","New package")})]}):void 0,children:[(c==null?void 0:c.description)&&t.jsx("p",{children:c.description}),t.jsx(ce,{items:[[m("devStudio.preview.packages","Packages"),String(((l=e.children)==null?void 0:l.length)??0)],[m("devStudio.preview.modules","Modules"),e.info]]}),t.jsx(Ne,{rows:e.children??[],onSelect:d})]})}function $n({row:e,workspaceId:i,packageId:n,session:s,readOnly:o,canCreateModule:a,editButton:d,onSelect:r,onNewModule:u}){var g;const{t:m}=h.useNiceTranslation(),c=(g=s.packagesByWs[i])==null?void 0:g.find(f=>f.id===n),p=s.workspaces.find(f=>f.id===i),l=!o()&&!(p!=null&&p.readOnly);return t.jsxs(ie,{icon:e.icon,title:e.label,subtitle:n,actions:t.jsxs(t.Fragment,{children:[d,l&&a&&t.jsx(h.NiceButton,{size:"sm",variant:d?"ghost":"primary",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:()=>u({workspaceId:i,packageId:n}),children:m("devStudio.preview.newModuleHere","New module here")})]}),children:[(c==null?void 0:c.description)&&t.jsx("p",{children:c.description}),t.jsx(Ne,{rows:e.children??[],onSelect:r})]})}function Kn(e){var P;const{row:i,module:n,session:s,preset:o,provider:a,readOnly:d,editButton:r}=e,{t:u}=h.useNiceTranslation(),m=n.key,c=(P=s.modulesByWs[m.workspaceId])==null?void 0:P.find(F=>F.id===m.id),p=d(m),l=e.issues(m),g=(c==null?void 0:c.contents)==="manifest"&&t.jsx("span",{title:u("devStudio.preview.manifestOnly","This provider gives only the manifest"),children:"—"}),f=lt(n).length,v=n.documents.filter(F=>F.kind.editor==="views").reduce((F,K)=>F+de(n,K).length,0),S=new Set(n.documents.filter(F=>F.kind.editor==="i18n").flatMap(F=>Object.keys(Z(n,F)??{}))),y={key:m,files:n.working,documents:n.documents},b=o.newFile?o.kinds.filter(F=>F.editor!=="scriptList").map(F=>{var K;return{kind:F,file:(K=o.newFile)==null?void 0:K.call(o,F.id,y)}}).filter(F=>!!F.file&&!n.working.some(K=>K.path===F.file.path)):[],[I,w]=_.useState(!1),k=!p&&ei(n,o),x=F=>t.jsx(h.NiceIcon,{name:F,size:14}),j=[...a!=null&&a.listRevisions?[{id:"history",icon:x("clock"),label:u("devStudio.overview.history","History"),onClick:()=>e.onEdit({kind:"history",module:m})}]:[],...e.canDuplicateModule&&!d()?[{id:"duplicate",icon:x("copy"),label:u("devStudio.explorer.duplicate","Duplicate"),onClick:()=>e.onModuleAction("duplicate",m)}]:[],...a!=null&&a.saveTemplate&&s.templates&&!d()?[{id:"addToTemplate",icon:x("layers"),label:u("devStudio.explorer.addToTemplate","Add to template"),onClick:()=>e.onModuleAction("addToTemplate",m)}]:[],...k?[{id:"addScript",icon:x("code"),label:u("devStudio.scripts.add","Add script"),onClick:()=>w(!0)}]:[],...p?[]:b.map(({kind:F,file:K})=>({id:`add:${F.id}`,icon:x(F.icon??"plus"),label:`${u("devStudio.preview.add","Add:")} ${F.labelKey?u(F.labelKey,F.label):F.label}`,onClick:()=>s.setRaw(m,K.path,K.text)})),...a!=null&&a.deleteModule&&!p?[{id:"sep",divider:!0},{id:"delete",icon:x("trash"),label:u("devStudio.delete","Delete"),danger:!0,onClick:()=>e.onModuleAction("delete",m)}]:[]],N=I&&t.jsx(ti,{module:n,preset:o,onClose:()=>w(!1),onAdd:F=>{const K=Zt(n,o,s,F);K&&e.onEdit(K)}});return t.jsxs(t.Fragment,{children:[N,t.jsxs(ie,{icon:i.icon,title:i.label,subtitle:(c==null?void 0:c.location)??m.id,badges:t.jsxs(t.Fragment,{children:[(c==null?void 0:c.readOnly)&&t.jsx("span",{className:"nice-development-studio__tag",children:u("devStudio.explorer.readOnly","Read-only")}),(c==null?void 0:c.shadowedBy)&&t.jsx("span",{className:"nice-development-studio__tag",title:c.shadowedBy,children:u("devStudio.explorer.shadowed","shadowed")})]}),actions:t.jsxs(t.Fragment,{children:[r,n.dirty&&!p&&t.jsxs(t.Fragment,{children:[t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:x("save"),onClick:()=>e.onSave(m),"data-tour":"devstudio-save",children:u("devStudio.saveCount","Save ({count})").replace("{count}",String(n.changes.length))}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:x("undo"),onClick:()=>s.discard(m),children:u("devStudio.discard","Discard changes")})]}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:x("check"),onClick:()=>void s.validate(m),children:u("devStudio.validate","Validate")}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:x(l.length===0?"success":"warning"),onClick:()=>e.onEdit({kind:"problems",module:m}),children:`${u("devStudio.overview.problems","Problems")} (${l.length})`}),j.length>0&&t.jsx(h.NiceMenu,{className:"nice-development-studio__more",variant:"ghost",size:"sm",fullWidth:!0,items:[{id:"more",icon:x("more-horizontal"),label:u("devStudio.preview.more.actions","More actions"),children:j}]})]}),children:[(c==null?void 0:c.description)&&t.jsx("p",{children:c.description}),t.jsx(ce,{items:[["Id",m.id],[u("devStudio.preview.version","Version"),c==null?void 0:c.version],[u("devStudio.preview.entities","Entities"),g||String(f)],[u("devStudio.preview.views","Views"),g||String(v)],[u("devStudio.preview.languages","Languages"),g||[...S].join(", ")],[u("devStudio.preview.state","State"),n.dirty?u("devStudio.status.changed","{count} changed files").replace("{count}",String(n.changes.length)):void 0]]}),l.length>0&&t.jsxs("div",{className:"nice-development-studio__preview-issues",children:[t.jsx("ul",{className:"nice-development-studio__issues",children:l.slice(0,3).map((F,K)=>t.jsx("li",{className:`nice-development-studio__issue nice-development-studio__issue--${F.severity}`,children:t.jsxs("button",{type:"button",className:"nice-development-studio__issue-link",title:u("devStudio.problems.goTo","Go to"),onClick:()=>e.onReveal(Ut(n,F)),children:[t.jsx(h.NiceIcon,{name:F.severity==="error"?"error":F.severity==="warning"?"warning":"info",size:14}),t.jsx("span",{children:ii(u,F)})]})},K))}),l.length>3&&t.jsx("span",{className:"nice-development-studio__muted",children:u("devStudio.preview.more","…and {count} more").replace("{count}",String(l.length-3))})]})]})]})}function Mn({row:e,module:i,group:n,preset:s,session:o,readOnly:a,onSelect:d,onEdit:r}){const{t:u}=h.useNiceTranslation(),[m,c]=_.useState(!1),p=a(i.key),l=n==="scripts"&&!p&&ei(i,s),g=!p&&!l?Fn(n,i,s,o):void 0;return t.jsxs(ie,{icon:e.icon,title:e.label,actions:l?t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:()=>c(!0),"data-testid":"studio-add",children:u("devStudio.scripts.add","Add script")}):g?t.jsx(h.NiceButton,{size:"sm",variant:"primary",leftIcon:t.jsx(h.NiceIcon,{name:"plus",size:14}),onClick:()=>r(g.run()),"data-testid":"studio-add",children:g.label(u)}):void 0,children:[t.jsx(Ne,{rows:e.children??[],onSelect:d}),m&&t.jsx(ti,{module:i,preset:s,onClose:()=>c(!1),onAdd:f=>{const v=Zt(i,s,o,f);v&&r(v)}})]})}function Fn(e,i,n,s){var c,p;if(e==="dataSources")return nn(i,n)?{label:l=>l("devStudio.items.addDataSource","New data source"),run:()=>Gt(i,n,s,h.newModuleDataSource("query","source1"))??{kind:"manifest",module:i.key}}:void 0;const o=e==="entities"?"entities":e==="views"?"views":e==="workflows"?"workflows":e==="dataSources"?"dataSources":void 0,a=o?i.documents.find(l=>l.kind.editor===o&&l.model!==void 0):void 0;if(!a)return;const d=i.key;if(e==="entities"){const l=Z(i,a)??[],g=((c=n.entities)==null?void 0:c.nameKey)??"name",f=((p=n.entities)==null?void 0:p.fieldsKey)??"fields";return{label:v=>v("devStudio.preview.newEntity","New entity"),run:()=>(s.setDraft(d,a.key,[...l,{[g]:`Entity${l.length+1}`,[f]:[]}]),{kind:"entity",module:d,docKey:a.key,index:l.length})}}const r=de(i,a),u=r.length+1,m=e==="views"?{id:`view-${u}`,name:`View ${u}`,version:2,columns:12,rows:[],dataSources:[]}:{id:`workflow-${u}`,name:`Workflow ${u}`,entityType:"",version:1,states:[],transitions:[]};return{label:l=>e==="views"?l("devStudio.items.addView","New view"):l("devStudio.items.addWorkflow","New workflow"),run:()=>{const l={key:m.id,label:m.name,definition:m,source:m};return s.setDraft(d,a.key,[...r,l]),{kind:"item",module:d,group:e,docKey:a.key,itemKey:m.id}}}}const On=[["isPrimaryKey","PK","Primary key"],["isForeignKey","FK","Foreign key"],["isRequired","Req","Required"]];function zn({row:e,module:i,docKey:n,index:s,preset:o,session:a,readOnly:d,editButton:r,onReveal:u}){var S;const{t:m}=h.useNiceTranslation(),c=he(i,n),p=c?Z(i,c):void 0,l=Array.isArray(p)?p[s]:void 0;if(!c||!p||!l)return t.jsx(ie,{icon:"table",title:e.label,children:t.jsx("p",{className:"nice-development-studio__muted",children:m("devStudio.edit.gone","This is no longer in the module.")})});const g=((S=o.entities)==null?void 0:S.fieldsKey)??"fields",f=Array.isArray(l[g])?l[g]:[],v=d(i.key);return t.jsxs(ie,{icon:"table",title:ut(l)||e.label,subtitle:String(l.name??""),badges:t.jsxs(t.Fragment,{children:[!!l.isAudited&&t.jsx("span",{className:"nice-development-studio__tag",children:m("entityEditor.flag.audited.abbr","Audit")}),!!l.isSoftDeleteEnabled&&t.jsx("span",{className:"nice-development-studio__tag",children:m("entityEditor.flag.softDelete.abbr","Soft-del")})]}),actions:t.jsxs(t.Fragment,{children:[r,!v&&t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:"trash",size:14}),onClick:()=>{a.setDraft(i.key,c.key,pt(p,s,null)),u({kind:"group",module:i.key,group:"entities"})},children:m("devStudio.delete","Delete")})]}),children:[typeof l.description=="string"&&l.description&&t.jsx("p",{children:l.description}),t.jsx(ce,{items:[[m("entityEditor.col.table","Table"),l.tableName],[m("entityEditor.col.fields","Fields"),String(f.length)]]}),f.length>0&&t.jsx("table",{className:"nice-development-studio__table nice-development-studio__preview-fields",children:t.jsx("tbody",{children:f.slice(0,8).map((y,b)=>t.jsxs("tr",{children:[t.jsx("td",{children:String(y.name??"")}),t.jsx("td",{className:"nice-development-studio__muted",children:String(y.dataType??y.type??"")}),t.jsx("td",{children:On.filter(([I])=>y[I]||I==="isRequired"&&y.required).map(([,I,w])=>t.jsx("span",{className:"nice-development-studio__tag",title:w,children:I},I))})]},b))})}),f.length>8&&t.jsx("span",{className:"nice-development-studio__muted",children:m("devStudio.preview.more","…and {count} more").replace("{count}",String(f.length-8))})]})}function Dn({row:e,module:i,node:n,advanced:s,renderViewPreview:o,editButton:a}){var f,v,S,y,b;const{t:d}=h.useNiceTranslation(),r=he(i,n.docKey),u=n.docKey===ze?mt(i).find(I=>I.key===n.itemKey):void 0,m=u?{key:u.key,label:u.label??u.key,definition:u,source:u}:r?de(i,r).find(I=>I.key===n.itemKey):void 0;if(!m)return t.jsx(ie,{icon:e.icon,title:e.label,children:t.jsx("p",{className:"nice-development-studio__muted",children:d("devStudio.edit.gone","This is no longer in the module.")})});const c=m.source??{},p=m.definition??{},l=n.group==="scripts"?m.definition:void 0,g=l?[[d("devStudio.scripts.name","Name"),l.name],[d("devStudio.scripts.kind","Kind"),ft(d,l.kind)],[d("devStudio.scripts.language","Language"),l.language],[d("devStudio.scripts.category","Category"),l.category],[d("devStudio.scripts.trigger","Runs on"),l.trigger],[d("devStudio.scripts.parameters","Parameters"),(f=l.parameters)==null?void 0:f.map(I=>I.name).join(", ")],[d("devStudio.scripts.returnType","Returns"),l.returnType],[d("devStudio.scripts.description","Description"),l.description]]:n.group==="views"?[["Id",m.key],[d("devStudio.preview.type","Type"),c.viewType??c.type??c.kind],[d("devStudio.preview.entity","Entity"),c.entityName??c.entity],[d("devStudio.preview.columns","Columns"),(v=Oe(c.columns))==null?void 0:v.toString()],[d("devStudio.preview.rows","Rows"),(S=Oe(p.rows))==null?void 0:S.toString()]]:n.group==="workflows"?[["Id",m.key],[d("devStudio.preview.states","States"),(y=Oe(p.states??c.states))==null?void 0:y.toString()],[d("devStudio.preview.transitions","Transitions"),(b=Oe(p.transitions??c.transitions))==null?void 0:b.toString()]]:[[d("devStudio.preview.key","Key"),m.key],[d("devStudio.preview.type","Type"),p.kind??void 0]];return t.jsxs(ie,{icon:e.icon,title:m.label||m.key,badges:m.definition===void 0?t.jsx("span",{className:"nice-development-studio__tag",children:d("devStudio.tree.noForm","no designer")}):void 0,actions:a,children:[t.jsx(ce,{items:g}),m.definition===void 0&&t.jsx("p",{className:"nice-development-studio__muted",children:s?d("devStudio.preview.noDesignerAdvanced","There is no designer for this kind of entry yet; edit its source."):d("devStudio.preview.noDesigner","There is no designer for this kind of entry yet.")}),n.group==="views"&&o&&t.jsx("div",{className:"nice-development-studio__preview-view",children:o({module:i.key,item:m,files:i.working})})]})}function Pn({row:e,module:i,docKey:n,advanced:s,editButton:o}){var m;const{t:a}=h.useNiceTranslation(),d=he(i,n);if(!d)return t.jsx(ie,{icon:e.icon,title:e.label,children:t.jsx("p",{className:"nice-development-studio__muted",children:a("devStudio.edit.gone","This is no longer in the module.")})});const r=Z(i,d);let u=null;if(d.model===void 0)u=t.jsxs("p",{className:"nice-development-studio__error",role:"alert",children:[s?a("devStudio.doc.unreadable","This file could not be read as its kind; edit its source."):a("devStudio.preview.unreadable","This file does not read; saving leaves it as it is. Fix it in the advanced mode.")," ",d.error]});else if(d.kind.editor==="i18n"){const c=r??{},p=Math.max(0,...Object.values(c).map(l=>Object.keys(l??{}).length));u=t.jsx(ce,{items:Object.entries(c).map(([l,g])=>{const f=Object.keys(g??{}).length;return[l,f<p?a("devStudio.preview.keysMissing","{count} keys, {missing} missing").replace("{count}",String(f)).replace("{missing}",String(p-f)):a("devStudio.preview.keys","{count} keys").replace("{count}",String(f))]})})}else if(d.kind.editor==="permissions"){const c=r??{permissions:[],groups:[]};u=t.jsx(ce,{items:[[a("devStudio.permissions.codes","Permissions"),String(c.permissions.length)],[a("devStudio.permissions.groups","Groups"),String(c.groups.length)]]})}else if(d.kind.editor==="seeds"){const c=r??{seeds:{}};u=t.jsx(ce,{items:Object.entries(c.seeds??{}).map(([p,l])=>[p,a("devStudio.preview.rowsCount","{count} rows").replace("{count}",String(l.length))])})}else d.kind.editor==="hooks"?u=t.jsx(ce,{items:[[a("devStudio.preview.bindings","Bindings"),(m=Oe(r))==null?void 0:m.toString()]]}):d.kind.editor==="script"&&(u=t.jsx(ce,{items:[[a("devStudio.preview.lines","Lines"),String(String(r??"").split(`
|
|
8
|
+
`).length)]]}));return t.jsx(ie,{icon:e.icon,title:e.label,subtitle:d.paths.join(", "),actions:o,children:u})}function Ln({tree:e,selected:i,expanded:n,onExpandedChange:s,onSelect:o,loadModule:a,newItems:d,actions:r,onRefresh:u,tutorialButton:m,emptyText:c,minWidth:p,contextMenuItems:l}){const{t:g}=h.useNiceTranslation(),f=_.useMemo(()=>[{field:"label",header:g("devStudio.explorer.name","Name"),render:(S,y)=>t.jsxs("span",{className:"nice-development-studio__tree-name",style:{maxWidth:`calc(100% - ${(y.depth??0)*20+28}px)`},children:[t.jsx(h.NiceIcon,{name:y.icon,size:14}),t.jsx("span",{className:`nice-development-studio__tree-label${y.missing?" nice-development-studio__missing":""}`,title:y.label,children:y.label}),y.dirty&&t.jsx("span",{className:"nice-development-studio__dot",title:g("devStudio.explorer.unsaved","Unsaved changes"),children:t.jsx(h.NiceIcon,{name:"circle",size:8})}),!!y.issues&&t.jsx("span",{className:"nice-development-studio__badge",title:g("devStudio.explorer.problems","Problems"),children:y.issues}),y.readOnly&&t.jsx("span",{title:g("devStudio.explorer.readOnly","Read-only"),children:t.jsx(h.NiceIcon,{name:"lock",size:12})}),y.noForm&&t.jsx("span",{className:"nice-development-studio__tag",children:g("devStudio.tree.noForm","no designer")}),y.shadowedBy&&t.jsx("span",{className:"nice-development-studio__tag",title:y.shadowedBy,children:g("devStudio.explorer.shadowed","shadowed")}),y.missing&&t.jsx("span",{className:"nice-development-studio__tag",children:g("devStudio.explorer.missing","missing")})]})},{field:"info",header:"",width:56,align:"right"}],[g]),v=t.jsxs("div",{className:"nice-development-studio__tree-actions",children:[d.length>0&&t.jsx(h.NiceMenu,{variant:"ghost",size:"sm",items:[{id:"new",label:g("devStudio.tree.new","New"),icon:t.jsx(h.NiceIcon,{name:"plus",size:14}),children:d}],"data-testid":"studio-new-menu"}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",ariaLabel:g("devStudio.refresh","Refresh"),onClick:u,children:t.jsx(h.NiceIcon,{name:"refresh",size:14})}),r==null?void 0:r.map(S=>t.jsx(h.NiceButton,{size:"sm",variant:"ghost",disabled:S.disabled,leftIcon:S.icon?t.jsx(h.NiceIcon,{name:S.icon,size:14}):void 0,onClick:S.onSelect,children:S.label},S.key)),m&&t.jsx("span",{className:"nice-development-studio__spacer"}),m]});return t.jsx("div",{className:"nice-development-studio__tree","data-tour":"devstudio-explorer",style:{minWidth:p},children:t.jsx(h.NiceTreeGrid,{data:e.rows,nested:!0,keyField:"id",childrenField:"children",columns:f,sortable:!1,compact:!0,searchable:!0,searchFields:["label","search"],searchPlaceholder:g("devStudio.tree.search","Search modules, entities and views"),toolbar:v,toolbarActions:["collapseAll"],expandedKeys:n,onExpandedChange:s,hasChildren:S=>S.node.kind==="module"&&!S.children,loadChildren:async S=>(S.node.kind==="module"&&await a(S.node.module),[]),onRowClick:o,contextMenuItems:l,rowClassName:S=>S.id===i?"nice-development-studio__tree-row--selected":void 0,emptyText:c,"aria-label":g("devStudio.explorer.modules","Modules"),"data-testid":"studio-tree"})})}const Rn=[{target:".nice-development-studio",titleKey:"tutorial.devStudio.intro.title",title:"Development studio",contentKey:"tutorial.devStudio.intro.content",content:"Design whole modules: their settings, entities, views, workflows, translations, permissions, data sources and seed data. Saving writes back only what changed.",placement:"auto"},{target:'[data-tour="devstudio-explorer"]',titleKey:"tutorial.devStudio.explorer.title",title:"Projects, packages and modules",contentKey:"tutorial.devStudio.explorer.content",content:"Browse projects, their packages and modules. Open a module to see its entities, views, translations and the rest; under Templates are the module sets installed together.",placement:"right"},{target:'[data-testid="studio-preview"]',titleKey:"tutorial.devStudio.preview.title",title:"A short preview",contentKey:"tutorial.devStudio.preview.content",content:"Pick a row in the tree to see a short preview of it here.",placement:"left"},{target:'[data-tour="devstudio-edit"]',titleKey:"tutorial.devStudio.edit.title",title:"Edit on the whole screen",contentKey:"tutorial.devStudio.edit.content",content:"Edit opens the form of what you picked on the whole studio. Back, or a step of the trail, brings you back to the tree.",placement:"bottom"},{target:'[data-tour="devstudio-save"]',titleKey:"tutorial.devStudio.save.title",title:"Validate and save",contentKey:"tutorial.devStudio.save.content",content:"Check the module, review the changed files and save them — only the bytes you changed are written.",placement:"bottom"}],Bn=["en","pl","de","fr","es","uk"],An=_.forwardRef(function(i,n){var bt,xt;const{provider:s,preset:o,defaultModule:a,defaultExplorerTab:d="modules",displayMode:r="standard",actions:u,onModuleOpen:m,onSaved:c,onError:p,reviewBeforeSave:l=!0,scriptRunner:g,editors:f,editorServices:v,scriptIo:S,previewDataSource:y,renderViewPreview:b,modulePanels:I,readOnly:w=!1,height:k=720,explorerWidth:x=320,previewWidth:j=260,tutorial:N,className:P,style:F,id:K,testId:G,"data-testid":ee}=i,{t:B}=h.useNiceTranslation(),ne=_.useRef(null);_.useImperativeHandle(n,()=>ne.current);const L=r==="advanced",A=_.useMemo(()=>typeof o=="function"?o(B):o??T.nativeStudioPreset,[o,B]),q=_.useMemo(()=>A.locales??Bn,[A]),M=Bi(s,A,{locales:q,onError:p,t:B}),{openModule:H}=M,[U,X]=_.useState(""),[ye,$e]=_.useState([]),[te,$]=_.useState(null),[O,z]=_.useState(null),[E,D]=_.useState(null),J=_.useCallback(C=>{var R;return(R=M.modulesByWs[C.workspaceId])==null?void 0:R.find(W=>W.id===C.id)},[M.modulesByWs]),Q=C=>{var R;return((R=J(C))==null?void 0:R.label)??C.id},V=_.useMemo(()=>{const C={};for(const[R,W]of Object.entries(M.modules))C[R]=[...Pt(W,A),...M.serverIssues[R]??[]];return C},[M.modules,M.serverIssues,A]),oe=_.useCallback(C=>V[Y(C)]??[],[V]),_e=_.useMemo(()=>Object.fromEntries(Object.entries(V).map(([C,R])=>[C,R.filter(W=>W.severity==="error").length])),[V]),ve=_.useCallback(C=>{var W;if(w)return!0;if(!C)return!1;const R=M.workspaces.find(ke=>ke.id===C.workspaceId);return!!(R!=null&&R.readOnly)||!!((W=J(C))!=null&&W.readOnly)},[w,M.workspaces,J]),ae=Cn(M,ve),se=_.useMemo(()=>Xi({workspaces:M.workspaces,modulesByWs:M.modulesByWs,packagesByWs:M.packagesByWs,templates:M.templates,modules:M.modules,issueCounts:_e,panels:I?C=>I({module:C.key,files:C.working,dirty:C.dirty}):void 0,advanced:L,groups:A.groups,t:B}),[A.groups,M.workspaces,M.modulesByWs,M.packagesByWs,M.templates,M.modules,_e,I,L,B]),Se=_.useRef(!1);_.useEffect(()=>{if(!Se.current&&M.workspaces.length>0){Se.current=!0;const C=M.workspaces.map(R=>`w:${R.id}`);d==="templates"&&(C.push(Be),X(Be)),$e(R=>[...new Set([...R,...C])])}},[M.workspaces,d]);const le=_.useCallback(C=>{const R=Tt(se,C).map(W=>W.id);$e(W=>[...new Set([...W,...R])]),X(C)},[se]),Ie=_.useCallback(C=>{$(null);const R=Fe(C);R&&!M.modules[Y(R)]&&H(R),z(C)},[M.modules,H]);_.useEffect(()=>{if(!O)return;const C=it(se,O);if(C){le(C),z(null);return}const R=Fe(O);if(R&&M.modules[Y(R)]){const W=it(se,{kind:"module",module:R});W&&le(W),z(null)}},[O,se,le,M.modules]);const We=_.useCallback(C=>{X(C.id);const R=Fe(C.node);R&&!M.modules[Y(R)]&&H(R),C.node.kind==="module"&&(m==null||m(C.node.module))},[M.modules,H,m]),ni=_.useCallback(C=>{const R=se.byId.get(C);R&&(We(R),le(C))},[se,We,le]),gt=_.useRef(!1);_.useEffect(()=>{a&&!gt.current&&M.modulesByWs[a.workspaceId]&&(gt.current=!0,H(a).then(()=>m==null?void 0:m(a)),z({kind:"module",module:a}))},[a,M.modulesByWs,H,m]);const Ce=se.byId.get(U),ue=te?"module"in te?te.module:void 0:Ce?Fe(Ce.node):void 0,Ve=_.useCallback(async C=>{const R=M.modules[Y(C)];if(!(R!=null&&R.dirty)||ve(C))return;if(l){D({kind:"review",module:C});return}const W=await M.save(C);W&&!W.ok?D({kind:"review",module:C,conflict:W}):W!=null&&W.ok&&(c==null||c(C,W))},[M,ve,l,c]),yt=_.useRef(()=>{});yt.current=()=>{ue&&Ve(ue)},_.useEffect(()=>{const C=ne.current;if(!C)return;const R=W=>{(W.ctrlKey||W.metaKey)&&!W.altKey&&W.key.toLowerCase()==="s"&&(W.preventDefault(),yt.current())};return C.addEventListener("keydown",R),()=>C.removeEventListener("keydown",R)},[]);const si=()=>{const C=te?Et(te):void 0;C?Ie(C):$(null)},oi=_.useMemo(()=>{if(!te)return[];const C=Et(te),R=C?it(se,C):void 0,W=R?Tt(se,R):[],ke=te.kind==="manifest"?B("devStudio.edit.settings","Settings"):te.kind==="problems"?B("devStudio.overview.problems","Problems"):te.kind==="history"?B("devStudio.overview.history","History"):te.kind==="template"&&!te.templateId?B("devStudio.template.new","New template"):void 0,be=W.map(jt=>({label:jt.label,onClick:()=>{$(null),le(jt.id)}}));return ke?be.push({label:ke}):be.length>0&&(be[be.length-1]={label:be[be.length-1].label}),be},[te,se,le,B]),St=!!(s!=null&&s.createModule)&&!!A.generateModule,ai=!!(s!=null&&s.createModule)&&!!A.duplicateModule,Ke=M.workspaces.filter(C=>!C.readOnly).map(C=>({id:C.id,label:C.label})),re=Ce==null?void 0:Ce.node,Je=re&&"workspaceId"in re?re.workspaceId:re&&"module"in re?re.module.workspaceId:void 0,di=(re==null?void 0:re.kind)==="package"?re.packageId:re&&"module"in re?(bt=J(re.module))==null?void 0:bt.packageId:void 0,Me=Ke.some(C=>C.id===Je)?Je:(xt=Ke[0])==null?void 0:xt.id,ri=w?[]:[...St&&Me?[{id:"module",label:B("devStudio.tree.newModule","Module…"),icon:t.jsx(h.NiceIcon,{name:"box",size:14}),onClick:()=>D({kind:"wizard",prefill:{workspaceId:Me,packageId:Me===Je?di:void 0}})}]:[],...s!=null&&s.savePackage&&Me?[{id:"package",label:B("devStudio.tree.newPackage","Package…"),icon:t.jsx(h.NiceIcon,{name:"archive",size:14}),onClick:()=>D({kind:"package",workspaceId:Me})}]:[],...s!=null&&s.saveTemplate&&M.templates?[{id:"template",label:B("devStudio.tree.newTemplate","Template"),icon:t.jsx(h.NiceIcon,{name:"layers",size:14}),onClick:()=>$({kind:"template",templateId:null})}]:[]],ci=(C,R)=>{D(C==="delete"?{kind:"delete",module:R}:C==="duplicate"?{kind:"duplicate",module:R}:{kind:"templates",module:R})},kt=N?t.jsx(h.NiceTutorialButton,{steps:h.resolveTutorial(N,Rn)}):void 0,De=ue?M.modules[Y(ue)]:void 0,Ue=ue?oe(ue):[],Ge=M.logs[M.logs.length-1],li=t.jsxs("div",{className:"nice-development-studio__statusbar",role:"status",children:[ue&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:Q(ue)}),t.jsx("span",{children:De!=null&&De.dirty?B("devStudio.status.changed","{count} changed files").replace("{count}",String(De.changes.length)):B("devStudio.status.saved","Saved")}),t.jsx(h.NiceButton,{size:"sm",variant:"ghost",leftIcon:t.jsx(h.NiceIcon,{name:Ue.length===0?"check":"warning",size:12}),onClick:()=>$({kind:"problems",module:ue}),children:Ue.length===0?B("devStudio.status.valid","No problems"):B("devStudio.status.problems","{count} problems").replace("{count}",String(Ue.length))})]}),t.jsx("span",{className:"nice-development-studio__spacer"}),M.busy?t.jsx("span",{children:B("devStudio.loading","Loading…")}):Ge&&t.jsx("span",{className:`nice-development-studio__status-message nice-development-studio__status-message--${Ge.level}`,children:Ge.message})]}),He=(E==null?void 0:E.kind)==="review"?M.modules[Y(E.module)]:void 0,ui=`nice-development-studio${P?` ${P}`:""}`,mi=s?B("devStudio.preview.empty","Pick a module, an entity or a view in the tree."):B("devStudio.noProvider","Connect a provider to browse modules.");return t.jsxs("div",{ref:ne,id:K,className:ui,style:{height:k,...F},"data-testid":ee??G,children:[t.jsx(h.NiceAppShell,{className:"nice-development-studio__shell",height:"100%",rightSidebar:te?void 0:t.jsx(Tn,{row:Ce,tree:se,session:M,preset:A,provider:s,readOnly:ve,advanced:L,issues:oe,canCreateModule:St,canDuplicateModule:ai,renderViewPreview:b,emptyText:mi,onSelect:ni,onEdit:$,onReveal:Ie,onSave:C=>void Ve(C),onNewModule:C=>D({kind:"wizard",prefill:C}),onNewPackage:C=>D({kind:"package",workspaceId:C}),onNewTemplate:()=>$({kind:"template",templateId:null}),onModuleAction:ci}),rightSidebarWidth:j,statusBar:li,bottomPanel:L?t.jsx("div",{"data-tour":"devstudio-output",className:"nice-development-studio__output",children:t.jsx(h.NiceLogConsole,{title:B("devStudio.output","Output"),entries:M.logs,onClear:M.clearLogs,maxHeight:"100%"})}):void 0,bottomPanelHeight:L?140:void 0,children:te?t.jsx(kn,{screen:te,crumbs:oi,session:M,preset:A,provider:s,locales:q,readOnly:ve,advanced:L,issues:oe,scriptRunner:g,editors:f,editorServices:v,scriptIo:S,previewDataSource:y,renderViewPreview:b,modulePanels:I,tutorialButton:kt,onBack:si,onSave:C=>void Ve(C),onReveal:Ie,onScreen:$,onNewModule:C=>D({kind:"wizard",prefill:C})}):t.jsx(Ln,{tree:se,selected:U,expanded:ye,onExpandedChange:$e,onSelect:We,loadModule:async C=>{await H(C)},newItems:ri,actions:u,onRefresh:()=>void M.refresh(),tutorialButton:kt,minWidth:x,contextMenuItems:ae.menuFor,emptyText:s?B("devStudio.explorer.empty","No modules."):B("devStudio.noProvider","Connect a provider to browse modules.")})}),(E==null?void 0:E.kind)==="wizard"&&t.jsx(zi,{open:!0,onClose:()=>D(null),session:M,preset:A,locales:q,prefill:E.prefill,onCreated:C=>{m==null||m(C),Ie({kind:"module",module:C})}}),(E==null?void 0:E.kind)==="review"&&He&&t.jsx(Di,{open:!0,moduleLabel:Q(E.module),changes:He.changes,original:C=>{var R;return((R=He.files.find(W=>W.path===C))==null?void 0:R.text)??""},conflict:E.conflict,onClose:()=>D(null),onSave:async()=>{const C=await M.save(E.module);C!=null&&C.ok?(D(null),c==null||c(E.module,C)):C&&D({...E,conflict:C})},onOverwrite:async()=>{const C=await M.save(E.module,{force:!0});C!=null&&C.ok&&(D(null),c==null||c(E.module,C))},onReload:async()=>{await M.reload(E.module),D(null)}}),(E==null?void 0:E.kind)==="delete"&&t.jsx(h.NiceConfirmDialog,{visible:!0,variant:"warning",header:B("devStudio.delete.title","Delete module"),message:B("devStudio.delete.message","Delete {module} and all its files?").replace("{module}",Q(E.module)),acceptLabel:B("devStudio.delete","Delete"),rejectLabel:B("devStudio.cancel","Cancel"),onReject:()=>D(null),onAccept:async()=>{const C=E.module;D(null),await M.deleteModule(C)&&($(null),X(`w:${C.workspaceId}`))}}),ae.dialog,(E==null?void 0:E.kind)==="duplicate"&&t.jsx(It,{open:!0,title:B("devStudio.duplicate.title","Duplicate {module}").replace("{module}",Q(E.module)),workspaces:Ke,workspaceId:Ke.some(C=>C.id===E.module.workspaceId)?E.module.workspaceId:void 0,idLabel:B("devStudio.duplicate.id","New module id"),initialId:`${E.module.id}Copy`,onClose:()=>D(null),onSubmit:async C=>{var ke;const R=E.module;D(null);const W=await M.duplicateModule(R,{workspaceId:C.workspaceId,id:C.id,packageId:(ke=J(R))==null?void 0:ke.packageId});W&&Ie({kind:"module",module:{workspaceId:W.workspaceId,id:W.id}})}}),(E==null?void 0:E.kind)==="package"&&t.jsx(It,{open:!0,title:B("devStudio.package.new","New package"),workspaces:Ke,workspaceId:E.workspaceId,idLabel:B("devStudio.package.id","Id"),withLabel:!0,onClose:()=>D(null),onSubmit:async C=>{D(null);const R=await M.savePackage({id:C.id,workspaceId:C.workspaceId,label:C.label});R&&Ie({kind:"package",workspaceId:R.workspaceId,packageId:R.id})}}),(E==null?void 0:E.kind)==="templates"&&M.templates&&t.jsx(Pi,{open:!0,moduleId:E.module.id,templates:M.templates,onClose:()=>D(null),onApply:async C=>{D(null);for(const R of C)await M.saveTemplate(R,R.id)}})]})});exports.NICE_STUDIO_SCRIPT_KINDS=T.NICE_STUDIO_SCRIPT_KINDS;exports.NICE_STUDIO_SCRIPT_PHASES=T.NICE_STUDIO_SCRIPT_PHASES;exports.addStudioFolder=T.addStudioFolder;exports.addStudioSection=T.addStudioSection;exports.arrayFileKind=T.arrayFileKind;exports.buildDocuments=T.buildDocuments;exports.createMemoryStudioProvider=T.createMemoryStudioProvider;exports.defineManifestSection=T.defineManifestSection;exports.deriveDefaultRbac=T.deriveDefaultRbac;exports.detectJsonTextFormat=T.detectJsonTextFormat;exports.emptyStudioLayout=T.emptyStudioLayout;exports.encodeDocument=T.encodeDocument;exports.endsWithAny=T.endsWithAny;exports.entitiesToSchemas=T.entitiesToSchemas;exports.fileName=T.fileName;exports.fitManifestSection=T.fitManifestSection;exports.fromStudioScriptItem=T.fromStudioScriptItem;exports.i18nFileKind=T.i18nFileKind;exports.inferStudioScriptKind=T.inferStudioScriptKind;exports.isEmptyStudioLayout=T.isEmptyStudioLayout;exports.isStudioLayoutPath=T.isStudioLayoutPath;exports.itemsFileKind=T.itemsFileKind;exports.jsonFallbackKind=T.jsonFallbackKind;exports.jsonFileKind=T.jsonFileKind;exports.jsonValueFitsSchema=T.jsonValueFitsSchema;exports.jsonValuesEqual=T.jsonValuesEqual;exports.keepTextFormat=T.keepTextFormat;exports.manifestSectionKeys=T.manifestSectionKeys;exports.modulePrefix=T.modulePrefix;exports.nativeDataSourcesKind=T.nativeDataSourcesKind;exports.nativeEntitiesKind=T.nativeEntitiesKind;exports.nativeEnvironmentsKind=T.nativeEnvironmentsKind;exports.nativeFileKinds=T.nativeFileKinds;exports.nativeHooksKind=T.nativeHooksKind;exports.nativeI18nKind=T.nativeI18nKind;exports.nativeIntegrationsKind=T.nativeIntegrationsKind;exports.nativeManifestKind=T.nativeManifestKind;exports.nativeRbacKind=T.nativeRbacKind;exports.nativeScriptsKind=T.nativeScriptsKind;exports.nativeStudioPreset=T.nativeStudioPreset;exports.nativeViewsKind=T.nativeViewsKind;exports.nativeWorkflowsKind=T.nativeWorkflowsKind;exports.newStudioScript=T.newStudioScript;exports.objectFileKind=T.objectFileKind;exports.parseJsonText=T.parseJsonText;exports.parseStudioLayout=T.parseStudioLayout;exports.patchJsonText=T.patchJsonText;exports.patchJsonTextDetailed=T.patchJsonTextDetailed;exports.placeStudioEntry=T.placeStudioEntry;exports.readTranslations=T.readTranslations;exports.removeStudioLayoutNode=T.removeStudioLayoutNode;exports.renameStudioEntryRef=T.renameStudioEntryRef;exports.renameStudioLayoutNode=T.renameStudioLayoutNode;exports.resolveFileKind=T.resolveFileKind;exports.safeJson=T.safeJson;exports.scriptsFileKind=T.scriptsFileKind;exports.serializeStudioLayout=T.serializeStudioLayout;exports.slugifyModuleId=T.slugifyModuleId;exports.stringifyJsonText=T.stringifyJsonText;exports.studioEntryRef=T.studioEntryRef;exports.studioLayoutPath=T.studioLayoutPath;exports.studioScriptIdentifier=T.studioScriptIdentifier;exports.studioScriptLanguages=T.studioScriptLanguages;exports.textFallbackKind=T.textFallbackKind;exports.toStudioScriptItem=T.toStudioScriptItem;exports.writeTranslations=T.writeTranslations;exports.NiceArrayField=dt;exports.NiceDevelopmentStudio=An;exports.NiceEntityEditor=zt;exports.NiceEntityForm=rt;exports.NiceI18nEditor=vt;exports.NiceSchemaForm=Ee;exports.aiFormConfigToFormFields=yi;exports.aiFormFieldType=Mt;exports.formBuilderSchemaToNiceFormItems=hi;exports.formFieldsToFormItems=ot;exports.formSchemaToJsonSchema=xi;exports.jsonSchemaToFormItems=st;exports.schemaToFormItems=vi;exports.validateAgainstJsonSchema=at;exports.validateFormSchema=fi;
|