@svgrid/enterprise 3.1.62 → 3.1.63
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/cdn/svgrid-enterprise.svelte-external.js +1 -1
- package/dist/designer/assets/{index-uxiZ_kt6.js → index-BxlgvZk3.js} +1 -1
- package/dist/designer/index.html +1 -1
- package/dist/fields/BaseImport.svelte +22 -3
- package/dist/fields/SvBase.svelte +1 -1
- package/dist/fields/base-import.d.ts +16 -0
- package/dist/fields/base-import.js +2 -2
- package/dist/fields/index.d.ts +1 -1
- package/dist/fields/index.js +1 -1
- package/dist/fields/messages/shell.d.ts +8 -0
- package/dist/fields/messages/shell.js +1 -1
- package/dist/fields/messages.svelte.d.ts +8 -0
- package/dist/node/studio.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/wc/sv-base-element.js +92 -92
- package/package.json +1 -1
|
@@ -1527,7 +1527,7 @@ ${O}
|
|
|
1527
1527
|
@keyframes st-home-spin { to { transform: rotate(360deg); } }
|
|
1528
1528
|
</style>
|
|
1529
1529
|
`}}function $S(t){for(let a of t)ss(a);let r=new Map(t.map(a=>[a.name,a])),n=t.map(a=>{let l=xse(a,r);return{schema:kse(a,l),infos:l}});return{entries:n,seed:_se(n)}}function ED(t,r={}){let{entries:n,seed:a}=$S(t),{file:l,needs:i}=Vse(n,a,r.sources,r.supabaseConn,r.serverMemory),o=[Cse(n),l];(i.supabase||r.supabaseAuth)&&!i.supabaseUrl&&(r.supabaseConn?.url||r.supabaseConn?.key)&&(i.supabaseUrl=r.supabaseConn.url,i.supabaseKey=r.supabaseConn.key),(i.supabase||r.supabaseAuth)&&o.push(Hse(i));for(let s of i.sqlRoutes)o.push(Fse(s.schema,s.table,s.dialect,{access:r.accessEnabled,audit:r.auditEnabled,screenIds:r.screensByEntity?.get(s.schema.name)??[],triggers:r.triggers?.[s.schema.name],dbSchema:s.dbSchema,tenantField:r.tenantField&&r.tenantScoped?.(s.schema.name)!==!1?r.tenantField:void 0}));if(i.memoryRoutes.length){o.push(Lse(i.memoryRoutes));for(let s of i.memoryRoutes)o.push(Ose(s.schema,{access:r.accessEnabled,audit:r.auditEnabled,screenIds:r.screensByEntity?.get(s.schema.name)??[],triggers:r.triggers?.[s.schema.name],tenantField:r.tenantField&&r.tenantScoped?.(s.schema.name)!==!1?r.tenantField:void 0}))}return{files:o,prepared:n.map(s=>s.schema)}}function Kse(t){if(t.length===0)throw Error("emitStudioApp: no schemas to emit");let{files:r,prepared:n}=ED(t),a=n.map(i=>{let o=Oa(i);return{href:`/${o.route}`,label:o.label}}),l={path:"src/custom.css",description:"Your custom styles (imported after app.css so it overrides).",userOwned:!0,contents:`/* Your custom styles. Imported after app.css, so these rules override the defaults. */
|
|
1530
|
-
`};return[...r,...n.map(i=>Wse(i)),AD(a),MD(a),l]}var Gse="3.1.
|
|
1530
|
+
`};return[...r,...n.map(i=>Wse(i)),AD(a),MD(a),l]}var Gse="3.1.63",Yse="3.0.39",hl=(t,r)=>t.some(n=>n.config.kind===r),RD=t=>`activeTab_${t.replace(/[^a-zA-Z0-9_$]/g,"_")}`,Zm=(t,r)=>`${t}-${r}`,ID=t=>`accOpen_${t.replace(/[^a-zA-Z0-9_$]/g,"_")}`,Qm=(t,r)=>`${t}-s${r}`,ev=t=>`md_${t.replace(/[^a-zA-Z0-9]/g,"_")}_rows`;function Xse(t){switch(t.type){case"number":{let r=t.decimals;return r==null?"{ type: 'number' }":`{ type: 'number', options: { minimumFractionDigits: ${r}, maximumFractionDigits: ${r} } }`}case"currency":return`{ type: 'currency', currency: ${en(t.currency||"USD")} }`;case"percent":{let r=["type: 'percent'"];return t.valueIsPercentPoints&&r.push("valueIsPercentPoints: true"),t.decimals!=null&&r.push(`options: { minimumFractionDigits: ${t.decimals}, maximumFractionDigits: ${t.decimals} }`),`{ ${r.join(", ")} }`}case"date":case"datetime":return t.pattern?`{ type: '${t.type}', pattern: ${en(t.pattern)} }`:`{ type: '${t.type}' }`}}function Jse(t,r,n,a){if(r.config.kind!=="grid")return`schemaToColumns(${t})`;let l=r.config,i=r.id.replace(/-/g,"_"),o=l.columns.filter(b=>b.show),s=new Set(o.map(b=>b.field)),c=new Set,d=o.map(b=>{let w=a?.get(b.field);return{c:b,col:w&&!s.has(w)?w:b.field}}).filter(b=>!c.has(b.col)&&!!c.add(b.col)),u=l.editing==="inline"?"":", editable: false";if(d.length===0)return u?`schemaToColumns(${t}).map((c) => ({ ...c${u} }))`:`schemaToColumns(${t})`;let p=d.map(b=>`'${b.col}'`),f=d.map(({c:b,col:w})=>{let v=[];return b.header&&v.push(`header: ${JSON.stringify(b.header)}`),b.width!=null&&v.push(`width: ${b.width}`),b.align&&v.push(`align: '${b.align}'`),b.aggregate&&v.push(`aggregate: '${b.aggregate}'`),l.treeData&&b.field===l.treeData.labelField&&n?v.push(`cell: (ctx: CellContext<${n}>) => renderSnippet(treeCell_${i}, { value: ctx.getValue(), row: ctx.row.original })`):b.cellType&&n?v.push(`cell: (ctx: CellContext<${n}>) => renderSnippet(${zD(i,b.field)}, { value: ctx.getValue() })`):b.format&&v.push(`format: ${Xse(b.format)}`),v.length?`'${w}': { ${v.join(", ")} }`:null}).filter(b=>!!b),y=f.length?` const ov: Record<string, Partial<(typeof all)[number]>> = { ${f.join(", ")} };`:"",h=f.length?", ...(ov[String(c.field)] ?? {})":"",_=`[${p.join(", ")}].map((f) => all.find((c) => c.field === f)).filter((c): c is (typeof all)[number] => !!c)`;return`(() => { const all = schemaToColumns(${t});${y} return ${u||h?`${_}.map((c) => ({ ...c${u}${h} }))`:_} })()`}function tc(t,r){let n=[`grid-column: span ${Xie(t)}`,"min-width: 0"];r&&n.push(r);let a=Zie(t.style);return a&&n.push(a),`style="${n.join("; ")}"`}var Zse=t=>t&&t.replace(/[^#a-zA-Z0-9(),.%\s_-]/g,"").slice(0,40)||"var(--sg-accent)";function Nu(t,r){let n=[r,Yie(t)].filter(Boolean).join(" ");return n?` class="${n}"`:""}function n1(t){let r=cS(t.className);return r?` ${r}`:""}function Qse(t){let r=Af(t);if(r==="grid"){let n=goe(t),a=n.maxWidth?` max-width: ${n.maxWidth}px; margin-inline: auto;`:"";return` .st-screen { grid-template-columns: repeat(12, 1fr); gap: ${n.rowGap}px ${n.colGap}px; align-items: ${n.align};${a} }
|
|
1531
1531
|
@media (max-width: ${n.mobileBreakpoint}px) { .st-screen { grid-template-columns: 1fr; gap: 12px; } }
|
|
1532
1532
|
`}if(r==="stack"){let n=foe(t),a=n.maxWidth?` max-width: ${n.maxWidth}px;${n.align==="center"?" margin-inline: auto;":""}`:"",l=n.minHeight?`
|
|
1533
1533
|
.st-stack > * { min-height: ${n.minHeight}px; }`:"",i=n.dividers?`
|
|
@@ -76332,7 +76332,7 @@ ${st}
|
|
|
76332
76332
|
.st-home a { color: var(--sg-accent, #6366f1); font-weight: 600; }
|
|
76333
76333
|
@keyframes st-home-spin { to { transform: rotate(360deg); } }
|
|
76334
76334
|
</style>
|
|
76335
|
-
`}}function s2e(a){for(let p of a)G4(p);let i=new Map(a.map(p=>[p.name,p])),l=a.map(p=>{let f=kpr(p,i);return{schema:Ppr(p,f),infos:f}});return{entries:l,seed:Cpr(l)}}function rur(a,i={}){let{entries:l,seed:p}=s2e(a),{file:f,needs:g}=Ypr(l,p,i.sources,i.supabaseConn,i.serverMemory),_=[Opr(l),f];(g.supabase||i.supabaseAuth)&&!g.supabaseUrl&&(i.supabaseConn?.url||i.supabaseConn?.key)&&(g.supabaseUrl=i.supabaseConn.url,g.supabaseKey=i.supabaseConn.key),(g.supabase||i.supabaseAuth)&&_.push(Zpr(g));for(let S of g.sqlRoutes)_.push(Upr(S.schema,S.table,S.dialect,{access:i.accessEnabled,audit:i.auditEnabled,screenIds:i.screensByEntity?.get(S.schema.name)??[],triggers:i.triggers?.[S.schema.name],dbSchema:S.dbSchema,tenantField:i.tenantField&&i.tenantScoped?.(S.schema.name)!==!1?i.tenantField:void 0}));if(g.memoryRoutes.length){_.push(Hpr(g.memoryRoutes));for(let S of g.memoryRoutes)_.push(Vpr(S.schema,{access:i.accessEnabled,audit:i.auditEnabled,screenIds:i.screensByEntity?.get(S.schema.name)??[],triggers:i.triggers?.[S.schema.name],tenantField:i.tenantField&&i.tenantScoped?.(S.schema.name)!==!1?i.tenantField:void 0}))}return{files:_,prepared:l.map(S=>S.schema)}}var nur="3.1.
|
|
76335
|
+
`}}function s2e(a){for(let p of a)G4(p);let i=new Map(a.map(p=>[p.name,p])),l=a.map(p=>{let f=kpr(p,i);return{schema:Ppr(p,f),infos:f}});return{entries:l,seed:Cpr(l)}}function rur(a,i={}){let{entries:l,seed:p}=s2e(a),{file:f,needs:g}=Ypr(l,p,i.sources,i.supabaseConn,i.serverMemory),_=[Opr(l),f];(g.supabase||i.supabaseAuth)&&!g.supabaseUrl&&(i.supabaseConn?.url||i.supabaseConn?.key)&&(g.supabaseUrl=i.supabaseConn.url,g.supabaseKey=i.supabaseConn.key),(g.supabase||i.supabaseAuth)&&_.push(Zpr(g));for(let S of g.sqlRoutes)_.push(Upr(S.schema,S.table,S.dialect,{access:i.accessEnabled,audit:i.auditEnabled,screenIds:i.screensByEntity?.get(S.schema.name)??[],triggers:i.triggers?.[S.schema.name],dbSchema:S.dbSchema,tenantField:i.tenantField&&i.tenantScoped?.(S.schema.name)!==!1?i.tenantField:void 0}));if(g.memoryRoutes.length){_.push(Hpr(g.memoryRoutes));for(let S of g.memoryRoutes)_.push(Vpr(S.schema,{access:i.accessEnabled,audit:i.auditEnabled,screenIds:i.screensByEntity?.get(S.schema.name)??[],triggers:i.triggers?.[S.schema.name],tenantField:i.tenantField&&i.tenantScoped?.(S.schema.name)!==!1?i.tenantField:void 0}))}return{files:_,prepared:l.map(S=>S.schema)}}var nur="3.1.63",our="3.0.39",sb=(a,i)=>a.some(l=>l.config.kind===i),qit=a=>`activeTab_${a.replace(/[^a-zA-Z0-9_$]/g,"_")}`,XZ=(a,i)=>`${a}-${i}`,Kit=a=>`accOpen_${a.replace(/[^a-zA-Z0-9_$]/g,"_")}`,JZ=(a,i)=>`${a}-s${i}`,YZ=a=>`md_${a.replace(/[^a-zA-Z0-9]/g,"_")}_rows`;function aur(a){switch(a.type){case"number":{let i=a.decimals;return i==null?"{ type: 'number' }":`{ type: 'number', options: { minimumFractionDigits: ${i}, maximumFractionDigits: ${i} } }`}case"currency":return`{ type: 'currency', currency: ${cu(a.currency||"USD")} }`;case"percent":{let i=["type: 'percent'"];return a.valueIsPercentPoints&&i.push("valueIsPercentPoints: true"),a.decimals!=null&&i.push(`options: { minimumFractionDigits: ${a.decimals}, maximumFractionDigits: ${a.decimals} }`),`{ ${i.join(", ")} }`}case"date":case"datetime":return a.pattern?`{ type: '${a.type}', pattern: ${cu(a.pattern)} }`:`{ type: '${a.type}' }`}}function iur(a,i,l,p){if(i.config.kind!=="grid")return`schemaToColumns(${a})`;let f=i.config,g=i.id.replace(/-/g,"_"),_=f.columns.filter(be=>be.show),S=new Set(_.map(be=>be.field)),A=new Set,k=_.map(be=>{let Be=p?.get(be.field);return{c:be,col:Be&&!S.has(Be)?Be:be.field}}).filter(be=>!A.has(be.col)&&!!A.add(be.col)),L=f.editing==="inline"?"":", editable: false";if(k.length===0)return L?`schemaToColumns(${a}).map((c) => ({ ...c${L} }))`:`schemaToColumns(${a})`;let F=k.map(be=>`'${be.col}'`),ee=k.map(({c:be,col:Be})=>{let Ue=[];return be.header&&Ue.push(`header: ${JSON.stringify(be.header)}`),be.width!=null&&Ue.push(`width: ${be.width}`),be.align&&Ue.push(`align: '${be.align}'`),be.aggregate&&Ue.push(`aggregate: '${be.aggregate}'`),f.treeData&&be.field===f.treeData.labelField&&l?Ue.push(`cell: (ctx: CellContext<${l}>) => renderSnippet(treeCell_${g}, { value: ctx.getValue(), row: ctx.row.original })`):be.cellType&&l?Ue.push(`cell: (ctx: CellContext<${l}>) => renderSnippet(${est(g,be.field)}, { value: ctx.getValue() })`):be.format&&Ue.push(`format: ${aur(be.format)}`),Ue.length?`'${Be}': { ${Ue.join(", ")} }`:null}).filter(be=>!!be),J=ee.length?` const ov: Record<string, Partial<(typeof all)[number]>> = { ${ee.join(", ")} };`:"",te=ee.length?", ...(ov[String(c.field)] ?? {})":"",Ie=`[${F.join(", ")}].map((f) => all.find((c) => c.field === f)).filter((c): c is (typeof all)[number] => !!c)`;return`(() => { const all = schemaToColumns(${a});${J} return ${L||te?`${Ie}.map((c) => ({ ...c${L}${te} }))`:Ie} })()`}function eW(a,i){let l=[`grid-column: span ${yM(a)}`,"min-width: 0"];i&&l.push(i);let p=vit(a.style);return p&&l.push(p),`style="${l.join("; ")}"`}var sur=a=>a&&a.replace(/[^#a-zA-Z0-9(),.%\s_-]/g,"").slice(0,40)||"var(--sg-accent)";function z8(a,i){let l=[i,LH(a)].filter(Boolean).join(" ");return l?` class="${l}"`:""}function ofe(a){let i=WZ(a.className);return i?` ${i}`:""}function lur(a){let i=iR(a);if(i==="grid"){let l=qDe(a),p=l.maxWidth?` max-width: ${l.maxWidth}px; margin-inline: auto;`:"";return` .st-screen { grid-template-columns: repeat(12, 1fr); gap: ${l.rowGap}px ${l.colGap}px; align-items: ${l.align};${p} }
|
|
76336
76336
|
@media (max-width: ${l.mobileBreakpoint}px) { .st-screen { grid-template-columns: 1fr; gap: 12px; } }
|
|
76337
76337
|
`}if(i==="stack"){let l=que(a),p=l.maxWidth?` max-width: ${l.maxWidth}px;${l.align==="center"?" margin-inline: auto;":""}`:"",f=l.minHeight?`
|
|
76338
76338
|
.st-stack > * { min-height: ${l.minHeight}px; }`:"",g=l.dividers?`
|
package/dist/designer/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>SvGrid Studio - Designer</title>
|
|
7
|
-
<script type="module" crossorigin src="./assets/index-
|
|
7
|
+
<script type="module" crossorigin src="./assets/index-BxlgvZk3.js"></script>
|
|
8
8
|
<link rel="modulepreload" crossorigin href="./assets/rolldown-runtime-Dd_uD5pT.js">
|
|
9
9
|
<link rel="modulepreload" crossorigin href="./assets/index-client-CwjHmKgT.js">
|
|
10
10
|
<link rel="modulepreload" crossorigin href="./assets/disclose-version-xihTtKlq.js">
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import{SvModal}from"@svgrid/grid";import{cellsLost,cellsUnmatched,guessField,importTargets,importTypeOf,matchColumns,recordsFromMatrix,repeatedRecords,tableFromMatrix,withEveryColumn}from"./base-import";import{BUILTIN_FIELD_TYPES}from"./builtin-types";import{bm,bmCount}from"./messages.svelte";let{open=$bindable(false),tables,current,mode=$bindable("new"),file=null,reader,onImport}=$props();const TYPES=["text","longText","number","currency","percent","checkbox","singleSelect","multiSelect","date","email","url","phone","rating","duration"];const typeLabel=id=>BUILTIN_FIELD_TYPES.find(t=>t.id===id)?.label??id;let matrix=$state.raw(null);let fileName=$state("");let error=$state("");let busy=$state(false);let name=$state("");let types=$state({});let targets=$state([]);let input=$state(null);let dragging=$state(false);let source=$state.raw(null);let delimited=$state(false);let delimiter=$state("");let encoding=$state("");let warnings=$state.raw([]);let chosenDelimiter=$state("");let chosenEncoding=$state("");const DELIMITERS=[[",","shell.importComma"],[";","shell.importSemicolon"],[" ","shell.importTab"],["|","shell.importPipe"]];const ENCODINGS=["utf-8","utf-16le","windows-1252","iso-8859-2","windows-1251","shift_jis","gb18030","euc-kr"];const headers=$derived((matrix?.[0]??[]).map((h,i)=>String(h??"").trim()||bm("shell.importFieldName",{n:i+1})));const body=$derived((matrix??[]).slice(1).filter(r=>r.some(c=>String(c??"").trim()!=="")));const guesses=$derived(headers.map((h,i)=>guessField(h,body.map(r=>String(r[i]??"")))));const fields=$derived(current?importTargets(current):[]);const mapped=$derived(targets.filter(Boolean).length);const lost=$derived.by(()=>{if(!matrix)return 0;if(mode==="append")return cellsLost(matrix,chosen);return cellsLost(matrix,headers.map((_,i)=>({fieldType:types[i]??(i===0?"text":guesses[i]?.fieldType),...guesses[i]?.fieldProps?{fieldProps:guesses[i].fieldProps}:{}})))});const chosen=$derived(current?targets.map(id=>id?current.columns.find(d=>String(d.id??d.field)===id):null):[]);const unmatched=$derived(matrix&&mode==="append"?cellsUnmatched(matrix,chosen):0);const repeated=$derived(matrix&&mode==="append"&¤t?repeatedRecords(matrix,current,targets):0);const warningText=w=>{const vars={count:w.count,line:w.lines[0]??0};if(w.kind==="unclosedQuote")return bmCount("shell.importWarnUnclosed",w.count,vars);if(w.kind==="strayQuote")return bmCount("shell.importWarnStray",w.count,vars);if(w.kind==="longRows")return bmCount("shell.importWarnLong",w.count,vars);if(w.kind==="shortRows")return bmCount("shell.importWarnShort",w.count,vars);return bm("shell.importWarnEncoding",{encoding})};$effect(()=>{if(open&&file)void read(file)});$effect(()=>{if(!open){matrix=null;error="";types={};warnings=[];chosenDelimiter="";chosenEncoding=""}});async function read(f){busy=true;error="";try{const own=reader&&!chosenDelimiter&&!chosenEncoding?await reader(f):null;const out=own?{matrix:own.map(row=>row.map(v=>v==null?"":String(v))),format:"xlsx",warnings:[],delimiter:void 0,encoding:void 0}:await(await import("../import")).readImportMatrix(f,"auto",{maxBytes:20*1024*1024,shownNumbers:true,...chosenDelimiter?{delimiter:chosenDelimiter}:{},...chosenEncoding?{encoding:chosenEncoding}:{}});if(out.warnings.some(w=>w.kind==="binary"))throw new Error(bm("shell.importBinary"));if(out.matrix.length<2)throw new Error(bm("shell.importNoRecords"));fileName=f.name;source=f;delimited=out.format==="csv"||out.format==="tsv";delimiter=out.delimiter??"";encoding=out.encoding??"";warnings=out.warnings;const base=f.name.replace(/\.[^.]+$/,"").replace(/[-_]+/g," ").trim();name=base?base[0].toUpperCase()+base.slice(1):bm("shell.importedName");const all=withEveryColumn(out.matrix);matrix=all;types={};targets=current?matchColumns(all[0].map(h=>String(h??"")),current):[]}catch(e){const code=e?.code;error=code==="no-jszip"?bm("shell.importNeedsZip"):code==="bad-xlsx"?bm("shell.importBadExcel"):code==="bad-json"?bm("shell.importBadJson"):e instanceof Error?e.message:String(e);matrix=null}finally{busy=false}}function readAgain(){if(source)void read(source)}function pick(e){const f=e.currentTarget.files?.[0];if(f)void read(f)}function drop(e){e.preventDefault();dragging=false;const f=e.dataTransfer?.files?.[0];if(f)void read(f)}function run(){if(!matrix)return;if(mode==="new"){onImport({mode:"new",table:tableFromMatrix(matrix,tables,name,types)})}else if(current){const out=recordsFromMatrix(matrix,current,targets);onImport({mode:"append",table:current.id,rows:out.rows,columns:out.columns,unmatched})}open=false}const preview=i=>body.slice(0,3).map(r=>String(r[i]??"")).filter(Boolean).join(", ");const selectValue=e=>e.currentTarget.value;
|
|
2
|
+
import{SvModal}from"@svgrid/grid";import{cellsLost,cellsUnmatched,guessField,importTargets,importTypeOf,matchColumns,mergeByKey,recordsFromMatrix,repeatedRecords,tableFromMatrix,withEveryColumn}from"./base-import";import{primaryOf}from"./base-tables";import{BUILTIN_FIELD_TYPES}from"./builtin-types";import{bm,bmCount}from"./messages.svelte";let{open=$bindable(false),tables,current,mode=$bindable("new"),file=null,reader,onImport}=$props();const TYPES=["text","longText","number","currency","percent","checkbox","singleSelect","multiSelect","date","email","url","phone","rating","duration"];const typeLabel=id=>BUILTIN_FIELD_TYPES.find(t=>t.id===id)?.label??id;let matrix=$state.raw(null);let fileName=$state("");let error=$state("");let busy=$state(false);let name=$state("");let types=$state({});let targets=$state([]);let onRepeat=$state("add");let matchBy=$state("");let input=$state(null);let dragging=$state(false);let source=$state.raw(null);let delimited=$state(false);let delimiter=$state("");let encoding=$state("");let warnings=$state.raw([]);let chosenDelimiter=$state("");let chosenEncoding=$state("");const DELIMITERS=[[",","shell.importComma"],[";","shell.importSemicolon"],[" ","shell.importTab"],["|","shell.importPipe"]];const ENCODINGS=["utf-8","utf-16le","windows-1252","iso-8859-2","windows-1251","shift_jis","gb18030","euc-kr"];const headers=$derived((matrix?.[0]??[]).map((h,i)=>String(h??"").trim()||bm("shell.importFieldName",{n:i+1})));const body=$derived((matrix??[]).slice(1).filter(r=>r.some(c=>String(c??"").trim()!=="")));const guesses=$derived(headers.map((h,i)=>guessField(h,body.map(r=>String(r[i]??"")))));const fields=$derived(current?importTargets(current):[]);const mapped=$derived(targets.filter(Boolean).length);const lost=$derived.by(()=>{if(!matrix)return 0;if(mode==="append")return cellsLost(matrix,chosen);return cellsLost(matrix,headers.map((_,i)=>({fieldType:types[i]??(i===0?"text":guesses[i]?.fieldType),...guesses[i]?.fieldProps?{fieldProps:guesses[i].fieldProps}:{}})))});const chosen=$derived(current?targets.map(id=>id?current.columns.find(d=>String(d.id??d.field)===id):null):[]);const unmatched=$derived(matrix&&mode==="append"?cellsUnmatched(matrix,chosen):0);const repeated=$derived(matrix&&mode==="append"&¤t?repeatedRecords(matrix,current,targets):0);const canUpdate=$derived(!!current&&!current.source?.server);const matchChoices=$derived(current?fields.filter(f=>targets.includes(f.id)):[]);$effect(()=>{if(!current||matchChoices.some(f=>f.id===matchBy))return;const primary=primaryOf(current);matchBy=(matchChoices.find(f=>String(current.columns.find(d=>String(d.id??d.field)===f.id)?.field)===primary)??matchChoices[0])?.id??""});const matchField=$derived(current?String(current.columns.find(d=>String(d.id??d.field)===matchBy)?.field??""):"");const filledFields=$derived(current?targets.filter(id=>!!id).map(id=>String(current.columns.find(d=>String(d.id??d.field)===id)?.field??id)):[]);const merged=$derived.by(()=>{if(!matrix||mode!=="append"||onRepeat!=="update"||!current||!matchField||!canUpdate)return null;const out=mergeByKey(current,recordsFromMatrix(matrix,current,targets).rows,matchField,filledFields);return{updated:out.updates.size,added:out.added.length}});const warningText=w=>{const vars={count:w.count,line:w.lines[0]??0};if(w.kind==="unclosedQuote")return bmCount("shell.importWarnUnclosed",w.count,vars);if(w.kind==="strayQuote")return bmCount("shell.importWarnStray",w.count,vars);if(w.kind==="longRows")return bmCount("shell.importWarnLong",w.count,vars);if(w.kind==="shortRows")return bmCount("shell.importWarnShort",w.count,vars);return bm("shell.importWarnEncoding",{encoding})};$effect(()=>{if(open&&file)void read(file)});$effect(()=>{if(!open){matrix=null;error="";types={};warnings=[];chosenDelimiter="";chosenEncoding=""}});async function read(f){busy=true;error="";try{const own=reader&&!chosenDelimiter&&!chosenEncoding?await reader(f):null;const out=own?{matrix:own.map(row=>row.map(v=>v==null?"":String(v))),format:"xlsx",warnings:[],delimiter:void 0,encoding:void 0}:await(await import("../import")).readImportMatrix(f,"auto",{maxBytes:20*1024*1024,shownNumbers:true,...chosenDelimiter?{delimiter:chosenDelimiter}:{},...chosenEncoding?{encoding:chosenEncoding}:{}});if(out.warnings.some(w=>w.kind==="binary"))throw new Error(bm("shell.importBinary"));if(out.matrix.length<2)throw new Error(bm("shell.importNoRecords"));fileName=f.name;source=f;delimited=out.format==="csv"||out.format==="tsv";delimiter=out.delimiter??"";encoding=out.encoding??"";warnings=out.warnings;const base=f.name.replace(/\.[^.]+$/,"").replace(/[-_]+/g," ").trim();name=base?base[0].toUpperCase()+base.slice(1):bm("shell.importedName");const all=withEveryColumn(out.matrix);matrix=all;types={};targets=current?matchColumns(all[0].map(h=>String(h??"")),current):[]}catch(e){const code=e?.code;error=code==="no-jszip"?bm("shell.importNeedsZip"):code==="bad-xlsx"?bm("shell.importBadExcel"):code==="bad-json"?bm("shell.importBadJson"):e instanceof Error?e.message:String(e);matrix=null}finally{busy=false}}function readAgain(){if(source)void read(source)}function pick(e){const f=e.currentTarget.files?.[0];if(f)void read(f)}function drop(e){e.preventDefault();dragging=false;const f=e.dataTransfer?.files?.[0];if(f)void read(f)}function run(){if(!matrix)return;if(mode==="new"){onImport({mode:"new",table:tableFromMatrix(matrix,tables,name,types)})}else if(current){const out=recordsFromMatrix(matrix,current,targets);onImport({mode:"append",table:current.id,rows:out.rows,columns:out.columns,unmatched,...merged&&matchField?{match:matchField,filled:filledFields}:{}})}open=false}const preview=i=>body.slice(0,3).map(r=>String(r[i]??"")).filter(Boolean).join(", ");const selectValue=e=>e.currentTarget.value;
|
|
3
3
|
</script>
|
|
4
4
|
|
|
5
5
|
<SvModal bind:open title={mode === 'new' ? bm('shell.importNewTitle') : bm('shell.importIntoTitle', { table: current?.name ?? bm('shell.thisTable') })} width={680}>
|
|
@@ -47,7 +47,7 @@ import{SvModal}from"@svgrid/grid";import{cellsLost,cellsUnmatched,guessField,imp
|
|
|
47
47
|
{#each warnings as w (w.kind)}<li>{warningText(w)}</li>{/each}
|
|
48
48
|
{#if lost}<li>{bmCount('shell.importWarnLost', lost, { count: lost })}</li>{/if}
|
|
49
49
|
{#if unmatched}<li>{bmCount('shell.importWarnUnmatched', unmatched, { count: unmatched })}</li>{/if}
|
|
50
|
-
{#if repeated}<li>{bmCount('shell.importWarnRepeated', repeated, { count: repeated })}</li>{/if}
|
|
50
|
+
{#if repeated && !merged}<li>{bmCount('shell.importWarnRepeated', repeated, { count: repeated })}</li>{/if}
|
|
51
51
|
</ul>
|
|
52
52
|
{/if}
|
|
53
53
|
<div class="sv-bimp-modes" role="radiogroup" aria-label={bm('shell.importInto')}>
|
|
@@ -93,6 +93,25 @@ import{SvModal}from"@svgrid/grid";import{cellsLost,cellsUnmatched,guessField,imp
|
|
|
93
93
|
</tbody>
|
|
94
94
|
</table>
|
|
95
95
|
{#if !mapped}<p class="sv-bimp-error">{bm('shell.importNoMapping')}</p>{/if}
|
|
96
|
+
{#if mapped}
|
|
97
|
+
|
|
98
|
+
<div class="sv-bimp-modes" role="radiogroup" aria-label={bm('shell.importRepeatedLabel')}>
|
|
99
|
+
<label class="sv-bimp-mode"><input type="radio" bind:group={onRepeat} value="add" /> {bm('shell.importAddAll')}</label>
|
|
100
|
+
<label class="sv-bimp-mode"><input type="radio" bind:group={onRepeat} value="update" disabled={!canUpdate} /> {bm('shell.importUpdateMatching')}</label>
|
|
101
|
+
</div>
|
|
102
|
+
{#if !canUpdate}
|
|
103
|
+
<p class="sv-bimp-note">{bm('shell.importUpdateTooBig')}</p>
|
|
104
|
+
{:else if onRepeat === 'update'}
|
|
105
|
+
<div class="sv-bimp-read">
|
|
106
|
+
<label>{bm('shell.importMatchBy')}
|
|
107
|
+
<select value={matchBy} onchange={(e) => (matchBy = selectValue(e))}>
|
|
108
|
+
{#each matchChoices as f (f.id)}<option value={f.id}>{f.header}</option>{/each}
|
|
109
|
+
</select>
|
|
110
|
+
</label>
|
|
111
|
+
</div>
|
|
112
|
+
{#if merged}<p class="sv-bimp-note">{bm('shell.importWillMerge', { updated: merged.updated, added: merged.added })}</p>{/if}
|
|
113
|
+
{/if}
|
|
114
|
+
{/if}
|
|
96
115
|
{/if}
|
|
97
116
|
{/if}
|
|
98
117
|
</div>
|
|
@@ -107,5 +126,5 @@ import{SvModal}from"@svgrid/grid";import{cellsLost,cellsUnmatched,guessField,imp
|
|
|
107
126
|
</SvModal>
|
|
108
127
|
|
|
109
128
|
<style>
|
|
110
|
-
.sv-bimp{display:flex;flex-direction:column;gap:12px;font-size:13px;color:var(--sg-fg, #1c1917)}.sv-bimp-drop{display:flex;flex-direction:column;align-items:center;gap:6px;padding:36px 16px;text-align:center;cursor:pointer;border:2px dashed var(--sg-border, #e7e5e4);border-radius:var(--sg-radius-lg, 10px);color:var(--sg-muted, #78716c)}.sv-bimp-drop strong{color:var(--sg-fg, #1c1917);font-weight:600}.sv-bimp-drop.is-over,.sv-bimp-drop:hover{border-color:var(--sg-accent, #2563eb)}.sv-bimp-drop:focus-visible{outline:2px solid var(--sg-focus-ring, var(--sg-accent, #2563eb));outline-offset:2px}.sv-bimp-error{margin:0;color:var(--sg-danger, #dc2626)}.sv-bimp-head{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px}.sv-bimp-file{font-weight:600}.sv-bimp-link{padding:0;border:0;background:none;color:var(--sg-accent, #2563eb);font:inherit;cursor:pointer}.sv-bimp-read{display:flex;flex-wrap:wrap;gap:16px}.sv-bimp-read label{display:inline-flex;align-items:center;gap:6px}.sv-bimp-read select{height:30px;padding:0 8px;font:inherit;color:var(--sg-fg, #1c1917);background:var(--sg-input-bg, var(--sg-bg, #fff));border:1px solid var(--sg-border, #e7e5e4);border-radius:var(--sg-radius, 6px)}.sv-bimp-warn{margin:0;padding:8px 8px 8px 26px;border:1px solid var(--sg-border, #e7e5e4);border-radius:var(--sg-radius, 6px)}.sv-bimp-modes{display:flex;flex-wrap:wrap;gap:16px}.sv-bimp-mode{display:inline-flex;align-items:center;gap:6px;cursor:pointer}.sv-bimp-name{display:flex;align-items:center;gap:8px}.sv-bimp-name input,.sv-bimp-map select{height:30px;padding:0 8px;box-sizing:border-box;font:inherit;color:var(--sg-fg, #1c1917);background:var(--sg-input-bg, var(--sg-bg, #fff));border:1px solid var(--sg-border, #e7e5e4);border-radius:var(--sg-radius, 6px)}.sv-bimp-name input{flex:1 1 auto;max-width:320px}.sv-bimp-map{width:100%;border-collapse:collapse}.sv-bimp-map th{padding:6px 8px;text-align:start;font-weight:600;font-size:12px;color:var(--sg-muted, #78716c);border-bottom:1px solid var(--sg-border, #e7e5e4)}.sv-bimp-map td{padding:5px 8px;border-bottom:1px solid var(--sg-border, #e7e5e4);vertical-align:middle}.sv-bimp-map select{width:100%;min-width:150px}.sv-bimp-col{font-weight:500}.sv-bimp-tag{display:block;font-size:11px;font-weight:400;color:var(--sg-muted, #78716c)}.sv-bimp-sample{max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--sg-muted, #78716c)}.sv-bimp-foot{display:flex;justify-content:flex-end;gap:8px;width:100%}.sv-bimp-btn{height:32px;padding:0 14px;font:inherit;font-size:13px;cursor:pointer;border-radius:var(--sg-radius, 6px);background:transparent;color:var(--sg-fg, #1c1917);border:1px solid var(--sg-border, #e7e5e4)}.sv-bimp-btn.is-primary{background:var(--sg-accent, #2563eb);border-color:var(--sg-accent, #2563eb);color:var(--sg-on-accent, #fff)}.sv-bimp-btn:disabled{opacity:.55;cursor:default}@media(max-width:560px){.sv-bimp-sample{display:none}}
|
|
129
|
+
.sv-bimp{display:flex;flex-direction:column;gap:12px;font-size:13px;color:var(--sg-fg, #1c1917)}.sv-bimp-drop{display:flex;flex-direction:column;align-items:center;gap:6px;padding:36px 16px;text-align:center;cursor:pointer;border:2px dashed var(--sg-border, #e7e5e4);border-radius:var(--sg-radius-lg, 10px);color:var(--sg-muted, #78716c)}.sv-bimp-drop strong{color:var(--sg-fg, #1c1917);font-weight:600}.sv-bimp-drop.is-over,.sv-bimp-drop:hover{border-color:var(--sg-accent, #2563eb)}.sv-bimp-drop:focus-visible{outline:2px solid var(--sg-focus-ring, var(--sg-accent, #2563eb));outline-offset:2px}.sv-bimp-error{margin:0;color:var(--sg-danger, #dc2626)}.sv-bimp-note{margin:0;color:var(--sg-muted, #78716c)}.sv-bimp-head{display:flex;flex-wrap:wrap;align-items:center;justify-content:space-between;gap:8px}.sv-bimp-file{font-weight:600}.sv-bimp-link{padding:0;border:0;background:none;color:var(--sg-accent, #2563eb);font:inherit;cursor:pointer}.sv-bimp-read{display:flex;flex-wrap:wrap;gap:16px}.sv-bimp-read label{display:inline-flex;align-items:center;gap:6px}.sv-bimp-read select{height:30px;padding:0 8px;font:inherit;color:var(--sg-fg, #1c1917);background:var(--sg-input-bg, var(--sg-bg, #fff));border:1px solid var(--sg-border, #e7e5e4);border-radius:var(--sg-radius, 6px)}.sv-bimp-warn{margin:0;padding:8px 8px 8px 26px;border:1px solid var(--sg-border, #e7e5e4);border-radius:var(--sg-radius, 6px)}.sv-bimp-modes{display:flex;flex-wrap:wrap;gap:16px}.sv-bimp-mode{display:inline-flex;align-items:center;gap:6px;cursor:pointer}.sv-bimp-name{display:flex;align-items:center;gap:8px}.sv-bimp-name input,.sv-bimp-map select{height:30px;padding:0 8px;box-sizing:border-box;font:inherit;color:var(--sg-fg, #1c1917);background:var(--sg-input-bg, var(--sg-bg, #fff));border:1px solid var(--sg-border, #e7e5e4);border-radius:var(--sg-radius, 6px)}.sv-bimp-name input{flex:1 1 auto;max-width:320px}.sv-bimp-map{width:100%;border-collapse:collapse}.sv-bimp-map th{padding:6px 8px;text-align:start;font-weight:600;font-size:12px;color:var(--sg-muted, #78716c);border-bottom:1px solid var(--sg-border, #e7e5e4)}.sv-bimp-map td{padding:5px 8px;border-bottom:1px solid var(--sg-border, #e7e5e4);vertical-align:middle}.sv-bimp-map select{width:100%;min-width:150px}.sv-bimp-col{font-weight:500}.sv-bimp-tag{display:block;font-size:11px;font-weight:400;color:var(--sg-muted, #78716c)}.sv-bimp-sample{max-width:220px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--sg-muted, #78716c)}.sv-bimp-foot{display:flex;justify-content:flex-end;gap:8px;width:100%}.sv-bimp-btn{height:32px;padding:0 14px;font:inherit;font-size:13px;cursor:pointer;border-radius:var(--sg-radius, 6px);background:transparent;color:var(--sg-fg, #1c1917);border:1px solid var(--sg-border, #e7e5e4)}.sv-bimp-btn.is-primary{background:var(--sg-accent, #2563eb);border-color:var(--sg-accent, #2563eb);color:var(--sg-on-accent, #fff)}.sv-bimp-btn:disabled{opacity:.55;cursor:default}@media(max-width:560px){.sv-bimp-sample{display:none}}
|
|
111
130
|
</style>
|