@nice2dev/ui-forms 1.4.6 → 1.4.7

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/studio.cjs CHANGED
@@ -5,12 +5,12 @@
5
5
  `,indent:" ",finalNewline:!0,colonSpace:!0};function q(e){const t=e.charCodeAt(0)===65279,n=e.includes(`\r
6
6
  `)?`\r
7
7
  `:`
8
- `;let s=de.indent;const i=e.split(/\r?\n/);for(let a=1;a<i.length;a++){const l=/^([ \t]+)\S/.exec(i[a]);if(l){s=l[1];break}}const r=/"\s*:(\s?)/.exec(e);return{bom:t,eol:n,indent:s,finalNewline:/\n$/.test(e),colonSpace:r?r[1]!=="":!0}}function A(e){const t=q(e);return{value:JSON.parse(t.bom?e.slice(1):e),format:t}}function S(e,t){const n={...de,...t},s=E(e,n,"");return(n.bom?le:"")+s+(n.finalNewline?n.eol:"")}function fe(e,t){if(t===void 0)return e;let n=t.includes(`\r
8
+ `;let s=de.indent;const i=e.split(/\r?\n/);for(let a=1;a<i.length;a++){const l=/^([ \t]+)\S/.exec(i[a]);if(l){s=l[1];break}}const r=/"\s*:(\s?)/.exec(e);return{bom:t,eol:n,indent:s,finalNewline:/\n$/.test(e),colonSpace:r?r[1]!=="":!0}}function E(e){const t=q(e);return{value:JSON.parse(t.bom?e.slice(1):e),format:t}}function k(e,t){const n={...de,...t},s=A(e,n,"");return(n.bom?le:"")+s+(n.finalNewline?n.eol:"")}function fe(e,t){if(t===void 0)return e;let n=t.includes(`\r
9
9
  `)?e.replace(/\r?\n/g,`\r
10
- `):e;return t.charCodeAt(0)===65279&&n.charCodeAt(0)!==65279&&(n=le+n),n}function F(e,t){if(e===t)return!0;if(typeof e!=typeof t||e===null||t===null||typeof e!="object"||Array.isArray(e)!==Array.isArray(t))return!1;if(Array.isArray(e)){const r=t;return e.length===r.length&&e.every((a,l)=>F(a,r[l]))}const n=e,s=t,i=Object.keys(n);return i.length!==Object.keys(s).length?!1:i.every(r=>Object.prototype.hasOwnProperty.call(s,r)&&F(n[r],s[r]))}function Y(e,t,n){return ue(e,t,n).text}function ue(e,t,n){const s=q(e),i=o=>({text:S(t,s),exact:!1,reason:o});let r;try{r=new it(e).parseDocument()}catch(o){return i(o instanceof Error?o.message:String(o))}if(H(r))return i("duplicate keys");const a=[],l={text:e,format:s,edits:a,options:n,compact:!e.trimEnd().includes(`
11
- `)};ee(l,r,t,"",!1);const f=rt(e,a);try{const o=JSON.parse(s.bom?f.slice(1):f);if(!F(o,t))return i("patch did not read back")}catch{return i("patch was not valid JSON")}return{text:f,exact:!0}}class it{constructor(t){se(this,"pos",0);this.text=t}parseDocument(){this.text.charCodeAt(0)===65279&&(this.pos=1);const t=this.value();if(this.ws(),this.pos<this.text.length)throw new Error(`Unexpected text at ${this.pos}`);return t}ws(){for(;this.pos<this.text.length&&/\s/.test(this.text[this.pos]);)this.pos++}value(){this.ws();const t=this.text[this.pos];if(t==="{")return this.object();if(t==="[")return this.array();const n=this.pos;if(t==='"')return{kind:"scalar",start:n,end:this.stringEnd(),value:JSON.parse(this.slice(n))};const s=/^(?:-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null)/.exec(this.text.slice(n,n+64));if(!s)throw new Error(`Unexpected token at ${n}`);return this.pos=n+s[0].length,{kind:"scalar",start:n,end:this.pos,value:JSON.parse(s[0])}}slice(t){return this.text.slice(t,this.pos)}stringEnd(){for(this.pos++;this.pos<this.text.length;){const t=this.text[this.pos];if(t==="\\"){this.pos+=2;continue}if(this.pos++,t==='"')return this.pos}throw new Error("Unterminated string")}object(){const t=this.pos++,n=[];if(this.ws(),this.text[this.pos]==="}")return{kind:"object",start:t,end:++this.pos,members:n};for(;;){this.ws();const s=this.pos;if(this.text[this.pos]!=='"')throw new Error(`Expected a key at ${this.pos}`);const i=JSON.parse(this.text.slice(s,this.stringEnd()));if(this.ws(),this.text[this.pos]!==":")throw new Error(`Expected ':' at ${this.pos}`);this.pos++,n.push({key:i,start:s,value:this.value()}),this.ws();const r=this.text[this.pos++];if(r==="}")return{kind:"object",start:t,end:this.pos,members:n};if(r!==",")throw new Error(`Expected ',' or '}' at ${this.pos-1}`)}}array(){const t=this.pos++,n=[];if(this.ws(),this.text[this.pos]==="]")return{kind:"array",start:t,end:++this.pos,items:n};for(;;){n.push(this.value()),this.ws();const s=this.text[this.pos++];if(s==="]")return{kind:"array",start:t,end:this.pos,items:n};if(s!==",")throw new Error(`Expected ',' or ']' at ${this.pos-1}`)}}}function H(e){if(e.kind==="object"){const t=new Set;for(const n of e.members){if(t.has(n.key)||H(n.value))return!0;t.add(n.key)}}else if(e.kind==="array")return e.items.some(H);return!1}function P(e){if(e.kind==="scalar")return e.value;if(e.kind==="array")return e.items.map(P);const t={};for(const n of e.members)t[n.key]=P(n.value);return t}function E(e,t,n){if(e===null||typeof e!="object")return e===void 0?"null":JSON.stringify(e);const s=n+t.indent,i=t.colonSpace?": ":":";if(Array.isArray(e))return e.length===0?"[]":`[${t.eol}${e.map(a=>s+E(a,t,s)).join(`,${t.eol}`)}${t.eol}${n}]`;const r=Object.entries(e).filter(([,a])=>a!==void 0);return r.length===0?"{}":`{${t.eol}${r.map(([a,l])=>`${s}${JSON.stringify(a)}${i}${E(l,t,s)}`).join(`,${t.eol}`)}${t.eol}${n}}`}function I(e,t,n=!1){if(e===null||typeof e!="object")return e===void 0?"null":JSON.stringify(e);const s=t.colonSpace?": ":":",i=n?",":", ";if(Array.isArray(e))return`[${e.map(l=>I(l,t,n)).join(i)}]`;const r=Object.entries(e).filter(([,l])=>l!==void 0),a=n?"":" ";return r.length===0?"{}":`{${a}${r.map(([l,f])=>`${JSON.stringify(l)}${s}${I(f,t,n)}`).join(i)}${a}}`}const pe=e=>e.compact?",":", ";function rt(e,t){let n=e;for(const s of[...t].sort((i,r)=>r.start-i.start))n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}function J(e,t){var s;const n=e.lastIndexOf(`
10
+ `):e;return t.charCodeAt(0)===65279&&n.charCodeAt(0)!==65279&&(n=le+n),n}function F(e,t){if(e===t)return!0;if(typeof e!=typeof t||e===null||t===null||typeof e!="object"||Array.isArray(e)!==Array.isArray(t))return!1;if(Array.isArray(e)){const r=t;return e.length===r.length&&e.every((a,l)=>F(a,r[l]))}const n=e,s=t,i=Object.keys(n);return i.length!==Object.keys(s).length?!1:i.every(r=>Object.prototype.hasOwnProperty.call(s,r)&&F(n[r],s[r]))}function Y(e,t,n){return ue(e,t,n).text}function ue(e,t,n){const s=q(e),i=o=>({text:k(t,s),exact:!1,reason:o});let r;try{r=new it(e).parseDocument()}catch(o){return i(o instanceof Error?o.message:String(o))}if(H(r))return i("duplicate keys");const a=[],l={text:e,format:s,edits:a,options:n,compact:!e.trimEnd().includes(`
11
+ `)};ee(l,r,t,"",!1);const f=rt(e,a);try{const o=JSON.parse(s.bom?f.slice(1):f);if(!F(o,t))return i("patch did not read back")}catch{return i("patch was not valid JSON")}return{text:f,exact:!0}}class it{constructor(t){se(this,"pos",0);this.text=t}parseDocument(){this.text.charCodeAt(0)===65279&&(this.pos=1);const t=this.value();if(this.ws(),this.pos<this.text.length)throw new Error(`Unexpected text at ${this.pos}`);return t}ws(){for(;this.pos<this.text.length&&/\s/.test(this.text[this.pos]);)this.pos++}value(){this.ws();const t=this.text[this.pos];if(t==="{")return this.object();if(t==="[")return this.array();const n=this.pos;if(t==='"')return{kind:"scalar",start:n,end:this.stringEnd(),value:JSON.parse(this.slice(n))};const s=/^(?:-?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?|true|false|null)/.exec(this.text.slice(n,n+64));if(!s)throw new Error(`Unexpected token at ${n}`);return this.pos=n+s[0].length,{kind:"scalar",start:n,end:this.pos,value:JSON.parse(s[0])}}slice(t){return this.text.slice(t,this.pos)}stringEnd(){for(this.pos++;this.pos<this.text.length;){const t=this.text[this.pos];if(t==="\\"){this.pos+=2;continue}if(this.pos++,t==='"')return this.pos}throw new Error("Unterminated string")}object(){const t=this.pos++,n=[];if(this.ws(),this.text[this.pos]==="}")return{kind:"object",start:t,end:++this.pos,members:n};for(;;){this.ws();const s=this.pos;if(this.text[this.pos]!=='"')throw new Error(`Expected a key at ${this.pos}`);const i=JSON.parse(this.text.slice(s,this.stringEnd()));if(this.ws(),this.text[this.pos]!==":")throw new Error(`Expected ':' at ${this.pos}`);this.pos++,n.push({key:i,start:s,value:this.value()}),this.ws();const r=this.text[this.pos++];if(r==="}")return{kind:"object",start:t,end:this.pos,members:n};if(r!==",")throw new Error(`Expected ',' or '}' at ${this.pos-1}`)}}array(){const t=this.pos++,n=[];if(this.ws(),this.text[this.pos]==="]")return{kind:"array",start:t,end:++this.pos,items:n};for(;;){n.push(this.value()),this.ws();const s=this.text[this.pos++];if(s==="]")return{kind:"array",start:t,end:this.pos,items:n};if(s!==",")throw new Error(`Expected ',' or ']' at ${this.pos-1}`)}}}function H(e){if(e.kind==="object"){const t=new Set;for(const n of e.members){if(t.has(n.key)||H(n.value))return!0;t.add(n.key)}}else if(e.kind==="array")return e.items.some(H);return!1}function P(e){if(e.kind==="scalar")return e.value;if(e.kind==="array")return e.items.map(P);const t={};for(const n of e.members)t[n.key]=P(n.value);return t}function A(e,t,n){if(e===null||typeof e!="object")return e===void 0?"null":JSON.stringify(e);const s=n+t.indent,i=t.colonSpace?": ":":";if(Array.isArray(e))return e.length===0?"[]":`[${t.eol}${e.map(a=>s+A(a,t,s)).join(`,${t.eol}`)}${t.eol}${n}]`;const r=Object.entries(e).filter(([,a])=>a!==void 0);return r.length===0?"{}":`{${t.eol}${r.map(([a,l])=>`${s}${JSON.stringify(a)}${i}${A(l,t,s)}`).join(`,${t.eol}`)}${t.eol}${n}}`}function I(e,t,n=!1){if(e===null||typeof e!="object")return e===void 0?"null":JSON.stringify(e);const s=t.colonSpace?": ":":",i=n?",":", ";if(Array.isArray(e))return`[${e.map(l=>I(l,t,n)).join(i)}]`;const r=Object.entries(e).filter(([,l])=>l!==void 0),a=n?"":" ";return r.length===0?"{}":`{${a}${r.map(([l,f])=>`${JSON.stringify(l)}${s}${I(f,t,n)}`).join(i)}${a}}`}const pe=e=>e.compact?",":", ";function rt(e,t){let n=e;for(const s of[...t].sort((i,r)=>r.start-i.start))n=n.slice(0,s.start)+s.text+n.slice(s.end);return n}function J(e,t){var s;const n=e.lastIndexOf(`
12
12
  `,t-1)+1;return((s=/^[ \t]*/.exec(e.slice(n,t)))==null?void 0:s[0])??""}function me(e,t){return!e.slice(t.start,t.end).includes(`
13
- `)}function Q(e,t,n){return e.compact?!0:t.kind==="scalar"||(t.kind==="object"?t.members.length===0:t.items.length===0)?n:me(e.text,t)}function x(e,t,n,s){const i=Q(e,t,s);e.edits.push({start:t.start,end:t.end,text:i?I(n,e.format,e.compact):E(n,e.format,J(e.text,t.start))})}const ye=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function ee(e,t,n,s,i){if(t.kind==="scalar"){if(t.value===n)return;x(e,t,n,i);return}F(P(t),n)||(t.kind==="object"&&ye(n)?ot(e,t,n,s,i):t.kind==="array"&&Array.isArray(n)?lt(e,t,n,s,i):x(e,t,n,i))}function he(e,t,n){return n!==void 0?J(e.text,n):J(e.text,t.start)+e.format.indent}function ot(e,t,n,s,i){var d;const r=Q(e,t,i),a=t.members.filter(u=>Object.prototype.hasOwnProperty.call(n,u.key)&&n[u.key]!==void 0),l=Object.keys(n).filter(u=>n[u]!==void 0&&!t.members.some(y=>y.key===u));if(a.length===0&&t.members.length>0){x(e,t,n,i);return}for(const u of a)ee(e,u.value,n[u.key],`${s}/${ut(u.key)}`,r);if(ge(e,t.members.map(u=>({start:u.start,end:u.value.end})),t.members.map(u=>a.includes(u))),l.length===0)return;const f=e.format.colonSpace?": ":":";if(r){const u=l.map(y=>`${JSON.stringify(y)}${f}${I(n[y],e.format,e.compact)}`);ke(e,t,a.length>0?a[a.length-1].value.end:void 0,u);return}const o=he(e,t,(d=t.members[0])==null?void 0:d.start),c=l.map(u=>`${o}${JSON.stringify(u)}${f}${E(n[u],e.format,o)}`);be(e,t,a.length>0?a[a.length-1].value.end:void 0,c)}const at=["name","id","code","key","slug","state","Id"];function ct(e,t,n,s){var f,o;const i=[...n,...s];if(i.length===0||!i.every(ye))return;const r=(c,d)=>{const u=c.map(y=>y[d]);return u.every(y=>typeof y=="string"||typeof y=="number")&&new Set(u).size===u.length},a=(o=(f=e.options)==null?void 0:f.arrayKey)==null?void 0:o.call(f,t);return(a?[a]:at).find(c=>r(n,c)&&r(s,c))}function lt(e,t,n,s,i){var g;const r=Q(e,t,i),a=t.items.map(P),l=ct(e,s,a,n),f=p=>p[l],o=l!==void 0?a.map(p=>{const m=f(p);return n.findIndex(k=>f(k)===m)}):ft(a,n);{const p=new Set(o.filter(m=>m>=0));for(let m=0;m<o.length;m++){if(o[m]>=0)continue;let k=-1;for(let h=m-1;h>=0;h--)if(o[h]>=0){k=o[h];break}let j=n.length;for(let h=m+1;h<o.length;h++)if(o[h]>=0){j=o[h];break}for(let h=k+1;h<j;h++)if(!p.has(h)){o[m]=h,p.add(h);break}}}const c=o.filter(p=>p>=0);if(c.some((p,m)=>m>0&&p<c[m-1])){x(e,t,n,i);return}if(c.length===0&&t.items.length>0){x(e,t,n,i);return}t.items.forEach((p,m)=>{o[m]>=0&&ee(e,p,n[o[m]],`${s}/${o[m]}`,r)}),ge(e,t.items.map(p=>({start:p.start,end:p.end})),o.map(p=>p>=0));const d=t.items.length>0&&t.items.every(p=>p.kind!=="scalar"&&me(e.text,p)),u=he(e,t,(g=t.items[0])==null?void 0:g.start),y=new Map;n.forEach((p,m)=>{if(o.includes(m))return;let k;for(let K=t.items.length-1;K>=0;K--)if(o[K]>=0&&o[K]<m){k=K;break}const j=r?I(p,e.format,e.compact):d?`${u}${I(p,e.format)}`:`${u}${E(p,e.format,u)}`,h=y.get(k)??[];h.push(j),y.set(k,h)});for(const[p,m]of y){const k=p===void 0?void 0:t.items[p].end;if(p===void 0&&c.length>0){const j=t.items[o.findIndex(K=>K>=0)],h=r?pe(e):`,${e.format.eol}`;e.edits.push({start:j.start,end:j.start,text:r?m.join(h)+h:m.join(h).trimStart()+h+u});continue}r?ke(e,t,k,m):be(e,t,k,m)}}const dt=4e6;function ft(e,t){const n=e.length,s=t.length;if(n*s>dt)return e.map((c,d)=>d<s?d:-1);const i=e.map(c=>JSON.stringify(c)),r=t.map(c=>JSON.stringify(c)),a=Array.from({length:n+1},()=>new Uint32Array(s+1));for(let c=n-1;c>=0;c--)for(let d=s-1;d>=0;d--)a[c][d]=i[c]===r[d]?a[c+1][d+1]+1:Math.max(a[c+1][d],a[c][d+1]);const l=new Array(n).fill(-1);let f=0,o=0;for(;f<n&&o<s;)i[f]===r[o]?l[f++]=o++:a[f+1][o]>=a[f][o+1]?f++:o++;return l}function ge(e,t,n){for(let s=0;s<t.length;s++){if(n[s])continue;let i=s;for(;i+1<t.length&&!n[i+1];)i++;i+1<t.length?e.edits.push({start:t[s].start,end:t[i+1].start,text:""}):s>0?e.edits.push({start:t[s-1].end,end:t[i].end,text:""}):e.edits.push({start:t[s].start,end:t[i].end,text:""}),s=i}}function be(e,t,n,s){const i=e.format.eol;if(n!==void 0){e.edits.push({start:n,end:n,text:`,${i}${s.join(`,${i}`)}`});return}const r=t.end-1;if((t.kind==="object"?t.members.length:t.items.length)===0)e.edits.push({start:t.start+1,end:r,text:`${i}${s.join(`,${i}`)}${i}${J(e.text,t.start)}`});else{const l=t.kind==="object"?t.members[0].start:t.items[0].start;e.edits.push({start:l,end:l,text:`${s.join(`,${i}`).trimStart()}`})}}function ke(e,t,n,s){const i=pe(e);if(n!==void 0){e.edits.push({start:n,end:n,text:`${i}${s.join(i)}`});return}const r=t.kind==="object"&&!e.compact?" ":"";e.edits.push({start:t.start+1,end:t.end-1,text:`${r}${s.join(i)}${r}`})}function ut(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}const O=e=>e.slice(e.lastIndexOf("/")+1),pt=e=>e.charCodeAt(0)===65279?e.slice(1):e;function L(e){return{id:e.id,label:e.label,labelKey:e.labelKey,icon:e.icon,match:e.match,editor:e.editor,decode(t,n){return e.select(A(t[0].text).value,n)},encode(t,n,s){const i=n[0].text,r=A(i).value,a=e.assign(r,t,s);return{files:[{path:n[0].path,text:Y(i,a,{arrayKey:e.arrayKey})}]}}}}const D=L({id:"json",label:"JSON",labelKey:"devStudio.kind.json",icon:"code",match:e=>e.toLowerCase().endsWith(".json"),editor:"json",select:e=>e,assign:(e,t)=>t}),_={id:"text",label:"Text",labelKey:"devStudio.kind.text",icon:"file",match:()=>!0,editor:"text",decode:e=>e[0].text,encode:(e,t)=>({files:[{path:t[0].path,text:fe(e,t[0].text)}]})};function Se(e,t){return e.find(n=>n.match(t))??(D.match(t)?D:_)}function mt(e,t,n){for(const s of[D,_])if(s.match(e.path))try{const i=s.decode([e],n);return{key:`${s.id}:${e.path}`,kind:s,paths:[e.path],label:O(e.path),model:i,error:t}}catch{}return{key:`text:${e.path}`,kind:_,paths:[e.path],label:O(e.path),model:e.text,error:t}}function yt(e,t,n,s){var l,f;const i=e.encode(t,n,s),r=new Map(n.map(o=>[o.path,o.text])),a=((l=i.files.find(o=>r.get(o.path)!==o.text))==null?void 0:l.path)??((f=i.deleted)==null?void 0:f.find(o=>r.has(o)));if(a!==void 0)throw new Error(`${O(a)} would not be stored as it is`)}function ht(e,t,n){const s=new Map;for(const r of t){const a=Se(e,r.path),l=a.group?a.group(r.path):r.path,f=`${a.id}:${l}`,o=s.get(f)??{kind:a,group:l,files:[]};o.files.push(r),s.set(f,o)}const i=[];for(const[r,{kind:a,group:l,files:f}]of s){const o=f.map(d=>d.path).sort(),c=O(a.group?l:o[0]);try{const d=a.decode(f,n);yt(a,d,f,n),i.push({key:r,kind:a,paths:o,label:c,model:d})}catch(d){const u=d instanceof Error?d.message:String(d);for(const y of f)i.push(mt(y,u,n))}}return i.sort((r,a)=>r.label.localeCompare(a.label))}function gt(e,t,n,s){const i=n.filter(f=>e.paths.includes(f.path)),r=e.kind.encode(t,i,s),a=new Map(n.map(f=>[f.path,f])),l=[];for(const f of r.files){const o=a.get(f.path);o&&o.text===f.text||l.push({type:"write",path:f.path,text:f.text,baseVersion:o==null?void 0:o.version})}for(const f of r.deleted??[]){const o=a.get(f);o&&l.push({type:"delete",path:f,baseVersion:o.version})}return l}function ve(e,t){try{return JSON.parse(pt(e))}catch{return t}}const v=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),w=(...e)=>t=>{const n=t.toLowerCase();return e.some(s=>n.endsWith(s.toLowerCase()))};function C(e){return L({id:e.id,label:e.label,labelKey:e.labelKey,icon:e.icon,editor:e.editor,match:e.match,select:t=>{if(Array.isArray(t))return t;const n=v(t)?t[e.property]:void 0;return Array.isArray(n)?n:[]},assign:(t,n)=>Array.isArray(t)?n:v(t)&&!(e.property in t)&&n.length===0?t:{...v(t)?t:{},[e.property]:n},arrayKey:e.itemKey?()=>e.itemKey:void 0})}function te(e){const t=C(e);return{...t,decode:(n,s)=>t.decode(n,s).map((i,r)=>e.toItem(i,r)),encode:(n,s,i)=>t.encode(n.map(r=>e.fromItem(r)),s,i)}}function ne(e){return L({...e,select:t=>v(t)?t:{},assign:(t,n)=>n})}const bt=/^(.*)\.([a-z]{2,3}(?:-[A-Za-z]{2,4})?)\.i18n\.json$/i,kt=e=>{const t=bt.exec(e);return t?{group:t[1],locale:t[2]}:null},X=e=>v(e)&&Object.values(e).every(t=>typeof t=="string");function we(e){if(v(e)){for(const t of["translations","keys"])if(t in e){if(X(e[t]))return e[t];throw new Error(`"${t}" is not a flat map of texts`)}if(X(e))return e}throw new Error("no translations in this file")}function Z(e,t){return v(e)?v(e.translations)?{...e,translations:t}:v(e.keys)?{...e,keys:t}:X(e)?t:{...e,translations:t}:{translations:t}}function $e(e={}){const t=e.parse??kt,n=e.pathFor??((s,i)=>`${s}.${i}.i18n.json`);return{id:e.id??"i18n",label:e.label??"Translations",labelKey:e.labelKey??"devStudio.kind.i18n",icon:"globe",editor:"i18n",match:s=>t(s)!==null,group:s=>{var i;return((i=t(s))==null?void 0:i.group)??s},decode(s){const i={};for(const r of s){const a=t(r.path);a&&(i[a.locale]={...we(A(r.text).value)})}return i},encode(s,i){const r=new Map;let a="";for(const c of i){const d=t(c.path);d&&(r.set(d.locale,c),a=d.group)}const l=r.get("en")??i[0],f=[];for(const[c,d]of Object.entries(s)){const u=r.get(c);if(u){const g=A(u.text).value;f.push({path:u.path,text:Y(u.text,Z(g,d))});continue}const y=n(a||O((l==null?void 0:l.path)??"module"),c);if(l){const g=A(l.text).value,p=v(g)&&"locale"in g?{...g,locale:c}:g;f.push({path:y,text:S(Z(p,d),q(l.text))})}else f.push({path:y,text:S({locale:c,translations:d})})}const o=[...r.entries()].filter(([c])=>!(c in s)).map(([,c])=>c.path);return{files:f,deleted:o}}}}const $=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),je=["frontend","backend","noCode","sql"],St=["preInstall","postInstall","preUninstall","postUninstall"];function Ke(e){switch(e){case"frontend":return["typescript","javascript"];case"backend":return["csharp","javascript"];case"sql":return["sql"];case"noCode":return[]}}const vt=new Set(["read","filter","map","aggregate","set","if","forEach","write","callScript","return"]),Oe=e=>Array.isArray(e)&&e.every(t=>$(t)&&typeof t.id=="string"&&vt.has(String(t.type)));function R(e){if(je.includes(e.kind))return e.kind;if(e.source===void 0&&Oe(e.steps))return"noCode";const t=typeof e.language=="string"?e.language.toLowerCase():"";return t.endsWith("sql")||e.source===void 0&&typeof e.sql=="string"?"sql":/^(csharp|c#|cs\b)/.test(t)?"backend":"frontend"}const Ae=["id","displayName","description","language","category","trigger","returnType","source","sourcePath"],wt=e=>Array.isArray(e)&&e.every(t=>$(t)&&typeof t.name=="string");function Ee(e,t){const n=`#${t+1}`;if(!$(e)||typeof e.name!="string"||!e.name){const l=$(e)&&typeof e.displayName=="string"?e.displayName:n;return{key:`#${t}`,label:l,rawReason:"no name",source:e}}const s=e.name,i=typeof e.displayName=="string"&&e.displayName?e.displayName:s,r=l=>({key:s,label:i,rawReason:l,source:e}),a={name:s,kind:R(e)};for(const l of Ae){const f=e[l];if(f!==void 0){if(typeof f!="string")return r(`"${l}" is not text`);a[l]=f}}if(e.parameters!==void 0){if(!wt(e.parameters))return r('"parameters" is not a list of named parameters');a.parameters=e.parameters}if(a.kind==="noCode"){if(e.steps!==void 0&&!Oe(e.steps))return r('"steps" are not no-code steps');a.steps=e.steps??[]}return{key:s,label:i,definition:a,source:e}}function Ie(e){const t=e.definition;if(!t)return e.source;const n=$(e.source)?e.source:{},s={...n,name:t.name};for(const i of Ae)t[i]===void 0?delete s[i]:s[i]=t[i];return t.parameters===void 0?delete s.parameters:s.parameters=t.parameters,t.kind==="noCode"?s.steps=t.steps??[]:R(n)==="noCode"&&delete s.steps,delete s.kind,("kind"in n||R(s)!==t.kind)&&(s.kind=t.kind),s}function z(e){const t=new Set;return e.map((n,s)=>{const i=Ee(n,s);return t.has(i.key)&&(i.key=`${i.key}#${s}`),t.add(i.key),i})}function ie(e,t){if(!$(e)||!Object.values(e).every(n=>Array.isArray(n)&&n.every(s=>typeof s=="string")))throw new Error(`"${t}" is not lists of SQL statements per phase`);return e}function Ne(e){const t=e.property??"scripts",n=e.phasesProperty??"phases",s=t===n,i=r=>r.scripts.map(Ie);return L({id:e.id??"scripts",label:e.label??"Scripts",labelKey:e.labelKey??"devStudio.kind.scripts",icon:e.icon??"code",editor:"scriptList",match:e.match,select:r=>{if(Array.isArray(r))return{scripts:z(r),...s?{holds:"scripts"}:{}};if(!$(r)||r[t]===void 0&&r[n]===void 0)throw new Error(`no "${t}" in this file`);const a=r[t];if(s)return Array.isArray(a)?{scripts:z(a),holds:"scripts"}:{scripts:[],phases:ie(a,t),holds:"phases"};if(a!==void 0&&!Array.isArray(a))throw new Error(`"${t}" is not a list`);const l=r[n];return{scripts:z(a??[]),...l!==void 0?{phases:ie(l,n)}:{}}},assign:(r,a)=>{if(a.holds==="phases"&&a.scripts.length>0)throw new Error("This file holds database scripts only; add scripts to another file.");if(Array.isArray(r)&&a.phases===void 0)return i(a);const l=$(r)?r:{};if(s)return{...l,[t]:a.holds==="phases"?a.phases??{}:i(a)};const f={...l};return(t in l||a.scripts.length>0)&&(f[t]=i(a)),a.phases===void 0?delete f[n]:f[n]=a.phases,f},arrayKey:r=>r===`/${t}`?"name":void 0})}function Te(e){const n=e.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").split(/[^A-Za-z0-9]+/).filter(Boolean).map((s,i)=>i===0?s[0].toLowerCase()+s.slice(1):s[0].toUpperCase()+s.slice(1)).join("");return/^[A-Za-z_]/.test(n)?n:`script${n}`}function $t(e){const t=Te(e.name),n=e.language??Ke(e.kind)[0],s={name:t,kind:e.kind,...e.name!==t?{displayName:e.name}:{},...n?{language:n}:{},...e.category?{category:e.category}:{},...e.trigger?{trigger:e.trigger}:{},parameters:[]},i=t[0].toUpperCase()+t.slice(1);switch(e.kind){case"noCode":return{...s,steps:[]};case"sql":return{...s,source:`-- ${e.name}
13
+ `)}function Q(e,t,n){return e.compact?!0:t.kind==="scalar"||(t.kind==="object"?t.members.length===0:t.items.length===0)?n:me(e.text,t)}function x(e,t,n,s){const i=Q(e,t,s);e.edits.push({start:t.start,end:t.end,text:i?I(n,e.format,e.compact):A(n,e.format,J(e.text,t.start))})}const ye=e=>typeof e=="object"&&e!==null&&!Array.isArray(e);function ee(e,t,n,s,i){if(t.kind==="scalar"){if(t.value===n)return;x(e,t,n,i);return}F(P(t),n)||(t.kind==="object"&&ye(n)?ot(e,t,n,s,i):t.kind==="array"&&Array.isArray(n)?lt(e,t,n,s,i):x(e,t,n,i))}function he(e,t,n){return n!==void 0?J(e.text,n):J(e.text,t.start)+e.format.indent}function ot(e,t,n,s,i){var d;const r=Q(e,t,i),a=t.members.filter(u=>Object.prototype.hasOwnProperty.call(n,u.key)&&n[u.key]!==void 0),l=Object.keys(n).filter(u=>n[u]!==void 0&&!t.members.some(y=>y.key===u));if(a.length===0&&t.members.length>0){x(e,t,n,i);return}for(const u of a)ee(e,u.value,n[u.key],`${s}/${ut(u.key)}`,r);if(ge(e,t.members.map(u=>({start:u.start,end:u.value.end})),t.members.map(u=>a.includes(u))),l.length===0)return;const f=e.format.colonSpace?": ":":";if(r){const u=l.map(y=>`${JSON.stringify(y)}${f}${I(n[y],e.format,e.compact)}`);Se(e,t,a.length>0?a[a.length-1].value.end:void 0,u);return}const o=he(e,t,(d=t.members[0])==null?void 0:d.start),c=l.map(u=>`${o}${JSON.stringify(u)}${f}${A(n[u],e.format,o)}`);be(e,t,a.length>0?a[a.length-1].value.end:void 0,c)}const at=["name","id","code","key","slug","state","Id"];function ct(e,t,n,s){var f,o;const i=[...n,...s];if(i.length===0||!i.every(ye))return;const r=(c,d)=>{const u=c.map(y=>y[d]);return u.every(y=>typeof y=="string"||typeof y=="number")&&new Set(u).size===u.length},a=(o=(f=e.options)==null?void 0:f.arrayKey)==null?void 0:o.call(f,t);return(a?[a]:at).find(c=>r(n,c)&&r(s,c))}function lt(e,t,n,s,i){var g;const r=Q(e,t,i),a=t.items.map(P),l=ct(e,s,a,n),f=p=>p[l],o=l!==void 0?a.map(p=>{const m=f(p);return n.findIndex(S=>f(S)===m)}):ft(a,n);{const p=new Set(o.filter(m=>m>=0));for(let m=0;m<o.length;m++){if(o[m]>=0)continue;let S=-1;for(let h=m-1;h>=0;h--)if(o[h]>=0){S=o[h];break}let j=n.length;for(let h=m+1;h<o.length;h++)if(o[h]>=0){j=o[h];break}for(let h=S+1;h<j;h++)if(!p.has(h)){o[m]=h,p.add(h);break}}}const c=o.filter(p=>p>=0);if(c.some((p,m)=>m>0&&p<c[m-1])){x(e,t,n,i);return}if(c.length===0&&t.items.length>0){x(e,t,n,i);return}t.items.forEach((p,m)=>{o[m]>=0&&ee(e,p,n[o[m]],`${s}/${o[m]}`,r)}),ge(e,t.items.map(p=>({start:p.start,end:p.end})),o.map(p=>p>=0));const d=t.items.length>0&&t.items.every(p=>p.kind!=="scalar"&&me(e.text,p)),u=he(e,t,(g=t.items[0])==null?void 0:g.start),y=new Map;n.forEach((p,m)=>{if(o.includes(m))return;let S;for(let K=t.items.length-1;K>=0;K--)if(o[K]>=0&&o[K]<m){S=K;break}const j=r?I(p,e.format,e.compact):d?`${u}${I(p,e.format)}`:`${u}${A(p,e.format,u)}`,h=y.get(S)??[];h.push(j),y.set(S,h)});for(const[p,m]of y){const S=p===void 0?void 0:t.items[p].end;if(p===void 0&&c.length>0){const j=t.items[o.findIndex(K=>K>=0)],h=r?pe(e):`,${e.format.eol}`;e.edits.push({start:j.start,end:j.start,text:r?m.join(h)+h:m.join(h).trimStart()+h+u});continue}r?Se(e,t,S,m):be(e,t,S,m)}}const dt=4e6;function ft(e,t){const n=e.length,s=t.length;if(n*s>dt)return e.map((c,d)=>d<s?d:-1);const i=e.map(c=>JSON.stringify(c)),r=t.map(c=>JSON.stringify(c)),a=Array.from({length:n+1},()=>new Uint32Array(s+1));for(let c=n-1;c>=0;c--)for(let d=s-1;d>=0;d--)a[c][d]=i[c]===r[d]?a[c+1][d+1]+1:Math.max(a[c+1][d],a[c][d+1]);const l=new Array(n).fill(-1);let f=0,o=0;for(;f<n&&o<s;)i[f]===r[o]?l[f++]=o++:a[f+1][o]>=a[f][o+1]?f++:o++;return l}function ge(e,t,n){for(let s=0;s<t.length;s++){if(n[s])continue;let i=s;for(;i+1<t.length&&!n[i+1];)i++;i+1<t.length?e.edits.push({start:t[s].start,end:t[i+1].start,text:""}):s>0?e.edits.push({start:t[s-1].end,end:t[i].end,text:""}):e.edits.push({start:t[s].start,end:t[i].end,text:""}),s=i}}function be(e,t,n,s){const i=e.format.eol;if(n!==void 0){e.edits.push({start:n,end:n,text:`,${i}${s.join(`,${i}`)}`});return}const r=t.end-1;if((t.kind==="object"?t.members.length:t.items.length)===0)e.edits.push({start:t.start+1,end:r,text:`${i}${s.join(`,${i}`)}${i}${J(e.text,t.start)}`});else{const l=t.kind==="object"?t.members[0].start:t.items[0].start;e.edits.push({start:l,end:l,text:`${s.join(`,${i}`).trimStart()}`})}}function Se(e,t,n,s){const i=pe(e);if(n!==void 0){e.edits.push({start:n,end:n,text:`${i}${s.join(i)}`});return}const r=t.kind==="object"&&!e.compact?" ":"";e.edits.push({start:t.start+1,end:t.end-1,text:`${r}${s.join(i)}${r}`})}function ut(e){return e.replace(/~/g,"~0").replace(/\//g,"~1")}const O=e=>e.slice(e.lastIndexOf("/")+1),pt=e=>e.charCodeAt(0)===65279?e.slice(1):e;function L(e){return{id:e.id,label:e.label,labelKey:e.labelKey,icon:e.icon,match:e.match,editor:e.editor,decode(t,n){return e.select(E(t[0].text).value,n)},encode(t,n,s){const i=n[0].text,r=E(i).value,a=e.assign(r,t,s);return{files:[{path:n[0].path,text:Y(i,a,{arrayKey:e.arrayKey})}]}}}}const D=L({id:"json",label:"JSON",labelKey:"devStudio.kind.json",icon:"code",match:e=>e.toLowerCase().endsWith(".json"),editor:"json",select:e=>e,assign:(e,t)=>t}),_={id:"text",label:"Text",labelKey:"devStudio.kind.text",icon:"file",match:()=>!0,editor:"text",decode:e=>e[0].text,encode:(e,t)=>({files:[{path:t[0].path,text:fe(e,t[0].text)}]})};function ke(e,t){return e.find(n=>n.match(t))??(D.match(t)?D:_)}function mt(e,t,n){for(const s of[D,_])if(s.match(e.path))try{const i=s.decode([e],n);return{key:`${s.id}:${e.path}`,kind:s,paths:[e.path],label:O(e.path),model:i,error:t}}catch{}return{key:`text:${e.path}`,kind:_,paths:[e.path],label:O(e.path),model:e.text,error:t}}function yt(e,t,n,s){var l,f;const i=e.encode(t,n,s),r=new Map(n.map(o=>[o.path,o.text])),a=((l=i.files.find(o=>r.get(o.path)!==o.text))==null?void 0:l.path)??((f=i.deleted)==null?void 0:f.find(o=>r.has(o)));if(a!==void 0)throw new Error(`${O(a)} would not be stored as it is`)}function ht(e,t,n){const s=new Map;for(const r of t){const a=ke(e,r.path),l=a.group?a.group(r.path):r.path,f=`${a.id}:${l}`,o=s.get(f)??{kind:a,group:l,files:[]};o.files.push(r),s.set(f,o)}const i=[];for(const[r,{kind:a,group:l,files:f}]of s){const o=f.map(d=>d.path).sort(),c=O(a.group?l:o[0]);try{const d=a.decode(f,n);yt(a,d,f,n),i.push({key:r,kind:a,paths:o,label:c,model:d})}catch(d){const u=d instanceof Error?d.message:String(d);for(const y of f)i.push(mt(y,u,n))}}return i.sort((r,a)=>r.label.localeCompare(a.label))}function gt(e,t,n,s){const i=n.filter(f=>e.paths.includes(f.path)),r=e.kind.encode(t,i,s),a=new Map(n.map(f=>[f.path,f])),l=[];for(const f of r.files){const o=a.get(f.path);o&&o.text===f.text||l.push({type:"write",path:f.path,text:f.text,baseVersion:o==null?void 0:o.version})}for(const f of r.deleted??[]){const o=a.get(f);o&&l.push({type:"delete",path:f,baseVersion:o.version})}return l}function ve(e,t){try{return JSON.parse(pt(e))}catch{return t}}const v=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),w=(...e)=>t=>{const n=t.toLowerCase();return e.some(s=>n.endsWith(s.toLowerCase()))};function C(e){return L({id:e.id,label:e.label,labelKey:e.labelKey,icon:e.icon,editor:e.editor,match:e.match,select:t=>{if(Array.isArray(t))return t;const n=v(t)?t[e.property]:void 0;return Array.isArray(n)?n:[]},assign:(t,n)=>Array.isArray(t)?n:v(t)&&!(e.property in t)&&n.length===0?t:{...v(t)?t:{},[e.property]:n},arrayKey:e.itemKey?()=>e.itemKey:void 0})}function te(e){const t=C(e);return{...t,decode:(n,s)=>t.decode(n,s).map((i,r)=>e.toItem(i,r)),encode:(n,s,i)=>t.encode(n.map(r=>e.fromItem(r)),s,i)}}function ne(e){return L({...e,select:t=>v(t)?t:{},assign:(t,n)=>n})}const bt=/^(.*)\.([a-z]{2,3}(?:-[A-Za-z]{2,4})?)\.i18n\.json$/i,St=e=>{const t=bt.exec(e);return t?{group:t[1],locale:t[2]}:null},X=e=>v(e)&&Object.values(e).every(t=>typeof t=="string");function we(e){if(v(e)){for(const t of["translations","keys"])if(t in e){if(X(e[t]))return e[t];throw new Error(`"${t}" is not a flat map of texts`)}if(X(e))return e}throw new Error("no translations in this file")}function Z(e,t){return v(e)?v(e.translations)?{...e,translations:t}:v(e.keys)?{...e,keys:t}:X(e)?t:{...e,translations:t}:{translations:t}}function $e(e={}){const t=e.parse??St,n=e.pathFor??((s,i)=>`${s}.${i}.i18n.json`);return{id:e.id??"i18n",label:e.label??"Translations",labelKey:e.labelKey??"devStudio.kind.i18n",icon:"globe",editor:"i18n",match:s=>t(s)!==null,group:s=>{var i;return((i=t(s))==null?void 0:i.group)??s},decode(s){const i={};for(const r of s){const a=t(r.path);a&&(i[a.locale]={...we(E(r.text).value)})}return i},encode(s,i){const r=new Map;let a="";for(const c of i){const d=t(c.path);d&&(r.set(d.locale,c),a=d.group)}const l=r.get("en")??i[0],f=[];for(const[c,d]of Object.entries(s)){const u=r.get(c);if(u){const g=E(u.text).value;f.push({path:u.path,text:Y(u.text,Z(g,d))});continue}const y=n(a||O((l==null?void 0:l.path)??"module"),c);if(l){const g=E(l.text).value,p=v(g)&&"locale"in g?{...g,locale:c}:g;f.push({path:y,text:k(Z(p,d),q(l.text))})}else f.push({path:y,text:k({locale:c,translations:d})})}const o=[...r.entries()].filter(([c])=>!(c in s)).map(([,c])=>c.path);return{files:f,deleted:o}}}}const $=e=>typeof e=="object"&&e!==null&&!Array.isArray(e),je=["frontend","backend","noCode","sql"],kt=["preInstall","postInstall","preUninstall","postUninstall"];function Ke(e){switch(e){case"frontend":return["typescript","javascript"];case"backend":return["csharp","javascript"];case"sql":return["sql"];case"noCode":return[]}}const vt=new Set(["read","filter","map","aggregate","set","if","forEach","write","callScript","return"]),Oe=e=>Array.isArray(e)&&e.every(t=>$(t)&&typeof t.id=="string"&&vt.has(String(t.type)));function R(e){if(je.includes(e.kind))return e.kind;if(e.source===void 0&&Oe(e.steps))return"noCode";const t=typeof e.language=="string"?e.language.toLowerCase():"";return t.endsWith("sql")||e.source===void 0&&typeof e.sql=="string"?"sql":/^(csharp|c#|cs\b)/.test(t)?"backend":"frontend"}const Ee=["id","displayName","description","language","category","trigger","returnType","source","sourcePath"],wt=e=>Array.isArray(e)&&e.every(t=>$(t)&&typeof t.name=="string");function Ae(e,t){const n=`#${t+1}`;if(!$(e)||typeof e.name!="string"||!e.name){const l=$(e)&&typeof e.displayName=="string"?e.displayName:n;return{key:`#${t}`,label:l,rawReason:"no name",source:e}}const s=e.name,i=typeof e.displayName=="string"&&e.displayName?e.displayName:s,r=l=>({key:s,label:i,rawReason:l,source:e}),a={name:s,kind:R(e)};for(const l of Ee){const f=e[l];if(f!==void 0){if(typeof f!="string")return r(`"${l}" is not text`);a[l]=f}}if(e.parameters!==void 0){if(!wt(e.parameters))return r('"parameters" is not a list of named parameters');a.parameters=e.parameters}if(a.kind==="noCode"){if(e.steps!==void 0&&!Oe(e.steps))return r('"steps" are not no-code steps');a.steps=e.steps??[]}return{key:s,label:i,definition:a,source:e}}function Ie(e){const t=e.definition;if(!t)return e.source;const n=$(e.source)?e.source:{},s={...n,name:t.name};for(const i of Ee)t[i]===void 0?delete s[i]:s[i]=t[i];return t.parameters===void 0?delete s.parameters:s.parameters=t.parameters,t.kind==="noCode"?s.steps=t.steps??[]:R(n)==="noCode"&&delete s.steps,delete s.kind,("kind"in n||R(s)!==t.kind)&&(s.kind=t.kind),s}function z(e){const t=new Set;return e.map((n,s)=>{const i=Ae(n,s);return t.has(i.key)&&(i.key=`${i.key}#${s}`),t.add(i.key),i})}function ie(e,t){if(!$(e)||!Object.values(e).every(n=>Array.isArray(n)&&n.every(s=>typeof s=="string")))throw new Error(`"${t}" is not lists of SQL statements per phase`);return e}function Ne(e){const t=e.property??"scripts",n=e.phasesProperty??"phases",s=t===n,i=r=>r.scripts.map(Ie);return L({id:e.id??"scripts",label:e.label??"Scripts",labelKey:e.labelKey??"devStudio.kind.scripts",icon:e.icon??"code",editor:"scriptList",match:e.match,select:r=>{if(Array.isArray(r))return{scripts:z(r),...s?{holds:"scripts"}:{}};if(!$(r)||r[t]===void 0&&r[n]===void 0)throw new Error(`no "${t}" in this file`);const a=r[t];if(s)return Array.isArray(a)?{scripts:z(a),holds:"scripts"}:{scripts:[],phases:ie(a,t),holds:"phases"};if(a!==void 0&&!Array.isArray(a))throw new Error(`"${t}" is not a list`);const l=r[n];return{scripts:z(a??[]),...l!==void 0?{phases:ie(l,n)}:{}}},assign:(r,a)=>{if(a.holds==="phases"&&a.scripts.length>0)throw new Error("This file holds database scripts only; add scripts to another file.");if(Array.isArray(r)&&a.phases===void 0)return i(a);const l=$(r)?r:{};if(s)return{...l,[t]:a.holds==="phases"?a.phases??{}:i(a)};const f={...l};return(t in l||a.scripts.length>0)&&(f[t]=i(a)),a.phases===void 0?delete f[n]:f[n]=a.phases,f},arrayKey:r=>r===`/${t}`?"name":void 0})}function Te(e){const n=e.normalize("NFKD").replace(/[\u0300-\u036f]/g,"").split(/[^A-Za-z0-9]+/).filter(Boolean).map((s,i)=>i===0?s[0].toLowerCase()+s.slice(1):s[0].toUpperCase()+s.slice(1)).join("");return/^[A-Za-z_]/.test(n)?n:`script${n}`}function $t(e){const t=Te(e.name),n=e.language??Ke(e.kind)[0],s={name:t,kind:e.kind,...e.name!==t?{displayName:e.name}:{},...n?{language:n}:{},...e.category?{category:e.category}:{},...e.trigger?{trigger:e.trigger}:{},parameters:[]},i=t[0].toUpperCase()+t.slice(1);switch(e.kind){case"noCode":return{...s,steps:[]};case"sql":return{...s,source:`-- ${e.name}
14
14
  SELECT 1;
15
15
  `};case"backend":return{...s,returnType:"object",source:n==="csharp"?`public static object ${i}(IDictionary<string, object> args)
16
16
  {
@@ -23,4 +23,4 @@ SELECT 1;
23
23
  }
24
24
  `:`export function ${t}() {
25
25
  }
26
- `}}}const T=e=>JSON.parse(JSON.stringify(e));function jt(e){const t=e.revisions!==!1;let n=0;const s=e.workspaces.map(o=>({meta:{id:o.id,label:o.label,description:o.description,icon:o.icon,readOnly:o.readOnly},packages:new Map((o.packages??[]).map(c=>[c.id,{...c,workspaceId:o.id}])),modules:new Map(o.modules.map(c=>[c.id,{...c,files:new Map(Object.entries(c.files).map(([d,u])=>[d,{text:u,version:++n}])),revisions:[]}]))}));let i=(e.templates??[]).map(o=>T(o));const r=o=>{const c=s.find(d=>d.meta.id===o);if(!c)throw new Error(`Unknown workspace "${o}"`);return c},a=o=>{const c=r(o.workspaceId).modules.get(o.id);if(!c)throw new Error(`Unknown module "${o.id}"`);return c},l=(o,c)=>({workspaceId:o,id:c.id,packageId:c.packageId,label:c.label??c.id,description:c.description,icon:c.icon,version:c.version,readOnly:c.readOnly||r(o).meta.readOnly,files:[...c.files.keys()].sort()}),f=(o,c)=>({path:o,text:c.text,version:String(c.version)});return{async listWorkspaces(){return s.map(o=>({...o.meta}))},async listModules(o){return[...r(o).modules.values()].map(d=>l(o,d))},async listPackages(o){const c=r(o),d=[...c.packages.values()],u=[...new Set([...c.modules.values()].map(y=>y.packageId).filter(Boolean))].filter(y=>!c.packages.has(y)).map(y=>({id:y,workspaceId:o,label:y,derived:!0}));return[...d,...u]},async readModule(o){return[...a(o).files.entries()].map(([d,u])=>f(d,u))},async writeModule(o,c){const d=a(o);if(d.readOnly||r(o.workspaceId).meta.readOnly)throw new Error(`Module "${o.id}" is read-only`);const u=c.filter(p=>p.baseVersion!==void 0).filter(p=>{const m=d.files.get(p.path);return m?String(m.version)!==p.baseVersion:!1}).map(p=>{var m;return{path:p.path,currentVersion:String((m=d.files.get(p.path))==null?void 0:m.version)}});if(u.length>0)return{ok:!1,conflicts:u};let y;if(t){const p={};for(const[m,k]of d.files)p[m]=k.text;y=`r${++n}`,d.revisions.unshift({id:y,timestamp:Date.now(),label:y,summary:c.map(m=>`${m.type} ${m.path}`).join(", "),files:p})}const g={};for(const p of c)if(p.type==="delete")d.files.delete(p.path);else{const m=++n;d.files.set(p.path,{text:p.text,version:m}),g[p.path]=String(m)}return{ok:!0,versions:g,revision:y}},async createModule(o){const c=r(o.workspaceId);if(c.meta.readOnly)throw new Error(`Workspace "${o.workspaceId}" is read-only`);if(c.modules.has(o.id))throw new Error(`Module "${o.id}" already exists`);const d={id:o.id,packageId:o.packageId,files:new Map(o.files.map(u=>[u.path,{text:u.text,version:++n}])),revisions:[]};return c.modules.set(o.id,d),l(o.workspaceId,d)},async deleteModule(o){const c=r(o.workspaceId);if(c.meta.readOnly)throw new Error(`Workspace "${o.workspaceId}" is read-only`);c.modules.delete(o.id)},async savePackage(o){return r(o.workspaceId).packages.set(o.id,{...o,derived:!1}),{...o,derived:!1}},async deletePackage(o){r(o.workspaceId).packages.delete(o.id)},async listTemplates(){return i.map(o=>T(o))},async saveTemplate(o,c){const d=(c==null?void 0:c.previousId)??o.id,u=T(o),y=i.findIndex(g=>g.id===d);return i=y>=0?i.map((g,p)=>p===y?u:g):[...i,u],T(u)},async deleteTemplate(o){i=i.filter(c=>c.id!==o)},async listRevisions(o,c){return a(o).revisions.filter(d=>!c||c in d.files).map(({files:d,...u})=>({...u,...c?{path:c}:{}}))},async readRevision(o,c,d){const u=a(o).revisions.find(y=>y.id===c);if(!u)throw new Error(`Unknown revision "${c}"`);return d?u.files[d]??"":JSON.stringify(u.files,null,2)},async rollback(o,c,d){const u=a(o),y=u.revisions.find(p=>p.id===c);if(!y)throw new Error(`Unknown revision "${c}"`);const g=d?{[d]:y.files[d]}:y.files;if(!d)for(const p of[...u.files.keys()])p in g||u.files.delete(p);for(const[p,m]of Object.entries(g))m!==void 0&&u.files.set(p,{text:m,version:++n})},snapshot(){return{workspaces:s.map(o=>({...o.meta,packages:[...o.packages.values()].map(({workspaceId:c,...d})=>d),modules:[...o.modules.values()].map(c=>({id:c.id,packageId:c.packageId,label:c.label,description:c.description,icon:c.icon,version:c.version,readOnly:c.readOnly,files:Object.fromEntries([...c.files.entries()].map(([d,u])=>[d,u.text]))}))})),templates:i.map(o=>T(o)),revisions:t}}}}function Kt(e){return e}function U(e,t){if(!t||e===void 0||e===null)return!0;if(t.enum&&!t.enum.includes(e))return!1;switch(t.type){case"string":return typeof e=="string";case"number":return typeof e=="number";case"integer":return Number.isInteger(e);case"boolean":return typeof e=="boolean";case"array":return Array.isArray(e)&&(!t.items||e.every(n=>U(n,t.items)));case"object":{if(typeof e!="object"||Array.isArray(e))return!1;const n=t.properties;return!n||Object.entries(e).every(([s,i])=>s in n&&U(i,n[s]))}default:return!0}}function Ot(e,t){var a;const n=(e.fields??[]).map(l=>l.name),s=(a=e.schema)==null?void 0:a.properties;if(!e.schema||!s)return{section:e,keys:n};const i=Object.entries(s).filter(([l,f])=>!(l in t)||U(t[l],f)),r=i.map(([l])=>l);return{section:{...e,schema:{...e.schema,properties:Object.fromEntries(i),...e.schema.required?{required:e.schema.required.filter(l=>r.includes(l))}:{}}},keys:[...r,...n]}}function At(e){var n;const t=new Set;for(const s of e){for(const i of Object.keys(((n=s.schema)==null?void 0:n.properties)??{}))t.add(i);for(const i of s.fields??[])t.add(i.name)}return t}function Et(e){return e.map(t=>{const n=t;return{name:String(n.tableName||n.name||"Entity"),columns:(Array.isArray(n.fields)?n.fields:[]).map(s=>({name:String(s.name??""),dataType:String(s.dataType??s.type??"string"),isPrimaryKey:!!s.isPrimaryKey,isForeignKey:!!(s.isForeignKey??s.foreignKey)}))}})}function It(e){const t=e.manifest??{},n=String(t.displayName||t.packageName||"Module"),s=(e.views??[]).map(r=>({id:`view:${r.id}`,label:r.name,type:"view"})),i=(e.entities??[]).map(r=>{const a=String(r.name??"Entity");return{id:`entity:${a}`,label:a,type:"entity"}});return{roles:[{id:"admin",label:"Admin"},{id:"user",label:"User"}],actions:[{id:"view",label:"View"},{id:"create",label:"Create"},{id:"edit",label:"Edit"},{id:"delete",label:"Delete"}],resources:[{id:"module",label:n,type:"module",children:[...s.length?[{id:"views",label:"Views",type:"group",children:s}]:[],...i.length?[{id:"entities",label:"Entities",type:"group",children:i}]:[]]}],grants:{}}}const V=ne({id:"manifest",label:"Manifest",labelKey:"devStudio.kind.manifest",icon:"file",editor:"manifest",match:w(".manifest.json")}),Fe=C({id:"entities",label:"Entities",labelKey:"devStudio.kind.entities",icon:"database",editor:"entities",match:w(".entities.json"),property:"entities",itemKey:"name"}),xe=$e();function Le(e,t){const n=e,s=typeof e=="object"&&e!==null&&typeof n.id=="string";return{key:s?n.id:`#${t}`,label:s&&n.name||(s?n.id:`#${t+1}`),...s?{definition:n}:{rawReason:"no id"},source:e}}const Ce=te({id:"views",label:"Views",labelKey:"devStudio.kind.views",icon:"grid",editor:"views",match:w(".views.json"),property:"views",itemKey:"id",toItem:(e,t)=>Le(e,t),fromItem:e=>e.definition??e.source}),Me=te({id:"workflows",label:"Workflows",labelKey:"devStudio.kind.workflows",icon:"git-branch",editor:"workflows",match:w(".workflows.json"),property:"workflows",itemKey:"id",toItem:(e,t)=>Le(e,t),fromItem:e=>e.definition??e.source}),Pe=C({id:"dataSources",label:"Data sources",labelKey:"devStudio.kind.dataSources",icon:"database",editor:"dataSources",match:w(".datasources.json"),property:"dataSources",itemKey:"key"}),Je=ne({id:"rbac",label:"Access",labelKey:"devStudio.kind.rbac",icon:"shield",editor:"rbac",match:w(".rbac.json")}),De=C({id:"hooks",label:"Lifecycle hooks",labelKey:"devStudio.kind.hooks",icon:"zap",editor:"hooks",match:w(".hooks.json"),property:"bindings",itemKey:"id"}),_e=Ne({match:w(".scripts.json")}),Re=[V,Fe,xe,Ce,Me,Pe,Je,De,_e];function G(e){return e.normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/ł/g,"l").replace(/Ł/g,"L").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"module"}const re=e=>{const t=e.find(n=>V.match(n.path));return t?ve(t.text,void 0):void 0};function Ue(e){const t=e.find(n=>V.match(n.path));return t?O(t.path).replace(/\.manifest\.json$/i,""):"module"}const oe=e=>Array.isArray(e.fields)?e.fields:[],Nt={id:"native",kinds:Re,locales:["en","pl","de","fr","es","uk"],requiredLocales:["en"],moduleId:e=>{const t=re(e),n=(t==null?void 0:t.id)??(t==null?void 0:t.packageName);return typeof n=="string"?n:void 0},validateModule:({files:e})=>{const t=re(e);return t?["id","name","version"].filter(n=>typeof t[n]!="string"||!t[n]).map(n=>({severity:"error",code:"manifest.required",message:`The manifest needs "${n}".`,messageKey:"devStudio.issue.manifestRequired",params:{field:n},pointer:`/${n}`})):[{severity:"error",code:"manifest.missing",message:"The module has no manifest.",messageKey:"devStudio.issue.manifestMissing"}]},newFile:(e,{files:t})=>{const n=Ue(t),i={entities:["entities.json",{entities:[]}],views:["views.json",{views:[]}],workflows:["workflows.json",{workflows:[]}],dataSources:["datasources.json",{dataSources:[]}],rbac:["rbac.json",{roles:[],actions:[],resources:[],grants:{}}],hooks:["hooks.json",{bindings:[]}],scripts:["scripts.json",{scripts:[]}]}[e];return i?{path:`${n}.${i[0]}`,text:S(i[1])}:void 0},generateModule:async(e,{existingIds:t})=>{let n=G(e.name);for(let i=2;t.has(n);i++)n=`${G(e.name)}-${i}`;const s=[{path:`${n}.manifest.json`,text:S({id:n,name:e.name,version:"1.0.0",...e.description?{description:e.description}:{},...e.icon?{icon:e.icon}:{},...e.packageId?{category:e.packageId}:{}})},{path:`${n}.entities.json`,text:S({entities:e.entities})}];for(const i of e.locales){const r={"module.displayName":e.name};for(const a of e.entities){const l=String(a.name??"");r[`entity.${l}.displayName`]=l;for(const f of oe(a))r[`field.${l}.${String(f.name)}.label`]=String(f.name)}s.push({path:`${n}.${i}.i18n.json`,text:S({locale:i,translations:r})})}if(e.views){const i=e.entities.map(r=>{const a=String(r.name??"Item");return{id:`${a}List`,name:`${a} list`,kind:"grid",version:2,columns:12,dataSources:[{key:"rows",type:"entity",entity:a,autoLoad:!0}],rows:[{id:"r1",cells:[{id:"grid",controlType:"dataGrid",colSpan:12,props:{columns:oe(r).map(l=>({field:String(l.name),header:String(l.name)}))},bindings:{data:{source:"rows",field:""}}}]}]}});s.push({path:`${n}.views.json`,text:S({views:i})})}if(e.permissions){const i={roles:[{id:"viewer",label:"Viewer"},{id:"editor",label:"Editor"},{id:"admin",label:"Admin"}],actions:[{id:"view",label:"View"},{id:"edit",label:"Edit"},{id:"delete",label:"Delete"}],resources:e.entities.map(r=>({id:`entity:${String(r.name)}`,label:String(r.name),type:"entity"})),grants:{}};s.push({path:`${n}.rbac.json`,text:S(i)})}return{id:n,packageId:e.packageId,files:s}}};exports.NICE_STUDIO_SCRIPT_KINDS=je;exports.NICE_STUDIO_SCRIPT_PHASES=St;exports.addStudioFolder=Qe;exports.addStudioSection=Ye;exports.arrayFileKind=C;exports.buildDocuments=ht;exports.createMemoryStudioProvider=jt;exports.defineManifestSection=Kt;exports.deriveDefaultRbac=It;exports.detectJsonTextFormat=q;exports.emptyStudioLayout=M;exports.encodeDocument=gt;exports.endsWithAny=w;exports.entitiesToSchemas=Et;exports.fileName=O;exports.fitManifestSection=Ot;exports.fromStudioScriptItem=Ie;exports.i18nFileKind=$e;exports.inferStudioScriptKind=R;exports.isEmptyStudioLayout=Xe;exports.isStudioLayoutPath=ae;exports.itemsFileKind=te;exports.jsonFallbackKind=D;exports.jsonFileKind=L;exports.jsonValueFitsSchema=U;exports.jsonValuesEqual=F;exports.keepTextFormat=fe;exports.manifestSectionKeys=At;exports.modulePrefix=Ue;exports.nativeDataSourcesKind=Pe;exports.nativeEntitiesKind=Fe;exports.nativeFileKinds=Re;exports.nativeHooksKind=De;exports.nativeI18nKind=xe;exports.nativeManifestKind=V;exports.nativeRbacKind=Je;exports.nativeScriptsKind=_e;exports.nativeStudioPreset=Nt;exports.nativeViewsKind=Ce;exports.nativeWorkflowsKind=Me;exports.newStudioScript=$t;exports.objectFileKind=ne;exports.parseJsonText=A;exports.parseStudioLayout=He;exports.patchJsonText=Y;exports.patchJsonTextDetailed=ue;exports.placeStudioEntry=nt;exports.readTranslations=we;exports.removeStudioLayoutNode=tt;exports.renameStudioEntryRef=st;exports.renameStudioLayoutNode=et;exports.resolveFileKind=Se;exports.safeJson=ve;exports.scriptsFileKind=Ne;exports.serializeStudioLayout=Ze;exports.slugifyModuleId=G;exports.stringifyJsonText=S;exports.studioEntryRef=ze;exports.studioLayoutPath=Be;exports.studioScriptIdentifier=Te;exports.studioScriptLanguages=Ke;exports.textFallbackKind=_;exports.toStudioScriptItem=Ee;exports.writeTranslations=Z;
26
+ `}}}const T=e=>JSON.parse(JSON.stringify(e));function jt(e){const t=e.revisions!==!1;let n=0;const s=e.workspaces.map(o=>({meta:{id:o.id,label:o.label,description:o.description,icon:o.icon,readOnly:o.readOnly},packages:new Map((o.packages??[]).map(c=>[c.id,{...c,workspaceId:o.id}])),modules:new Map(o.modules.map(c=>[c.id,{...c,files:new Map(Object.entries(c.files).map(([d,u])=>[d,{text:u,version:++n}])),revisions:[]}]))}));let i=(e.templates??[]).map(o=>T(o));const r=o=>{const c=s.find(d=>d.meta.id===o);if(!c)throw new Error(`Unknown workspace "${o}"`);return c},a=o=>{const c=r(o.workspaceId).modules.get(o.id);if(!c)throw new Error(`Unknown module "${o.id}"`);return c},l=(o,c)=>({workspaceId:o,id:c.id,packageId:c.packageId,label:c.label??c.id,description:c.description,icon:c.icon,version:c.version,readOnly:c.readOnly||r(o).meta.readOnly,files:[...c.files.keys()].sort()}),f=(o,c)=>({path:o,text:c.text,version:String(c.version)});return{async listWorkspaces(){return s.map(o=>({...o.meta}))},async listModules(o){return[...r(o).modules.values()].map(d=>l(o,d))},async listPackages(o){const c=r(o),d=[...c.packages.values()],u=[...new Set([...c.modules.values()].map(y=>y.packageId).filter(Boolean))].filter(y=>!c.packages.has(y)).map(y=>({id:y,workspaceId:o,label:y,derived:!0}));return[...d,...u]},async readModule(o){return[...a(o).files.entries()].map(([d,u])=>f(d,u))},async writeModule(o,c){const d=a(o);if(d.readOnly||r(o.workspaceId).meta.readOnly)throw new Error(`Module "${o.id}" is read-only`);const u=c.filter(p=>p.baseVersion!==void 0).filter(p=>{const m=d.files.get(p.path);return m?String(m.version)!==p.baseVersion:!1}).map(p=>{var m;return{path:p.path,currentVersion:String((m=d.files.get(p.path))==null?void 0:m.version)}});if(u.length>0)return{ok:!1,conflicts:u};let y;if(t){const p={};for(const[m,S]of d.files)p[m]=S.text;y=`r${++n}`,d.revisions.unshift({id:y,timestamp:Date.now(),label:y,summary:c.map(m=>`${m.type} ${m.path}`).join(", "),files:p})}const g={};for(const p of c)if(p.type==="delete")d.files.delete(p.path);else{const m=++n;d.files.set(p.path,{text:p.text,version:m}),g[p.path]=String(m)}return{ok:!0,versions:g,revision:y}},async createModule(o){const c=r(o.workspaceId);if(c.meta.readOnly)throw new Error(`Workspace "${o.workspaceId}" is read-only`);if(c.modules.has(o.id))throw new Error(`Module "${o.id}" already exists`);const d={id:o.id,packageId:o.packageId,files:new Map(o.files.map(u=>[u.path,{text:u.text,version:++n}])),revisions:[]};return c.modules.set(o.id,d),l(o.workspaceId,d)},async deleteModule(o){const c=r(o.workspaceId);if(c.meta.readOnly)throw new Error(`Workspace "${o.workspaceId}" is read-only`);c.modules.delete(o.id)},async savePackage(o){return r(o.workspaceId).packages.set(o.id,{...o,derived:!1}),{...o,derived:!1}},async deletePackage(o){r(o.workspaceId).packages.delete(o.id)},async listTemplates(){return i.map(o=>T(o))},async saveTemplate(o,c){const d=(c==null?void 0:c.previousId)??o.id,u=T(o),y=i.findIndex(g=>g.id===d);return i=y>=0?i.map((g,p)=>p===y?u:g):[...i,u],T(u)},async deleteTemplate(o){i=i.filter(c=>c.id!==o)},async listRevisions(o,c){return a(o).revisions.filter(d=>!c||c in d.files).map(({files:d,...u})=>({...u,...c?{path:c}:{}}))},async readRevision(o,c,d){const u=a(o).revisions.find(y=>y.id===c);if(!u)throw new Error(`Unknown revision "${c}"`);return d?u.files[d]??"":JSON.stringify(u.files,null,2)},async rollback(o,c,d){const u=a(o),y=u.revisions.find(p=>p.id===c);if(!y)throw new Error(`Unknown revision "${c}"`);const g=d?{[d]:y.files[d]}:y.files;if(!d)for(const p of[...u.files.keys()])p in g||u.files.delete(p);for(const[p,m]of Object.entries(g))m!==void 0&&u.files.set(p,{text:m,version:++n})},snapshot(){return{workspaces:s.map(o=>({...o.meta,packages:[...o.packages.values()].map(({workspaceId:c,...d})=>d),modules:[...o.modules.values()].map(c=>({id:c.id,packageId:c.packageId,label:c.label,description:c.description,icon:c.icon,version:c.version,readOnly:c.readOnly,files:Object.fromEntries([...c.files.entries()].map(([d,u])=>[d,u.text]))}))})),templates:i.map(o=>T(o)),revisions:t}}}}function Kt(e){return e}function U(e,t){if(!t||e===void 0||e===null)return!0;if(t.enum&&!t.enum.includes(e))return!1;switch(t.type){case"string":return typeof e=="string";case"number":return typeof e=="number";case"integer":return Number.isInteger(e);case"boolean":return typeof e=="boolean";case"array":return Array.isArray(e)&&(!t.items||e.every(n=>U(n,t.items)));case"object":{if(typeof e!="object"||Array.isArray(e))return!1;const n=t.properties;return!n||Object.entries(e).every(([s,i])=>s in n&&U(i,n[s]))}default:return!0}}function Ot(e,t){var a;const n=(e.fields??[]).map(l=>l.name),s=(a=e.schema)==null?void 0:a.properties;if(!e.schema||!s)return{section:e,keys:n};const i=Object.entries(s).filter(([l,f])=>!(l in t)||U(t[l],f)),r=i.map(([l])=>l);return{section:{...e,schema:{...e.schema,properties:Object.fromEntries(i),...e.schema.required?{required:e.schema.required.filter(l=>r.includes(l))}:{}}},keys:[...r,...n]}}function Et(e){var n;const t=new Set;for(const s of e){for(const i of Object.keys(((n=s.schema)==null?void 0:n.properties)??{}))t.add(i);for(const i of s.fields??[])t.add(i.name)}return t}function At(e){const t=n=>{const s=e.find(i=>i.name===n);return String((s==null?void 0:s.tableName)||(s==null?void 0:s.name)||n)};return e.map(n=>{const s=n,i=String(s.tableName||s.name||"Entity");return{name:i,...s.name&&s.name!==i?{entity:String(s.name)}:{},...typeof s.description=="string"&&s.description?{description:s.description}:{},columns:(Array.isArray(s.fields)?s.fields:[]).map(r=>{const a=typeof r.referencedEntity=="string"?r.referencedEntity:typeof r.references=="string"?r.references:void 0;return{name:String(r.name??""),dataType:String(r.dataType??r.type??"string"),isPrimaryKey:!!r.isPrimaryKey,isForeignKey:!!(r.isForeignKey??r.foreignKey??a),...a?{references:{table:t(a),column:typeof r.referencedField=="string"?r.referencedField:"Id"}}:{}}})}})}function It(e){const t=e.manifest??{},n=String(t.displayName||t.packageName||"Module"),s=(e.views??[]).map(r=>({id:`view:${r.id}`,label:r.name,type:"view"})),i=(e.entities??[]).map(r=>{const a=String(r.name??"Entity");return{id:`entity:${a}`,label:a,type:"entity"}});return{roles:[{id:"admin",label:"Admin"},{id:"user",label:"User"}],actions:[{id:"view",label:"View"},{id:"create",label:"Create"},{id:"edit",label:"Edit"},{id:"delete",label:"Delete"}],resources:[{id:"module",label:n,type:"module",children:[...s.length?[{id:"views",label:"Views",type:"group",children:s}]:[],...i.length?[{id:"entities",label:"Entities",type:"group",children:i}]:[]]}],grants:{}}}const V=ne({id:"manifest",label:"Manifest",labelKey:"devStudio.kind.manifest",icon:"file",editor:"manifest",match:w(".manifest.json")}),Fe=C({id:"entities",label:"Entities",labelKey:"devStudio.kind.entities",icon:"database",editor:"entities",match:w(".entities.json"),property:"entities",itemKey:"name"}),xe=$e();function Le(e,t){const n=e,s=typeof e=="object"&&e!==null&&typeof n.id=="string";return{key:s?n.id:`#${t}`,label:s&&n.name||(s?n.id:`#${t+1}`),...s?{definition:n}:{rawReason:"no id"},source:e}}const Ce=te({id:"views",label:"Views",labelKey:"devStudio.kind.views",icon:"grid",editor:"views",match:w(".views.json"),property:"views",itemKey:"id",toItem:(e,t)=>Le(e,t),fromItem:e=>e.definition??e.source}),Me=te({id:"workflows",label:"Workflows",labelKey:"devStudio.kind.workflows",icon:"git-branch",editor:"workflows",match:w(".workflows.json"),property:"workflows",itemKey:"id",toItem:(e,t)=>Le(e,t),fromItem:e=>e.definition??e.source}),Pe=C({id:"dataSources",label:"Data sources",labelKey:"devStudio.kind.dataSources",icon:"database",editor:"dataSources",match:w(".datasources.json"),property:"dataSources",itemKey:"key"}),Je=ne({id:"rbac",label:"Access",labelKey:"devStudio.kind.rbac",icon:"shield",editor:"rbac",match:w(".rbac.json")}),De=C({id:"hooks",label:"Lifecycle hooks",labelKey:"devStudio.kind.hooks",icon:"zap",editor:"hooks",match:w(".hooks.json"),property:"bindings",itemKey:"id"}),_e=Ne({match:w(".scripts.json")}),Re=[V,Fe,xe,Ce,Me,Pe,Je,De,_e];function G(e){return e.normalize("NFKD").replace(/[̀-ͯ]/g,"").replace(/ł/g,"l").replace(/Ł/g,"L").toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")||"module"}const re=e=>{const t=e.find(n=>V.match(n.path));return t?ve(t.text,void 0):void 0};function Ue(e){const t=e.find(n=>V.match(n.path));return t?O(t.path).replace(/\.manifest\.json$/i,""):"module"}const oe=e=>Array.isArray(e.fields)?e.fields:[],Nt={id:"native",kinds:Re,locales:["en","pl","de","fr","es","uk"],requiredLocales:["en"],moduleId:e=>{const t=re(e),n=(t==null?void 0:t.id)??(t==null?void 0:t.packageName);return typeof n=="string"?n:void 0},validateModule:({files:e})=>{const t=re(e);return t?["id","name","version"].filter(n=>typeof t[n]!="string"||!t[n]).map(n=>({severity:"error",code:"manifest.required",message:`The manifest needs "${n}".`,messageKey:"devStudio.issue.manifestRequired",params:{field:n},pointer:`/${n}`})):[{severity:"error",code:"manifest.missing",message:"The module has no manifest.",messageKey:"devStudio.issue.manifestMissing"}]},newFile:(e,{files:t})=>{const n=Ue(t),i={entities:["entities.json",{entities:[]}],views:["views.json",{views:[]}],workflows:["workflows.json",{workflows:[]}],dataSources:["datasources.json",{dataSources:[]}],rbac:["rbac.json",{roles:[],actions:[],resources:[],grants:{}}],hooks:["hooks.json",{bindings:[]}],scripts:["scripts.json",{scripts:[]}]}[e];return i?{path:`${n}.${i[0]}`,text:k(i[1])}:void 0},generateModule:async(e,{existingIds:t})=>{let n=G(e.name);for(let i=2;t.has(n);i++)n=`${G(e.name)}-${i}`;const s=[{path:`${n}.manifest.json`,text:k({id:n,name:e.name,version:"1.0.0",...e.description?{description:e.description}:{},...e.icon?{icon:e.icon}:{},...e.packageId?{category:e.packageId}:{}})},{path:`${n}.entities.json`,text:k({entities:e.entities})}];for(const i of e.locales){const r={"module.displayName":e.name};for(const a of e.entities){const l=String(a.name??"");r[`entity.${l}.displayName`]=l;for(const f of oe(a))r[`field.${l}.${String(f.name)}.label`]=String(f.name)}s.push({path:`${n}.${i}.i18n.json`,text:k({locale:i,translations:r})})}if(e.views){const i=e.entities.map(r=>{const a=String(r.name??"Item");return{id:`${a}List`,name:`${a} list`,kind:"grid",version:2,columns:12,dataSources:[{key:"rows",type:"entity",entity:a,autoLoad:!0}],rows:[{id:"r1",cells:[{id:"grid",controlType:"dataGrid",colSpan:12,props:{columns:oe(r).map(l=>({field:String(l.name),header:String(l.name)}))},bindings:{data:{source:"rows",field:""}}}]}]}});s.push({path:`${n}.views.json`,text:k({views:i})})}if(e.permissions){const i={roles:[{id:"viewer",label:"Viewer"},{id:"editor",label:"Editor"},{id:"admin",label:"Admin"}],actions:[{id:"view",label:"View"},{id:"edit",label:"Edit"},{id:"delete",label:"Delete"}],resources:e.entities.map(r=>({id:`entity:${String(r.name)}`,label:String(r.name),type:"entity"})),grants:{}};s.push({path:`${n}.rbac.json`,text:k(i)})}return{id:n,packageId:e.packageId,files:s}}};exports.NICE_STUDIO_SCRIPT_KINDS=je;exports.NICE_STUDIO_SCRIPT_PHASES=kt;exports.addStudioFolder=Qe;exports.addStudioSection=Ye;exports.arrayFileKind=C;exports.buildDocuments=ht;exports.createMemoryStudioProvider=jt;exports.defineManifestSection=Kt;exports.deriveDefaultRbac=It;exports.detectJsonTextFormat=q;exports.emptyStudioLayout=M;exports.encodeDocument=gt;exports.endsWithAny=w;exports.entitiesToSchemas=At;exports.fileName=O;exports.fitManifestSection=Ot;exports.fromStudioScriptItem=Ie;exports.i18nFileKind=$e;exports.inferStudioScriptKind=R;exports.isEmptyStudioLayout=Xe;exports.isStudioLayoutPath=ae;exports.itemsFileKind=te;exports.jsonFallbackKind=D;exports.jsonFileKind=L;exports.jsonValueFitsSchema=U;exports.jsonValuesEqual=F;exports.keepTextFormat=fe;exports.manifestSectionKeys=Et;exports.modulePrefix=Ue;exports.nativeDataSourcesKind=Pe;exports.nativeEntitiesKind=Fe;exports.nativeFileKinds=Re;exports.nativeHooksKind=De;exports.nativeI18nKind=xe;exports.nativeManifestKind=V;exports.nativeRbacKind=Je;exports.nativeScriptsKind=_e;exports.nativeStudioPreset=Nt;exports.nativeViewsKind=Ce;exports.nativeWorkflowsKind=Me;exports.newStudioScript=$t;exports.objectFileKind=ne;exports.parseJsonText=E;exports.parseStudioLayout=He;exports.patchJsonText=Y;exports.patchJsonTextDetailed=ue;exports.placeStudioEntry=nt;exports.readTranslations=we;exports.removeStudioLayoutNode=tt;exports.renameStudioEntryRef=st;exports.renameStudioLayoutNode=et;exports.resolveFileKind=ke;exports.safeJson=ve;exports.scriptsFileKind=Ne;exports.serializeStudioLayout=Ze;exports.slugifyModuleId=G;exports.stringifyJsonText=k;exports.studioEntryRef=ze;exports.studioLayoutPath=Be;exports.studioScriptIdentifier=Te;exports.studioScriptLanguages=Ke;exports.textFallbackKind=_;exports.toStudioScriptItem=Ae;exports.writeTranslations=Z;
package/dist/studio.mjs CHANGED
@@ -179,18 +179,18 @@ function Oe(e, t) {
179
179
  `) : e;
180
180
  return t.charCodeAt(0) === 65279 && n.charCodeAt(0) !== 65279 && (n = ie + n), n;
181
181
  }
182
- function C(e, t) {
182
+ function F(e, t) {
183
183
  if (e === t)
184
184
  return !0;
185
185
  if (typeof e != typeof t || e === null || t === null || typeof e != "object" || Array.isArray(e) !== Array.isArray(t))
186
186
  return !1;
187
187
  if (Array.isArray(e)) {
188
188
  const i = t;
189
- return e.length === i.length && e.every((a, l) => C(a, i[l]));
189
+ return e.length === i.length && e.every((a, l) => F(a, i[l]));
190
190
  }
191
191
  const n = e, s = t, r = Object.keys(n);
192
192
  return r.length !== Object.keys(s).length ? !1 : r.every(
193
- (i) => Object.prototype.hasOwnProperty.call(s, i) && C(n[i], s[i])
193
+ (i) => Object.prototype.hasOwnProperty.call(s, i) && F(n[i], s[i])
194
194
  );
195
195
  }
196
196
  function ae(e, t, n) {
@@ -222,7 +222,7 @@ function Ae(e, t, n) {
222
222
  const f = Ke(e, a);
223
223
  try {
224
224
  const o = JSON.parse(s.bom ? f.slice(1) : f);
225
- if (!C(o, t))
225
+ if (!F(o, t))
226
226
  return r("patch did not read back");
227
227
  } catch {
228
228
  return r("patch was not valid JSON");
@@ -324,14 +324,14 @@ function R(e) {
324
324
  return e.items.some(R);
325
325
  return !1;
326
326
  }
327
- function F(e) {
327
+ function C(e) {
328
328
  if (e.kind === "scalar")
329
329
  return e.value;
330
330
  if (e.kind === "array")
331
- return e.items.map(F);
331
+ return e.items.map(C);
332
332
  const t = {};
333
333
  for (const n of e.members)
334
- t[n.key] = F(n.value);
334
+ t[n.key] = C(n.value);
335
335
  return t;
336
336
  }
337
337
  function A(e, t, n) {
@@ -392,7 +392,7 @@ function G(e, t, n, s, r) {
392
392
  T(e, t, n, r);
393
393
  return;
394
394
  }
395
- C(F(t), n) || (t.kind === "object" && de(n) ? Ne(e, t, n, s, r) : t.kind === "array" && Array.isArray(n) ? Te(e, t, n, s, r) : T(e, t, n, r));
395
+ F(C(t), n) || (t.kind === "object" && de(n) ? Ne(e, t, n, s, r) : t.kind === "array" && Array.isArray(n) ? Te(e, t, n, s, r) : T(e, t, n, r));
396
396
  }
397
397
  function fe(e, t, n) {
398
398
  return n !== void 0 ? L(e.text, n) : L(e.text, t.start) + e.format.indent;
@@ -443,10 +443,10 @@ function xe(e, t, n, s) {
443
443
  }
444
444
  function Te(e, t, n, s, r) {
445
445
  var g;
446
- const i = Z(e, t, r), a = t.items.map(F), l = xe(e, s, a, n), f = (u) => u[l], o = l !== void 0 ? a.map((u) => {
446
+ const i = Z(e, t, r), a = t.items.map(C), l = xe(e, s, a, n), f = (u) => u[l], o = l !== void 0 ? a.map((u) => {
447
447
  const m = f(u);
448
448
  return n.findIndex((k) => f(k) === m);
449
- }) : Fe(a, n);
449
+ }) : Ce(a, n);
450
450
  {
451
451
  const u = new Set(o.filter((m) => m >= 0));
452
452
  for (let m = 0; m < o.length; m++) {
@@ -514,10 +514,10 @@ function Te(e, t, n, s, r) {
514
514
  i ? me(e, t, k, m) : ue(e, t, k, m);
515
515
  }
516
516
  }
517
- const Ce = 4e6;
518
- function Fe(e, t) {
517
+ const Fe = 4e6;
518
+ function Ce(e, t) {
519
519
  const n = e.length, s = t.length;
520
- if (n * s > Ce)
520
+ if (n * s > Fe)
521
521
  return e.map((c, d) => d < s ? d : -1);
522
522
  const r = e.map((c) => JSON.stringify(c)), i = t.map((c) => JSON.stringify(c)), a = Array.from({ length: n + 1 }, () => new Uint32Array(s + 1));
523
523
  for (let c = n - 1; c >= 0; c--)
@@ -1246,17 +1246,33 @@ function Kt(e) {
1246
1246
  return t;
1247
1247
  }
1248
1248
  function Nt(e) {
1249
- return e.map((t) => {
1250
- const n = t;
1249
+ const t = (n) => {
1250
+ const s = e.find((r) => r.name === n);
1251
+ return String((s == null ? void 0 : s.tableName) || (s == null ? void 0 : s.name) || n);
1252
+ };
1253
+ return e.map((n) => {
1254
+ const s = n, r = String(s.tableName || s.name || "Entity");
1251
1255
  return {
1252
- name: String(n.tableName || n.name || "Entity"),
1253
- columns: (Array.isArray(n.fields) ? n.fields : []).map((s) => ({
1254
- name: String(s.name ?? ""),
1255
- // seeds spell the type both ways (OmniVerk: `dataType`, older files: `type`)
1256
- dataType: String(s.dataType ?? s.type ?? "string"),
1257
- isPrimaryKey: !!s.isPrimaryKey,
1258
- isForeignKey: !!(s.isForeignKey ?? s.foreignKey)
1259
- }))
1256
+ name: r,
1257
+ // the entity, when the table goes by another name (1.4.7)
1258
+ ...s.name && s.name !== r ? { entity: String(s.name) } : {},
1259
+ ...typeof s.description == "string" && s.description ? { description: s.description } : {},
1260
+ columns: (Array.isArray(s.fields) ? s.fields : []).map((i) => {
1261
+ const a = typeof i.referencedEntity == "string" ? i.referencedEntity : typeof i.references == "string" ? i.references : void 0;
1262
+ return {
1263
+ name: String(i.name ?? ""),
1264
+ // seeds spell the type both ways (OmniVerk: `dataType`, older files: `type`)
1265
+ dataType: String(i.dataType ?? i.type ?? "string"),
1266
+ isPrimaryKey: !!i.isPrimaryKey,
1267
+ isForeignKey: !!(i.isForeignKey ?? i.foreignKey ?? a),
1268
+ ...a ? {
1269
+ references: {
1270
+ table: t(a),
1271
+ column: typeof i.referencedField == "string" ? i.referencedField : "Id"
1272
+ }
1273
+ } : {}
1274
+ };
1275
+ })
1260
1276
  };
1261
1277
  });
1262
1278
  }
@@ -1544,7 +1560,7 @@ export {
1544
1560
  q as jsonFallbackKind,
1545
1561
  M as jsonFileKind,
1546
1562
  B as jsonValueFitsSchema,
1547
- C as jsonValuesEqual,
1563
+ F as jsonValuesEqual,
1548
1564
  Oe as keepTextFormat,
1549
1565
  Kt as manifestSectionKeys,
1550
1566
  ct as modulePrefix,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nice2dev/ui-forms",
3
- "version": "1.4.6",
3
+ "version": "1.4.7",
4
4
  "description": "Nice2Dev UI Forms - schema-driven forms and module editors: NiceDevelopmentStudio, NiceSchemaForm, NiceEntityEditor, NiceI18nEditor",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -45,10 +45,10 @@
45
45
  "react-dom": ">=17.0.0"
46
46
  },
47
47
  "devDependencies": {
48
- "@nice2dev/i18n": "^1.4.6",
49
- "@nice2dev/ui": "^1.4.6",
50
- "@nice2dev/ui-core": "^1.4.6",
51
- "@nice2dev/ui-diagrams": "^1.4.6",
48
+ "@nice2dev/i18n": "^1.4.7",
49
+ "@nice2dev/ui": "^1.4.7",
50
+ "@nice2dev/ui-core": "^1.4.7",
51
+ "@nice2dev/ui-diagrams": "^1.4.7",
52
52
  "@testing-library/react": "^16.3.3",
53
53
  "@types/react": "^19.2.18",
54
54
  "@types/react-dom": "^19.2.7",