tinybase 3.2.0 → 3.3.0
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/lib/cjs/store.cjs +1 -1
- package/lib/cjs/store.cjs.gz +0 -0
- package/lib/cjs/tinybase.cjs +1 -1
- package/lib/cjs/tinybase.cjs.gz +0 -0
- package/lib/cjs/tools.cjs +1 -1
- package/lib/cjs/tools.cjs.gz +0 -0
- package/lib/cjs/ui-react.cjs +1 -1
- package/lib/cjs/ui-react.cjs.gz +0 -0
- package/lib/cjs-es6/store.cjs +1 -1
- package/lib/cjs-es6/store.cjs.gz +0 -0
- package/lib/cjs-es6/tinybase.cjs +1 -1
- package/lib/cjs-es6/tinybase.cjs.gz +0 -0
- package/lib/cjs-es6/tools.cjs +1 -1
- package/lib/cjs-es6/tools.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react.cjs +1 -1
- package/lib/cjs-es6/ui-react.cjs.gz +0 -0
- package/lib/debug/store.js +53 -13
- package/lib/debug/tinybase.js +53 -13
- package/lib/debug/tools.js +93 -1
- package/lib/debug/ui-react.js +24 -0
- package/lib/es6/store.js +1 -1
- package/lib/es6/store.js.gz +0 -0
- package/lib/es6/tinybase.js +1 -1
- package/lib/es6/tinybase.js.gz +0 -0
- package/lib/es6/tools.js +1 -1
- package/lib/es6/tools.js.gz +0 -0
- package/lib/es6/ui-react.js +1 -1
- package/lib/es6/ui-react.js.gz +0 -0
- package/lib/store.js +1 -1
- package/lib/store.js.gz +0 -0
- package/lib/tinybase.js +1 -1
- package/lib/tinybase.js.gz +0 -0
- package/lib/tools.js +1 -1
- package/lib/tools.js.gz +0 -0
- package/lib/types/store.d.ts +302 -9
- package/lib/types/tools.d.ts +2 -2
- package/lib/types/ui-react.d.ts +156 -0
- package/lib/types/with-schemas/store.d.ts +405 -16
- package/lib/types/with-schemas/tools.d.ts +2 -2
- package/lib/types/with-schemas/ui-react.d.ts +181 -5
- package/lib/ui-react.js +1 -1
- package/lib/ui-react.js.gz +0 -0
- package/lib/umd/store.js +1 -1
- package/lib/umd/store.js.gz +0 -0
- package/lib/umd/tinybase.js +1 -1
- package/lib/umd/tinybase.js.gz +0 -0
- package/lib/umd/tools.js +1 -1
- package/lib/umd/tools.js.gz +0 -0
- package/lib/umd/ui-react.js +1 -1
- package/lib/umd/ui-react.js.gz +0 -0
- package/lib/umd-es6/store.js +1 -1
- package/lib/umd-es6/store.js.gz +0 -0
- package/lib/umd-es6/tinybase.js +1 -1
- package/lib/umd-es6/tinybase.js.gz +0 -0
- package/lib/umd-es6/tools.js +1 -1
- package/lib/umd-es6/tools.js.gz +0 -0
- package/lib/umd-es6/ui-react.js +1 -1
- package/lib/umd-es6/ui-react.js.gz +0 -0
- package/package.json +15 -15
- package/readme.md +2 -2
package/lib/tools.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=e=>typeof e,t="",l=e(t),a=e(!0),n=e(0),o="type",d="default",r="Listener",s="get",I="add",$="Ids",c="Table",i=c+"s",u=c+$,p="Row",b=p+$,C="Sorted"+p+$,h="Cell",g=h+$,m="Value",f=m+"s",w=m+$,y=(e,t)=>e.every(t),T=(e,t)=>e.sort(t),v=(e,t)=>e.forEach(t),V=(e,t)=>e.map(t),x=e=>e.length,R=e=>0==x(e),k=(e,t)=>e.filter(t),S=(e,...t)=>e.push(...t),P=e=>e.pop(),A=(e,...t)=>e.unshift(...t),E=e=>e.shift(),D=JSON.parse,O=isFinite,N=(e,t)=>e instanceof t,j=e=>null==e,L=e=>e==l||e==a,M=t=>e(t)==l,G=e=>Array.isArray(e),J=t=>{const l=e(t);return L(l)||l==n&&O(t)?l:void 0},z=(e,t)=>e?.has(t)??!1,W=e=>[...e?.values()??[]],B=(e,t)=>e?.forEach(t),F=(e,t)=>e?.delete(t),U=e=>new Map(e),_=(e,t)=>e?.get(t),Z=(e,t)=>B(e,((e,l)=>t(l,e))),H=(e,t)=>V([...e?.entries()??[]],(([e,l])=>t(l,e))),Q=(e,t,l)=>j(l)?(F(e,t),e):e?.set(t,l),q=(e,t,l)=>(z(e,t)||Q(e,t,l()),_(e,t)),K=e=>e.toUpperCase(),X=e=>e.toLowerCase(),Y="a ",ee="A function for",te=", and registers a listener so that any changes to that result will cause a re-render",le="Callback",ae="Del",ne="Deps",oe=ne+"?: React.DependencyList",de="doRollback?: DoRollback",re="actions: () => Return, "+de,se="export",Ie="Id",$e="Invalid",ce="Json",ie=X(r),ue="?: ",pe=" | undefined",be="NonNullable",Ce="Partial",he="Props",ge="Provider",me=`Registers a ${ie} that will be called`,fe="Represents",we="rowId: "+Ie,ye="Schema",Te="Set",ve=", descending?: boolean, offset?: number, limit?: number",Ve="[]",xe="the Store",Re="Transaction",ke=X(Re),Se="Execute a "+ke+" to make multiple mutations",Pe="Explicitly starts a "+ke,Ae="Explicitly finishes a "+ke,Ee="the end of the "+ke,De="void",Oe=" => "+De,Ne="WhenSet",je=" when setting it",Le=Y+"string serialization of",Me=" ",Ge="Gets a callback that can ",Je="the ",ze=" the schema for",We=(e=0,l=0)=>`the ${dt[e]}content of`+(l?Me+xe:t),Be=(e=0,l,a=0)=>at[l]+Me+We(e,1)+(a?" when setting it":t),Fe=(e,t=0)=>fe+` a Row when ${t?"s":"g"}etting ${We()} the '${e}' `+c,Ue=(e,t,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in `+t,_e=(e,t)=>`Calls a function for each ${e} in `+t,Ze=e=>"The props passed to a component that renders "+e,He=e=>"A function that takes "+e,Qe=(e,t=0)=>ee+" listening to changes to "+ot[e]+" in "+ot[t],qe=(e,l,a=0)=>me+" whenever "+ot[e]+" in "+ot[l]+" change"+(a?t:"s"),Ke=e=>`the '${e}' `+c,Xe=e=>"the specified Row in "+Ke(e),Ye=(e,t=0)=>at[t]+` ${We()} `+Ke(e),et=(e,t=0)=>at[t]+` ${We()} `+Xe(e),tt=(e,t,l=0)=>at[l]+` the '${t}' Cell for `+Xe(e),lt=(e,t=0)=>at[t]+` the '${e}' Value`,at=["Gets","Checks existence of","Sets","Deletes","Sets part of",fe,"Gets "+Le,"Sets "+Le,me+" whenever",Ge+"set",Ge+"add",Ge+"set part of",Ge+"delete","Renders","Gets "+Le+ze,"Sets"+ze,"Deletes"+ze],nt=[s,"has","set","del","set","forEach",I,t],ot=[xe,i,Je+c+Me+$,Y+c,Je+p+Me+$,Y+p,Je+h+Me+$,Y+h,"invalid Cell changes",f,Je+m+Me+$,Y+m,"invalid Value changes",Je+"sorted "+p+Me+$],dt=[t,"tabular ","keyed value "],rt=e=>new Set(G(e)||j(e)?e:[e]),st=(e,t)=>e?.add(t),It=/[^A-Za-z]+/,$t=/[^A-Za-z0-9]+/,ct=/^( *)\/\*\* *(.*?) *\*\/$/gm,it=(e,t,l)=>e.substring(t,l),ut=e=>e.includes(","),pt=(e,t,l,a=1)=>{const n=`${t}${1==a?"":a}`;return z(e,n)?pt(e,t,l,a+1):(Q(e,n,l),n)},bt=e=>e.replace(ct,((e,t,l)=>{const a=77-Ct(t);return`${t}/**\n${l.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),t+" * $1\n")}${t} */`})),Ct=e=>e.length,ht=(e,l=t)=>e.join(l),gt=e=>e.flat(1e3),mt=(e,t=0)=>ht(V(e.split($t),((e,l)=>(l>0||t?K:X)(it(e,0,1))+it(e,1)))),ft=e=>K(ht((e&&!It.test(e[0])?e:" "+e).split($t),"_")),wt=e=>`/** ${e}. */`,yt=(...e)=>ht(k(e,(e=>e)),", "),Tt=(...e)=>"{"+ht(e,"; ")+"}",vt=(...e)=>Tt(...V(e,(e=>"readonly "+e))),Vt=()=>{const e=[U(),U(),U(),U()],l=U(),a=U();return[(...e)=>ht(gt(e),"\n"),(t,l,...a)=>v(a,(a=>v([0,1],(n=>(t??n)==n?st(q(e[n],l,rt),a):0)))),(e,a,n,o=t,d=1)=>pt(l,e,[a,n,o,d]),(e,t,l)=>pt(a,e,G(l)?[`(${t}) => {`,l,"}"]:[`(${t}) => ${l}`]),(e,t)=>_(a,e)===t?e:pt(a,e,t),(l=0)=>V([...T(H(e[l],((e,t)=>`import {${ht(T(W(e)),", ")}} from '${t}';`)),((e,t)=>ut(e)!=ut(t)?ut(e)?-1:1:e>t?1:-1)),t],(e=>e.replace("{React}","React"))),()=>H(l,(([e,l,a,n],o)=>[wt(l),`${n?se+" ":t}type ${o}${a} = ${e};`,t])),()=>H(a,((e,l)=>(e=G(e)?e:[e],S(e,P(e)+";"),[`const ${l} = ${E(e)}`,e,t])))]},xt=Object,Rt=xt.keys,kt=xt.freeze,St=e=>N(e,xt)&&e.constructor==xt,Pt=(e,t)=>V(xt.entries(e),(([e,l])=>t(l,e))),At=e=>St(e)&&R(Rt(e)),Et=e=>{const t=new WeakMap;return l=>(t.has(l)||t.set(l,e(l)),t.get(l))},Dt=(e,t,l)=>[t=>Pt(e,((e,a)=>t(a,mt(a,1),l(ft(a),`'${a}'`)))),(t,a)=>Pt(e[t],((e,t)=>a(t,e[o],e[d],l(ft(t),`'${t}'`),mt(t,1)))),e=>Pt(t,((t,a)=>e(a,t[o],t[d],l(ft(a),`'${a}'`),mt(a,1))))],Ot=(e,l,a,n)=>[(n,o)=>{const d=n+": "+o,s=e(i,Tt(...l((e=>`'${e}'?: {[rowId: Id]: `+Tt(...a(e,((e,l,a)=>`'${e}'${j(a)?"?":t}: ${l}`)))+"}"))),Be(1,5)),I=e(i+Ne,Tt(...l((e=>`'${e}'?: {[rowId: Id]: `+Tt(...a(e,((e,t)=>`'${e}'?: ${t}`)))+"}"))),Be(1,5,1)),$=e(c+Ie,"keyof "+s,"A "+c+" Id in "+xe),m=`<TId extends ${$}>`,f=e(c,be+`<${s}[TId]>`,"A "+c+" in "+xe,m),w=e(c+Ne,be+`<${I}[TId]>`,"A "+c+" in "+xe+je,m),y=e(p,f+"<TId>[Id]","A "+p+" in a "+c,m),T=e(p+Ne,w+"<TId>[Id]","A "+p+" in a "+c+je,m),v=e(h+Ie,`Extract<keyof ${y}<TId>, Id>`,"A "+h+" Id in a "+p,m),V=e(h,be+`<${s}[TId]>[Id][CId]`,"A "+h+" in a "+p,`<TId extends ${$}, CId extends ${v}<TId>>`),x=e("CellIdCellArray",`CId extends ${v}<TId> ? [cellId: CId, cell: ${V}<TId, CId>] : never`,h+" Ids and types in a "+p,`<TId extends ${$}, CId = ${v}<TId>>`,0),R=e(h+le,`(...[cellId, cell]: ${x}<TId>)`+Oe,He(Y+h+" Id, and "+h),m),k=e(p+le,"(rowId: Id, forEachCell: (cellCallback: CellCallback<TId>) "+Oe+") "+Oe,He(Y+p+" Id, and a "+h+" iterator"),m),S=e("TableIdForEachRowArray",`TId extends ${$} ? [tableId: TId, forEachRow: (rowCallback: ${k}<TId>)${Oe}] : never`,c+" Ids and callback types",`<TId = ${$}>`,0),P=e(c+le,`(...[tableId, forEachRow]: ${S})`+Oe,He(Y+c+" Id, and a "+p+" iterator"),t),A=e("TableIdRowIdCellIdArray",`TId extends ${$} ? [tableId: TId, rowId: Id, cellId: ${v}<TId>] : never`,"Ids for GetCellChange",`<TId = ${$}>`,0),E=e("GetCellChange",`(...[tableId, rowId, cellId]: ${A}) => CellChange`,ee+" returning information about any Cell's changes during a "+ke),D=e(i+r,`(${d}, getCellChange: ${E}${pe})`+Oe,Qe(1)),O=e(u+r,`(${d})`+Oe,Qe(2)),N=e(c+r,`(${d}, tableId: ${$}, getCellChange: ${E}${pe})`+Oe,Qe(3)),L=e(b+r,`(${d}, tableId: ${$})`+Oe,Qe(4,3)),M=e(C+r,"("+yt(d,"tableId: "+$,"cellId: Id"+pe,"descending: boolean","offset: number","limit: number"+pe,"sortedRowIds: Ids")+")"+Oe,Qe(13,3)),G=e(p+r,"("+yt(""+d,"tableId: "+$,we,`getCellChange: ${E}${pe}`)+")"+Oe,Qe(5,3)),J=e(g+r,"("+yt(""+d,"tableId: "+$,we)+")"+Oe,Qe(6,5)),z=e("CellListenerArgsArrayInner",`CId extends ${v}<TId> ? [${d}, tableId: TId, ${we}, cellId: CId, newCell: ${V}<TId, CId> ${pe}, oldCell: ${V}<TId, CId> ${pe}, getCellChange: ${E} ${pe}] : never`,"Cell args for CellListener",`<TId extends ${$}, CId = ${v}<TId>>`,0),W=e("CellListenerArgsArrayOuter",`TId extends ${$} ? `+z+"<TId> : never","Table args for CellListener",`<TId = ${$}>`,0);return[s,I,$,f,w,y,T,v,V,R,k,P,D,O,N,L,M,G,J,e(h+r,`(...[${n}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${W})`+Oe,Qe(7,5)),e($e+h+r,`(${d}, tableId: Id, ${we}, cellId: Id, invalidCells: any[])`+Oe,Qe(8))]},(l,a)=>{const o=l+": "+a,d=e(f,Tt(...n(((e,l,a)=>`'${e}'${j(a)?"?":t}: ${l}`))),Be(2,5)),s=e(f+Ne,Tt(...n(((e,t)=>`'${e}'?: ${t}`))),Be(2,5,1)),I=e(m+Ie,"keyof "+d,"A "+m+" Id in "+xe),$=e(m,be+`<${d}[VId]>`,"A "+m+" Id in "+xe,`<VId extends ${I}>`),c=e("ValueIdValueArray",`VId extends ${I} ? [valueId: VId, value: ${$}<VId>] : never`,m+" Ids and types in "+xe,`<VId = ${I}>`,0),i=e(m+le,`(...[valueId, value]: ${c})`+Oe,He(Y+m+" Id, and "+m)),u=e("GetValueChange",`(valueId: ${I}) => ValueChange`,ee+" returning information about any Value's changes during a "+ke),p=e(f+r,`(${o}, getValueChange: ${u}${pe})`+Oe,Qe(9)),b=e(w+r,`(${o})`+Oe,Qe(10)),C=e("ValueListenerArgsArray",`VId extends ${I} ? [${o}, valueId: VId, newValue: ${$}<VId> ${pe}, oldValue: ${$}<VId> ${pe}, getValueChange: ${u} ${pe}] : never`,"Value args for ValueListener",`<VId = ${I}>`,0);return[d,s,I,$,i,p,b,e(m+r,`(...[${l}, valueId, newValue, oldValue, getValueChange]: `+C+")"+Oe,Qe(11)),e($e+m+r,`(${o}, valueId: Id, invalidValues: any[])`+Oe,Qe(12))]},(t,l)=>e(Re+r,`(${t}: ${l}, cellsTouched: boolean, valuesTouched: boolean)`+Oe,ee+" listening to the completion of a "+ke)],Nt=(e,l=t,a=t)=>`store.${e}(${l})`+(a?" as "+a:t),jt=(e,l=t)=>`fluent(() => ${Nt(e,l)})`,Lt=(e,l=t,a=t)=>`store.${e}(${l?l+", ":t}proxy(listener)${a?", "+a:t})`,Mt=(e,l,n)=>{const[s,y,T,V,x,R,k,P]=Vt(),[E,D,O]=Dt(e,l,x),[N,L,G]=Ot(T,E,D,O),J=U(),z=(e=0)=>H(J,(([l,a,n,o,d],r)=>{const s=e?[r+`: ${d}(${l}): ${a} => ${n},`]:[r+d+`(${l}): ${a};`];return e||A(s,wt(o)),S(s,t),s})),B=(e,l,a,n,o,d=t)=>pt(J,e,[l,a,n,o,d]),F=(e,l,a,n,o,d=t,r=t,s=t)=>B(nt[e]+l+(4==e?Ce:t)+a,d,n,(n==X?jt:Nt)(nt[e]+(4==e?Ce:t)+a,r,e?void 0:n),o,s),q=(e,l,a,n=t,o=t,d=1,s=t)=>B(I+e+r,(n?n+", ":t)+ie+": "+l+(d?", mutator?: boolean":t),Ie,Lt(I+e+r,o,d?"mutator":t),a,s),K=`./${mt(n)}.d`,X=mt(n,1),Y=mt(X),ee=[],te=U();let ae=[],ne=[];if(y(1,K,X,`create${X} as create${X}Decl`),!At(e)){y(0,"tinybase","CellChange"),y(null,"tinybase",$);const[e,l,n,r,s,I,m,f,w,V,R,k,P,A,O,L,G,J,z,B,Z]=N(Y,X),H=U();E(((e,t)=>{const l=`<'${e}'>`,a=[T(t+c,r+l,fe+` the '${e}' `+c),T(t+c+Ne,s+l,fe+` the '${e}' `+c+je),T(t+p,I+l,Fe(e)),T(t+p+Ne,m+l,Fe(e,1)),T(t+h+Ie,f+l,`A Cell Id for the '${e}' `+c),T(t+h+le,V+l,He(`a Cell Id and value from a Row in the '${e}' `+c)),T(t+p+le,R+l,He(`a Row Id from the '${e}' Table, and a Cell iterator`))];Q(H,e,a),y(1,K,...a)})),y(1,K,e,l,n,f,k,P,A,O,L,G,J,z,B,Z),ae=[e,l,n,f,P,A,O,L,G,J,z,B,H],v([[e],[a],[X,"tables: "+l,"tables"],[X]],(([e,l,a],n)=>F(n,t,i,e,Be(1,n),l,a))),F(0,t,u,n+Ve,Ue(c,xe)),F(5,t,c,De,_e(c,xe),"tableCallback: "+k,"tableCallback as any"),E(((e,l,n)=>{const[o,d,r,s,I,i,u]=_(H,e);v([[o],[a],[X,"table: "+d,", table"],[X]],(([a,o,d=t],r)=>F(r,l,c,a,Ye(e,r),o,n+d))),F(0,l,b,$,Ue(p,Ke(e)),t,n),F(0,l,C,$,Ue(p,Ke(e),1),"cellId?: "+I+ve,n+", cellId, descending, offset, limit"),F(5,l,p,De,_e(p,Ke(e)),"rowCallback: "+u,n+", rowCallback as any"),v([[r],[a],[X,", row: "+s,", row"],[X],[X,", partialRow: "+s,", partialRow"]],(([a,o=t,d=t],r)=>F(r,l,p,a,et(e,r),we+o,n+", rowId"+d))),F(6,l,p,Ie+pe,"Add a new Row to "+Ke(e),"row: "+s+", reuseIds?: boolean",n+", row, reuseIds"),F(0,l,g,I+Ve,Ue(h,Xe(e)),we,n+", rowId"),F(5,l,h,De,_e(h,Xe(e)),we+", cellCallback: "+i,n+", rowId, cellCallback as any"),D(e,((o,d,r,s,I)=>{const $="Map"+mt(d,1);Q(te,d,$);const c=d+(j(r)?pe:t);v([[c],[a],[X,`, cell: ${d} | `+$,", cell as any"],[X]],(([a,d=t,r=t],$)=>F($,l+I,h,a,tt(e,o,$),we+d,n+", rowId, "+s+r)))}))})),F(0,t,i+ce,ce,Be(1,6)),F(2,t,i+ce,X,Be(1,7),"tablesJson: "+ce,"tables"+ce),q(i,P,Be(1,8)+" changes"),q(u,A,qe(2,0,1)),q(c,O,qe(3,0),`tableId: ${n} | null`,"tableId"),q(b,L,qe(4,3,1),`tableId: ${n} | null`,"tableId"),q(C,G,qe(13,3,1),yt("tableId: TId",`cellId: ${f}<TId>`+pe,"descending: boolean","offset: number","limit: number"+pe),yt("tableId","cellId","descending","offset","limit"),1,"<TId extends TableId>"),q(p,J,qe(5,3),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),q(g,z,qe(6,5,1),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),q(h,B,qe(7,5),`tableId: ${n} | null, rowId: IdOrNull, cellId: ${ht(E((e=>_(H,e)?.[4]??t))," | ")} | null`,"tableId, rowId, cellId"),q($e+h,Z,me+" whenever an invalid Cell change was attempted","tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull","tableId, rowId, cellId"),y(1,K,...W(te)),S(ee,".set"+i+ye+"({",gt(E(((e,l,a)=>[`[${a}]: {`,...D(e,((e,l,a,n)=>`[${n}]: {[${x(ft(o),`'${o}'`)}]: ${x(ft(l),`'${l}'`)}${j(a)?t:`, [${x(ft(d),`'${d}'`)}]: `+(M(a)?x(ft(a),`'${a}'`):a)}},`)),"},"]))),"})")}if(!At(l)){const[e,l,n,r,s,I,$,c,i]=L(Y,X);y(1,K,e,l,n,s,I,$,c,i),ne=[e,l,n,I,$,c],v([[e],[a],[X,"values: "+l,"values"],[X],[X,"partialValues: "+l,"partialValues"]],(([e,l,a],n)=>F(n,t,f,e,Be(2,n),l,a))),F(0,t,w,n+Ve,Ue(m,xe)),F(5,t,m,"void",_e(m,xe),"valueCallback: "+s,"valueCallback as any"),O(((e,l,n,o,d)=>{const r="Map"+mt(l,1);Q(te,l,r),v([[l],[a],[X,`value: ${l} | `+r,", value as any"],[X]],(([l,a,n=t],r)=>F(r,d,m,l,lt(e,r),a,o+n)))})),F(0,t,f+ce,ce,Be(2,6)),F(2,t,f+ce,X,Be(2,7),"valuesJson: "+ce,"values"+ce),q(f,I,Be(2,8)+" changes"),q(w,$,qe(10,0,1)),q(m,c,qe(11,0),`valueId: ${n} | null`,"valueId"),q($e+m,i,me+" whenever an invalid Value change was attempted","valueId: IdOrNull","valueId"),y(1,K,...W(te)),y(0,"tinybase","ValueChange"),S(ee,".set"+f+ye+"({",O(((e,l,a,n)=>[`[${n}]: {[${x(ft(o),`'${o}'`)}]: ${x(ft(l),`'${l}'`)}${j(a)?t:`, [${x(ft(d),`'${d}'`)}]: `+(M(a)?x(ft(a),`'${a}'`):a)}},`])),"})")}Z(te,((e,t)=>T(t,`(cell: ${e}${pe}) => `+e,`Takes a ${e} Cell value and returns another`))),y(null,"tinybase","DoRollback",Ie,"IdOrNull",ce,"Store"),F(0,t,ce,ce,Be(0,6)),F(2,t,ce,X,Be(0,7),"tablesAndValuesJson: "+ce,"tablesAndValuesJson"),F(7,t,ke,"Return",Se,re,"actions, doRollback","<Return>"),F(7,t,"start"+Re,X,Pe),F(7,t,"finish"+Re,X,Ae,de,"doRollback");const oe=G(Y,X);return q("Start"+Re,oe,me+" just before the start of the "+ke,t,t,0),q("WillFinish"+Re,oe,me+" just before "+Ee,t,t,0),q("DidFinish"+Re,oe,me+" just after "+Ee,t,t,0),F(7,t,"call"+r,X,"Manually provoke a listener to be called","listenerId: Id","listenerId"),F(3,t,r,X,"Remove a listener that was previously added to "+xe,"listenerId: Id","listenerId"),B("getStore",t,"Store","store",at[0]+" the underlying Store object"),y(1,"tinybase","createStore"),y(1,K,X,`create${X} as create${X}Decl`,oe),x("store",["createStore()",...ee]),V("fluent","actions: () => Store",["actions();",`return ${Y};`]),V("proxy","listener: any",`(_: Store, ...params: any[]) => listener(${Y}, ...params)`),x(Y,["{",...z(1),"}"]),[s(...R(0),...k(),se+" interface "+X+" {",...z(0),"}",t,wt(`Creates a ${X} object`),se+" function create"+X+"(): "+X+";"),s(...R(1),se+" const create"+X+": typeof create"+X+"Decl = () => {",...P(),`return Object.freeze(${Y});`,"};"),ae,ne]},Gt=e=>s+e,Jt=e=>yt(Gt(e),Gt(e)+ne),zt="debugIds?: boolean",Wt="debugIds={debugIds}",Bt="then"+oe,Ft="Parameter",Ut=": (parameter: "+Ft+", store: Store) => ",_t="const contextValue = useContext(Context);",Zt=", based on a parameter",Ht=": ",Qt="<"+Ft+",>",qt=Ft+"ized"+le+"<"+Ft+">",Kt="rowId",Xt="rowId={rowId}",Yt=", separator, debugIds",el="separator?: ReactElement | string",tl="then?: (store: Store",ll=yt(tl+")"+Oe,Bt),al="then, then"+ne,nl=Kt+Ht+Ie,ol="View",dl=(e,...t)=>yt(...t,ie+": "+e,ie+oe,"mutator?: boolean"),rl=(...e)=>yt(...e,ie,ie+ne,"mutator"),sl=(e,l,a,n,o)=>{const[d,s,I,y,T,v,V,x]=Vt(),[R,k,P]=Dt(e,l,T),E=`./${mt(a)}.d`,D=`./${mt(a)}-ui-react.d`,O="tinybase/ui-react",N=mt(a,1),L=mt(N),M=N+"Or"+N+Ie,G=L+"Or"+N+Ie,J=L+`={${L}}`,z=U(),W=(e,l,a,n,o,d=t)=>(s(1,D,e+" as "+e+"Decl"),pt(z,e,[l,a,n,o,d])),B=(e,l,a,n,o,d=t)=>W("use"+e,l,a,n,o,d),F=(e,l,a,n,o=t,d=t,r=t,I=t,$=t)=>(s(1,O,`use${l} as use${l}Core`),B(e,yt(o,X,I),a,ne+`(${G}, use${l}Core, [`+(d||t)+($?"], ["+$:t)+"]);",n,r)),Z=(e,t,l,a)=>W(e,t,1,l,a),Q=(e=0)=>H(z,(([l,a,n,o,d],r)=>{const s=e?[se+` const ${r}: typeof ${r}Decl = ${d}(${l}): ${1==a?"any":a} =>`,n]:[se+` function ${r}${d}(${l}): ${1==a?"ComponentReturnType":a};`];return e||A(s,wt(o)),S(s,t),s}));s(null,"tinybase",Ie,"Store",le,Ft+"ized"+le),s(0,O,"ComponentReturnType"),s(null,O,"ExtraProps"),s(0,E,N);const q=I(M,N+" | "+Ie,`Used when you need to refer to a ${N} in a React hook or component`),K=I(ge+he,vt(L+ue+N,L+`ById?: {[${L}Id: Id]: ${N}}`),`Used with the ${ge} component, so that a `+N+" can be passed into the context of an application");s(0,"react","ReactElement","ComponentType"),s(1,"react","React"),s(1,D,q,K);const X=G+ue+q;T("{createContext, useContext, useMemo}","React"),T("Context",`createContext<[${N}?, {[${L}Id: Id]: ${N}}?]>([])`),B("Create"+N,`create: () => ${N}, create`+oe,N,"\n// eslint-disable-next-line react-hooks/exhaustive-deps\nuseMemo(create, createDeps)",`Create a ${N} within a React application with convenient memoization`);const ee=B(N,"id?: Id",N+pe,["{",_t,"return id == null ? contextValue[0] : contextValue[1]?.[id];","}"],`Get a reference to a ${N} from within a ${ge} component context`),ne=y("useHook",G+`: ${q} | undefined, hook: (...params: any[]) => any, preParams: any[], postParams: any[] = []`,[`const ${L} = ${ee}(${G} as Id);`,`return hook(...preParams, ((${G} == null || typeof ${G} == 'string')`,`? ${L} : ${G})?.getStore(), ...postParams)`]),de=y("getProps","getProps: ((id: any) => ExtraProps) | undefined, id: Id","(getProps == null) ? ({} as ExtraProps) : getProps(id)"),re=y("wrap",yt("children: any","separator?: any","encloseWithId?: boolean","id?: Id"),["const separated = separator==null || !Array.isArray(children)"," ? children"," : children.map((child, c) => (c > 0 ? [separator, child] : child));","return encloseWithId ? [id, ':{', separated, '}'] : separated;"]),$e=T("NullComponent","() => null");if(!At(e)){const[e,l,a,o,d,m,f,w,T,v,V,x,S]=n;s(null,E,e,l,a,d,m,f,w,T,v,V,x),s(0,E,o),s(1,E,N),s(null,"tinybase",$,"IdOrNull");const P=y("tableView",`{${L}, rowComponent, getRowComponentProps`+Yt+"}: any, rowIds: Ids, tableId: Id, defaultRowComponent: React.ComponentType<any>",["const Row = rowComponent ?? defaultRowComponent;",`return ${re}(rowIds.map((rowId) => (`,"<Row","{..."+de+"(getRowComponentProps, rowId)}","key={rowId}","tableId={tableId}",Xt,J,Wt,"/>","))",Yt,", tableId,",");"]),A=y("getDefaultTableComponent","tableId: Id",ht(R(((e,t,l)=>`tableId == ${l} ? ${t}TableView : `)))+$e),O=y("getDefaultCellComponent","tableId: Id, cellId: Id",ht(R(((e,t,l)=>`tableId == ${l} ? ${ht(k(e,((e,l,a,n,o)=>`cellId == ${n} ? `+t+o+"CellView : ")))+$e} : `)))+$e);F(i,i,e,Be(1,0)+te);const M=F(u,u,a+Ve,Ue(c,xe)+te);F(Te+i+le,Te+i+le,qt,Be(1,9)+Zt,yt(Gt(i)+Ut+l,Gt(i)+oe),Jt(i),Qt,yt(tl,`tables: ${l})`+Oe,Bt),al),F(ae+i+le,ae+i+le,le,Be(1,12),t,t,t,ll,al);const G=I(h+he,vt("tableId?: TId","rowId: Id","cellId?: CId",L+ue+N,zt),Ze(Y+h),`<TId extends ${a}, CId extends ${o}<TId>>`),z=I(p+he,vt("tableId?: TId","rowId: Id",L+ue+N,"cellComponents?: {readonly [CId in "+o+`<TId>]?: ComponentType<${G}<TId, CId>>;}`,`getCellComponentProps?: (cellId: ${o}<TId>) => ExtraProps`,el,zt),Ze(Y+p),`<TId extends ${a}>`),W=I(c+he,vt("tableId?: TId",L+ue+N,`rowComponent?: ComponentType<${z}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps",el,zt),Ze(Y+c),`<TId extends ${a}>`),B=I("Sorted"+c+he,vt("tableId?: TId","cellId?: "+o+"<TId>","descending?: boolean","offset?: number","limit?: number",L+ue+N,`rowComponent?: ComponentType<${z}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps",el,zt),Ze(Y+"sorted "+c),`<TId extends ${a}>`),U=I(i+he,vt(L+ue+N,"tableComponents?: {readonly [TId in "+a+`]?: ComponentType<${W}<TId>>;}`,`getTableComponentProps?: (tableId: ${a}) => ExtraProps`,el,zt),Ze(We(1,1)));s(1,D,U,W,B,z,G),Z(i+ol,"{"+L+", tableComponents, getTableComponentProps"+Yt+"}: "+U,[re+`(${M}(${L}).map((tableId) => {`,"const Table = (tableComponents?.[tableId] ?? "+A+"(tableId)) as React.ComponentType<TableProps<typeof tableId>>;","return <Table",`{...${de}(getTableComponentProps, tableId)}`,"tableId={tableId}","key={tableId}",J,Wt,"/>;","}), separator)"],Be(1,13)+te),R(((e,l,a)=>{const[n,o,d,r,I]=_(S,e);s(null,E,n,o,d,r,I),F(l+c,c,n,Ye(e)+te,t,a);const i=F(l+b,b,$,Ue(p,Ke(e))+te,t,a),u=F(l+C,C,$,Ue(p,Ke(e),1)+te,"cellId?: "+I+", descending?: boolean, offset?: number, limit?: number",a+", cellId, descending, offset, limit");F(l+p,p,d,et(e)+te,nl,yt(a,Kt));const m=F(l+g,g,I+Ve,Ue(h,Xe(e))+te,nl,yt(a,Kt));F(Te+l+c+le,Te+c+le,qt,Ye(e,9)+Zt,yt(Gt(c)+Ut+o,Gt(c)+oe),yt(a,Jt(c)),Qt,yt(tl,`table: ${o})`+Oe,Bt),al),F(ae+l+c+le,ae+c+le,le,Ye(e,12),t,a,t,ll,al),F(Te+l+p+le,Te+p+le,qt,et(e,9)+Zt,yt(nl,Gt(p)+Ut+r,Gt(p)+oe),yt(a,Kt,Jt(p)),Qt,yt(tl,`row: ${r})`+Oe,Bt),al),F("Add"+l+p+le,"Add"+p+le,qt,et(e,10)+Zt,yt(Gt(p)+Ut+r,Gt(p)+oe),yt(a,Jt(p)),Qt,"then?: ("+yt(nl+pe,"store: Store","row: "+r+")"+Oe,"then"+oe)+", reuseRowIds?: boolean",al+", reuseRowIds"),F(Te+l+Ce+p+le,Te+Ce+p+le,qt,et(e,11)+Zt,yt(nl,Gt(Ce+p)+Ut+r,Gt(Ce+p)+oe),yt(a,Kt,Jt(Ce+p)),Qt,yt(tl,`partialRow: ${r})`+Oe,Bt),al),F(ae+l+p+le,ae+p+le,le,et(e,12),nl,yt(a,Kt),t,ll,al);const f=Z(l+p+ol,"{rowId, "+L+", cellComponents, getCellComponentProps"+Yt+`}: ${z}<'${e}'>`,[re+`(${m}(rowId, ${L}).map((cellId) => {`,"const Cell = (cellComponents?.[cellId] ?? "+O+`(${a}, cellId)) as React.ComponentType<CellProps<typeof `+a+", typeof cellId>>;","return <Cell",`{...${de}(getCellComponentProps, cellId)} `,"key={cellId}",`tableId={${a}}`,Xt,"cellId={cellId}",J,Wt,"/>;","})"+Yt+", rowId)"],et(e,13)+te);Z(l+"Sorted"+c+ol,"{cellId, descending, offset, limit, ...props}: "+B+`<'${e}'>`,P+"(props, "+u+`(cellId, descending, offset, limit, props.${L}), ${a}, ${f});`,Ye(e,13)+", sorted"+te),Z(l+c+ol,`props: ${W}<'${e}'>`,P+"(props, "+i+`(props.${L}), ${a}, ${f});`,Ye(e,13)+te),k(e,((n,o,d,r,I)=>{const $="Map"+mt(o,1);s(0,E,$),s(1,E,$);const c=F(l+I+h,h,o+(j(d)?pe:t),tt(e,n)+te,nl,yt(a,Kt,r));F(Te+l+I+h+le,Te+h+le,qt,tt(e,n,9)+Zt,yt(nl,Gt(h)+Ut+o+" | "+$,Gt(h)+oe),yt(a,Kt,r,Jt(h)),Qt,yt(tl,`cell: ${o} | ${$})`+Oe,Bt),al),F(ae+l+I+h+le,ae+h+le,le,tt(e,n,12),yt(nl,"forceDel?: boolean"),yt(a,Kt,r,"forceDel"),t,ll,al),Z(l+I+h+ol,`{rowId, ${L}, debugIds}: `+G+`<'${e}', '${n}'>`,[re+`('' + ${c}(rowId, `+L+`) ?? '', undefined, debugIds, ${r})`],tt(e,n,13)+te)}))}));const H=ht(R((e=>_(S,e)?.[4]??t))," | ");F(i+r,i+r,De,Be(1,8)+" changes",dl(d),rl()),F(u+r,u+r,De,qe(2,0,1),dl(m),rl()),F(c+r,c+r,De,qe(3,0),dl(f,`tableId: ${a} | null`),rl("tableId")),F(b+r,b+r,De,qe(4,3,1),dl(w,`tableId: ${a} | null`),rl("tableId")),F(C+r,C+r,De,qe(13,3,1),dl(T,`tableId: ${a} | null`,"cellId: "+H+pe,"descending: boolean","offset: number","limit: number"+pe),rl("tableId","cellId","descending","offset","limit")),F(p+r,p+r,De,qe(5,3),dl(v,`tableId: ${a} | null`,Kt+": IdOrNull"),rl("tableId",Kt)),F(g+r,g+r,De,qe(6,5,1),dl(V,`tableId: ${a} | null`,Kt+": IdOrNull"),rl("tableId",Kt)),F(h+r,h+r,De,qe(7,5),dl(x,`tableId: ${a} | null`,Kt+": IdOrNull",`cellId: ${H} | null`),rl("tableId",Kt,"cellId"))}if(!At(l)){const[e,l,a,n,d,$]=o;s(null,E,...o),s(1,E,N);const c=y("getDefaultValueComponent","valueId: Id",ht(P(((e,t,l,a,n)=>`valueId == ${a} ? `+n+"ValueView : ")))+$e);F(f,f,e,Be(2,0)+te);const i=F(w,w,a+Ve,Ue(m,xe)+te);F(Te+f+le,Te+f+le,qt,Be(2,9)+Zt,yt(Gt(f)+Ut+l,Gt(f)+oe),Jt(f),Qt,yt(tl,`values: ${l})`+Oe,Bt),al),F(Te+Ce+f+le,Te+Ce+f+le,qt,Be(2,11)+Zt,yt(Gt(Ce+f)+Ut+l,Gt(Ce+f)+oe),Jt(Ce+f),Qt,yt(tl,`partialValues: ${l})`+Oe,Bt),al),F(ae+f+le,ae+f+le,le,Be(2,12),t,t,t,ll,al);const u=I(m+he,vt("valueId?: VId",L+ue+N,zt),Ze("a Value"),`<VId extends ${a}>`),p=I(f+he,vt(L+ue+N,"valueComponents?: {readonly [VId in "+a+`]?: ComponentType<${u}<VId>>;}`,`getValueComponentProps?: (valueId: ${a}) => ExtraProps`,el,zt),Ze(We(2,1)));s(1,D,p,u),Z(f+ol,"{"+L+", valueComponents, getValueComponentProps"+Yt+"}: "+p,[re+`(${i}(${L}).map((valueId) => {`,"const Value = valueComponents?.[valueId] ?? "+c+"(valueId);","return <Value",`{...${de}(getValueComponentProps, valueId)}`,"key={valueId}",J,Wt,"/>;","}), separator)"],Be(2,13)+te),P(((e,l,a,n,o)=>{const d="Map"+mt(l,1);s(0,E,d),s(1,E,d);const r=F(o+m,m,l,lt(e)+te,t,n);F(Te+o+m+le,Te+m+le,qt,lt(e,9)+Zt,yt(Gt(m)+Ut+l+" | "+d,Gt(m)+oe),yt(n,Jt(m)),Qt,yt(tl,`value: ${l} | ${d})`+Oe,Bt),al),F(ae+o+m+le,ae+m+le,le,lt(e,12),t,n,t,ll,al),Z(o+m+ol,`{${L}, debugIds}: ${u}<'${e}'>`,[re+`('' + ${r}(`+L+`) ?? '', undefined, debugIds, ${n})`],lt(e,13)+te)})),F(f+r,f+r,De,Be(2,8)+" changes",dl(n),rl()),F(w+r,w+r,De,qe(10,0,1),dl(d),rl()),F(m+r,m+r,De,qe(11,0),dl($,`valueId: ${a} | null`),rl("valueId"))}return Z(ge,`{${L}, ${L}ById, children}: `+K+" & {children: React.ReactNode}",["{",_t,"return (","<Context."+ge,"value={useMemo(",`() => [${L} ?? contextValue[0], {...contextValue[1], ...${L}ById}],`,`[${L}, ${L}ById, contextValue],`,")}>","{children}",`</Context.${ge}>`,");","}"],"Wraps part of an application in a context that provides default objects to be used by hooks and components within"),[d(...v(0),...V(),...Q(0)),d(...v(1),...x(),...Q(1))]},Il=(e,l,a)=>{if(At(e)&&At(l))return[t,t,t,t];const[n,o,d,r]=Mt(e,l,a);return[n,o,...sl(e,l,a,d,r)]},$l={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},cl=Et((e=>{const t=()=>{const t=D(e.getTablesSchemaJson());return!At(t)||y(e.getTableIds(),(l=>{const a=e.getRowIds(l),n=U();if(y(a,(t=>y(e.getCellIds(l,t),(a=>{const o=e.getCell(l,t,a),d=q(n,a,(()=>[J(o),U(),[0],0])),[r,s,[I]]=d,$=q(s,o,(()=>0))+1;return $>I&&(d[2]=[$,o]),Q(s,o,$),d[3]++,r==J(o)})))))return t[l]={},B(n,(([e,,[,n],r],s)=>{t[l][s]={[o]:e,...r==x(a)?{[d]:n}:{}}})),1}))?t:{}},l=()=>{const t=D(e.getValuesSchemaJson());return At(t)&&e.forEachValue(((e,l)=>{t[e]={[o]:J(l)}})),t},a=e=>Il(t(),l(),e),n=async e=>{const t=["d.ts","ts","d.ts","tsx"];let l;try{l=(await import("prettier")).format}catch(e){l=e=>e}return V(a(e),((e,a)=>bt(l(e,{...$l,filepath:"_."+t[a]}))))};return kt({getStoreStats:t=>{let l=0,a=0,n=0;const o={};return e.forEachTable(((e,d)=>{l++;let r=0,s=0;const I={};d(((e,l)=>{r++;let a=0;l((()=>a++)),s+=a,t&&(I[e]={rowCells:a})})),a+=r,n+=s,t&&(o[e]={tableRows:r,tableCells:s,rows:I})})),{totalTables:l,totalRows:a,totalCells:n,totalValues:x(e.getValueIds()),jsonLength:Ct(e.getJson()),...t?{detail:{tables:o}}:{}}},getStoreTablesSchema:t,getStoreValuesSchema:l,getStoreApi:a,getPrettyStoreApi:n,getStore:()=>e})}));export{cl as createTools};
|
|
1
|
+
const e=e=>typeof e,t="",l=e(t),a=e(!0),n=e(0),o="type",d="default",r="Listener",s="get",I="add",$="Ids",c="Table",i=c+"s",u=c+$,p="Row",b=p+$,C="Sorted"+p+$,h="Cell",m=h+$,g="Value",f=g+"s",w=g+$,y=(e,t)=>e.every(t),T=(e,t)=>e.sort(t),v=(e,t)=>e.forEach(t),V=(e,t)=>e.map(t),x=e=>e.length,R=e=>0==x(e),k=(e,t)=>e.filter(t),S=(e,...t)=>e.push(...t),P=e=>e.pop(),A=(e,...t)=>e.unshift(...t),E=e=>e.shift(),D=JSON.parse,O=isFinite,N=(e,t)=>e instanceof t,j=e=>null==e,L=e=>e==l||e==a,M=t=>e(t)==l,G=e=>Array.isArray(e),J=t=>{const l=e(t);return L(l)||l==n&&O(t)?l:void 0},z=(e,t)=>e?.has(t)??!1,W=e=>[...e?.values()??[]],B=(e,t)=>e?.forEach(t),F=(e,t)=>e?.delete(t),U=e=>new Map(e),_=(e,t)=>e?.get(t),Z=(e,t)=>B(e,((e,l)=>t(l,e))),H=(e,t)=>V([...e?.entries()??[]],(([e,l])=>t(l,e))),Q=(e,t,l)=>j(l)?(F(e,t),e):e?.set(t,l),q=(e,t,l)=>(z(e,t)||Q(e,t,l()),_(e,t)),K=e=>e.toUpperCase(),X=e=>e.toLowerCase(),Y="a ",ee="A function for",te=", and registers a listener so that any changes to that result will cause a re-render",le="Callback",ae="Del",ne="Deps",oe=ne+"?: React.DependencyList",de="doRollback?: DoRollback",re="actions: () => Return, "+de,se="export",Ie="Id",$e="Invalid",ce="Json",ie=X(r),ue="?: ",pe=" | undefined",be="NonNullable",Ce="Partial",he="Props",me="Provider",ge=`Registers a ${ie} that will be called`,fe="Represents",we="rowId: "+Ie,ye="Schema",Te="Set",ve=", descending?: boolean, offset?: number, limit?: number",Ve="[]",xe="the Store",Re="Transaction",ke=X(Re),Se="Execute a "+ke+" to make multiple mutations",Pe="Explicitly starts a "+ke,Ae="Explicitly finishes a "+ke,Ee="the end of the "+ke,De="void",Oe=" => "+De,Ne="WhenSet",je=" when setting it",Le=Y+"string serialization of",Me=" ",Ge="Gets a callback that can ",Je="the ",ze=" the schema for",We=(e=0,l=0)=>`the ${dt[e]}content of`+(l?Me+xe:t),Be=(e=0,l,a=0)=>at[l]+Me+We(e,1)+(a?" when setting it":t),Fe=(e,t=0)=>fe+` a Row when ${t?"s":"g"}etting ${We()} the '${e}' `+c,Ue=(e,t,l=0)=>`Gets ${l?"sorted, paginated":"the"} Ids of the ${e}s in `+t,_e=(e,t)=>`Calls a function for each ${e} in `+t,Ze=e=>"The props passed to a component that renders "+e,He=e=>"A function that takes "+e,Qe=(e,t=0)=>ee+" listening to changes to "+ot[e]+" in "+ot[t],qe=(e,l,a=0)=>ge+" whenever "+ot[e]+" in "+ot[l]+" change"+(a?t:"s"),Ke=e=>`the '${e}' `+c,Xe=e=>"the specified Row in "+Ke(e),Ye=(e,t=0)=>at[t]+` ${We()} `+Ke(e),et=(e,t=0)=>at[t]+` ${We()} `+Xe(e),tt=(e,t,l=0)=>at[l]+` the '${t}' Cell for `+Xe(e),lt=(e,t=0)=>at[t]+` the '${e}' Value`,at=["Gets","Checks existence of","Sets","Deletes","Sets part of",fe,"Gets "+Le,"Sets "+Le,ge+" whenever",Ge+"set",Ge+"add",Ge+"set part of",Ge+"delete","Renders","Gets "+Le+ze,"Sets"+ze,"Deletes"+ze],nt=[s,"has","set","del","set","forEach",I,t],ot=[xe,i,Je+c+Me+$,Y+c,Je+p+Me+$,Y+p,Je+h+Me+$,Y+h,"invalid Cell changes",f,Je+g+Me+$,Y+g,"invalid Value changes",Je+"sorted "+p+Me+$,Je+h+Me+$+" anywhere"],dt=[t,"tabular ","keyed value "],rt=e=>new Set(G(e)||j(e)?e:[e]),st=(e,t)=>e?.add(t),It=/[^A-Za-z]+/,$t=/[^A-Za-z0-9]+/,ct=/^( *)\/\*\* *(.*?) *\*\/$/gm,it=(e,t,l)=>e.substring(t,l),ut=e=>e.includes(","),pt=(e,t,l,a=1)=>{const n=`${t}${1==a?"":a}`;return z(e,n)?pt(e,t,l,a+1):(Q(e,n,l),n)},bt=e=>e.replace(ct,((e,t,l)=>{const a=77-Ct(t);return`${t}/**\n${l.replace(RegExp(`([^\\n]{1,${a}})(\\s|$)`,"g"),t+" * $1\n")}${t} */`})),Ct=e=>e.length,ht=(e,l=t)=>e.join(l),mt=e=>e.flat(1e3),gt=(e,t=0)=>ht(V(e.split($t),((e,l)=>(l>0||t?K:X)(it(e,0,1))+it(e,1)))),ft=e=>K(ht((e&&!It.test(e[0])?e:" "+e).split($t),"_")),wt=e=>`/** ${e}. */`,yt=(...e)=>ht(k(e,(e=>e)),", "),Tt=(...e)=>"{"+ht(e,"; ")+"}",vt=(...e)=>Tt(...V(e,(e=>"readonly "+e))),Vt=()=>{const e=[U(),U(),U(),U()],l=U(),a=U(),n=e=>{const t=e.indexOf(" as ");return-1!=t?e.substring(t+4):e};return[(...e)=>ht(mt(e),"\n"),(t,l,...a)=>v(a,(a=>v([0,1],(n=>(t??n)==n?st(q(e[n],l,rt),a):0)))),(e,a,n,o=t,d=1)=>pt(l,e,[a,n,o,d]),(e,t,l)=>pt(a,e,G(l)?[`(${t}) => {`,l,"}"]:[`(${t}) => ${l}`]),(e,t)=>_(a,e)===t?e:pt(a,e,t),(l=0)=>V([...T(H(e[l],((e,t)=>`import {${ht(T(W(e),((e,t)=>n(e)>n(t)?1:-1)),", ")}} from '${t}';`)),((e,t)=>ut(e)!=ut(t)?ut(e)?-1:1:e>t?1:-1)),t],(e=>e.replace("{React}","React"))),()=>H(l,(([e,l,a,n],o)=>[wt(l),`${n?se+" ":t}type ${o}${a} = ${e};`,t])),()=>H(a,((e,l)=>(e=G(e)?e:[e],S(e,P(e)+";"),[`const ${l} = ${E(e)}`,e,t])))]},xt=Object,Rt=xt.keys,kt=xt.freeze,St=e=>N(e,xt)&&e.constructor==xt,Pt=(e,t)=>V(xt.entries(e),(([e,l])=>t(l,e))),At=e=>St(e)&&R(Rt(e)),Et=e=>{const t=new WeakMap;return l=>(t.has(l)||t.set(l,e(l)),t.get(l))},Dt=(e,t,l)=>[t=>Pt(e,((e,a)=>t(a,gt(a,1),l(ft(a),`'${a}'`)))),(t,a)=>Pt(e[t],((e,t)=>a(t,e[o],e[d],l(ft(t),`'${t}'`),gt(t,1)))),e=>Pt(t,((t,a)=>e(a,t[o],t[d],l(ft(a),`'${a}'`),gt(a,1))))],Ot=(e,l,a,n)=>[(n,o)=>{const d=n+": "+o,s=e(i,Tt(...l((e=>`'${e}'?: {[rowId: Id]: `+Tt(...a(e,((e,l,a)=>`'${e}'${j(a)?"?":t}: ${l}`)))+"}"))),Be(1,5)),I=e(i+Ne,Tt(...l((e=>`'${e}'?: {[rowId: Id]: `+Tt(...a(e,((e,t)=>`'${e}'?: ${t}`)))+"}"))),Be(1,5,1)),$=e(c+Ie,"keyof "+s,"A "+c+" Id in "+xe),g=`<TId extends ${$}>`,f=e(c,be+`<${s}[TId]>`,"A "+c+" in "+xe,g),w=e(c+Ne,be+`<${I}[TId]>`,"A "+c+" in "+xe+je,g),y=e(p,f+"<TId>[Id]","A "+p+" in a "+c,g),T=e(p+Ne,w+"<TId>[Id]","A "+p+" in a "+c+je,g),v=e(h+Ie,`Extract<keyof ${y}<TId>, Id>`,"A "+h+" Id in a "+p,g),V=e(h,be+`<${s}[TId]>[Id][CId]`,"A "+h+" in a "+p,`<TId extends ${$}, CId extends ${v}<TId>>`),x=e("CellIdCellArray",`CId extends ${v}<TId> ? [cellId: CId, cell: ${V}<TId, CId>] : never`,h+" Ids and types in a "+p,`<TId extends ${$}, CId = ${v}<TId>>`,0),R=e(h+le,`(...[cellId, cell]: ${x}<TId>)`+Oe,He(Y+h+" Id, and "+h),g),k=e(p+le,"(rowId: Id, forEachCell: (cellCallback: CellCallback<TId>) "+Oe+") "+Oe,He(Y+p+" Id, and a "+h+" iterator"),g),S=e(c+h+le,`(cellId: ${v}<TId>, count: number) `+Oe,He(Y+h+" Id, and count of how many times it appears"),g),P=e("TableIdForEachRowArray",`TId extends ${$} ? [tableId: TId, forEachRow: (rowCallback: ${k}<TId>)${Oe}] : never`,c+" Ids and callback types",`<TId = ${$}>`,0),A=e(c+le,`(...[tableId, forEachRow]: ${P})`+Oe,He(Y+c+" Id, and a "+p+" iterator"),t),E=e("TableIdRowIdCellIdArray",`TId extends ${$} ? [tableId: TId, rowId: Id, cellId: ${v}<TId>] : never`,"Ids for GetCellChange",`<TId = ${$}>`,0),D=e("GetCellChange",`(...[tableId, rowId, cellId]: ${E}) => CellChange`,ee+" returning information about any Cell's changes during a "+ke),O=e(i+r,`(${d}, getCellChange: ${D}${pe})`+Oe,Qe(1)),N=e(u+r,`(${d})`+Oe,Qe(2)),L=e(c+r,`(${d}, tableId: ${$}, getCellChange: ${D}${pe})`+Oe,Qe(3)),M=e(c+m+r,`(${d}, tableId: ${$})`+Oe,Qe(14,3)),G=e(b+r,`(${d}, tableId: ${$})`+Oe,Qe(4,3)),J=e(C+r,"("+yt(d,"tableId: "+$,"cellId: Id"+pe,"descending: boolean","offset: number","limit: number"+pe,"sortedRowIds: Ids")+")"+Oe,Qe(13,3)),z=e(p+r,"("+yt(""+d,"tableId: "+$,we,`getCellChange: ${D}${pe}`)+")"+Oe,Qe(5,3)),W=e(m+r,"("+yt(""+d,"tableId: "+$,we)+")"+Oe,Qe(6,5)),B=e("CellListenerArgsArrayInner",`CId extends ${v}<TId> ? [${d}, tableId: TId, ${we}, cellId: CId, newCell: ${V}<TId, CId> ${pe}, oldCell: ${V}<TId, CId> ${pe}, getCellChange: ${D} ${pe}] : never`,"Cell args for CellListener",`<TId extends ${$}, CId = ${v}<TId>>`,0),F=e("CellListenerArgsArrayOuter",`TId extends ${$} ? `+B+"<TId> : never","Table args for CellListener",`<TId = ${$}>`,0);return[s,I,$,f,w,y,T,v,V,R,k,S,A,O,N,L,M,G,J,z,W,e(h+r,`(...[${n}, tableId, rowId, cellId, newCell, oldCell, getCellChange]: ${F})`+Oe,Qe(7,5)),e($e+h+r,`(${d}, tableId: Id, ${we}, cellId: Id, invalidCells: any[])`+Oe,Qe(8))]},(l,a)=>{const o=l+": "+a,d=e(f,Tt(...n(((e,l,a)=>`'${e}'${j(a)?"?":t}: ${l}`))),Be(2,5)),s=e(f+Ne,Tt(...n(((e,t)=>`'${e}'?: ${t}`))),Be(2,5,1)),I=e(g+Ie,"keyof "+d,"A "+g+" Id in "+xe),$=e(g,be+`<${d}[VId]>`,"A "+g+" Id in "+xe,`<VId extends ${I}>`),c=e("ValueIdValueArray",`VId extends ${I} ? [valueId: VId, value: ${$}<VId>] : never`,g+" Ids and types in "+xe,`<VId = ${I}>`,0),i=e(g+le,`(...[valueId, value]: ${c})`+Oe,He(Y+g+" Id, and "+g)),u=e("GetValueChange",`(valueId: ${I}) => ValueChange`,ee+" returning information about any Value's changes during a "+ke),p=e(f+r,`(${o}, getValueChange: ${u}${pe})`+Oe,Qe(9)),b=e(w+r,`(${o})`+Oe,Qe(10)),C=e("ValueListenerArgsArray",`VId extends ${I} ? [${o}, valueId: VId, newValue: ${$}<VId> ${pe}, oldValue: ${$}<VId> ${pe}, getValueChange: ${u} ${pe}] : never`,"Value args for ValueListener",`<VId = ${I}>`,0);return[d,s,I,$,i,p,b,e(g+r,`(...[${l}, valueId, newValue, oldValue, getValueChange]: `+C+")"+Oe,Qe(11)),e($e+g+r,`(${o}, valueId: Id, invalidValues: any[])`+Oe,Qe(12))]},(t,l)=>e(Re+r,`(${t}: ${l}, cellsTouched: boolean, valuesTouched: boolean)`+Oe,ee+" listening to the completion of a "+ke)],Nt=(e,l=t,a=t)=>`store.${e}(${l})`+(a?" as "+a:t),jt=(e,l=t)=>`fluent(() => ${Nt(e,l)})`,Lt=(e,l=t,a=t)=>`store.${e}(${l?l+", ":t}proxy(listener)${a?", "+a:t})`,Mt=(e,l,n)=>{const[s,y,T,V,x,R,k,P]=Vt(),[E,D,O]=Dt(e,l,x),[N,L,G]=Ot(T,E,D,O),J=U(),z=(e=0)=>H(J,(([l,a,n,o,d],r)=>{const s=e?[r+`: ${d}(${l}): ${a} => ${n},`]:[r+d+`(${l}): ${a};`];return e||A(s,wt(o)),S(s,t),s})),B=(e,l,a,n,o,d=t)=>pt(J,e,[l,a,n,o,d]),F=(e,l,a,n,o,d=t,r=t,s=t)=>B(nt[e]+l+(4==e?Ce:t)+a,d,n,(n==X?jt:Nt)(nt[e]+(4==e?Ce:t)+a,r,e?void 0:n),o,s),q=(e,l,a,n=t,o=t,d=1,s=t)=>B(I+e+r,(n?n+", ":t)+ie+": "+l+(d?", mutator?: boolean":t),Ie,Lt(I+e+r,o,d?"mutator":t),a,s),K=`./${gt(n)}.d`,X=gt(n,1),Y=gt(X),ee=[],te=U();let ae=[],ne=[];if(y(1,K,X,`create${X} as create${X}Decl`),!At(e)){y(0,"tinybase","CellChange"),y(null,"tinybase",$);const[e,l,n,r,s,I,g,f,w,V,R,k,P,A,O,L,G,J,z,B,Z,H,ne]=N(Y,X),oe=U();E(((e,t)=>{const l=`<'${e}'>`,a=[T(t+c,r+l,fe+` the '${e}' `+c),T(t+c+Ne,s+l,fe+` the '${e}' `+c+je),T(t+p,I+l,Fe(e)),T(t+p+Ne,g+l,Fe(e,1)),T(t+h+Ie,f+l,`A Cell Id for the '${e}' `+c),T(t+h+le,V+l,He(`a Cell Id and value from a Row in the '${e}' `+c)),T(t+p+le,R+l,He(`a Row Id from the '${e}' Table, and a Cell iterator`)),T(t+c+h+le,k+l,He(`a Cell Id from anywhere in the '${e}' Table, and a count of how many times it appears`))];Q(oe,e,a),y(1,K,...a)})),y(1,K,e,l,n,f,P,A,O,L,G,J,z,B,Z,H,ne),ae=[e,l,n,f,A,O,L,G,J,z,B,Z,H,oe],v([[e],[a],[X,"tables: "+l,"tables"],[X]],(([e,l,a],n)=>F(n,t,i,e,Be(1,n),l,a))),F(0,t,u,n+Ve,Ue(c,xe)),F(5,t,c,De,_e(c,xe),"tableCallback: "+P,"tableCallback as any"),E(((e,l,n)=>{const[o,d,r,s,I,i,u,g]=_(oe,e);v([[o],[a],[X,"table: "+d,", table"],[X]],(([a,o,d=t],r)=>F(r,l,c,a,Ye(e,r),o,n+d))),F(0,l,c+m,$,Ue(h,"the whole of "+Ke(e)),t,n),F(5,l,c+h,De,_e(c+h,"the whole of "+Ke(e)),"tableCellCallback: "+g,n+", tableCellCallback as any"),F(0,l,b,$,Ue(p,Ke(e)),t,n),F(0,l,C,$,Ue(p,Ke(e),1),"cellId?: "+I+ve,n+", cellId, descending, offset, limit"),F(5,l,p,De,_e(p,Ke(e)),"rowCallback: "+u,n+", rowCallback as any"),v([[r],[a],[X,", row: "+s,", row"],[X],[X,", partialRow: "+s,", partialRow"]],(([a,o=t,d=t],r)=>F(r,l,p,a,et(e,r),we+o,n+", rowId"+d))),F(6,l,p,Ie+pe,"Add a new Row to "+Ke(e),"row: "+s+", reuseIds?: boolean",n+", row, reuseIds"),F(0,l,m,I+Ve,Ue(h,Xe(e)),we,n+", rowId"),F(5,l,h,De,_e(h,Xe(e)),we+", cellCallback: "+i,n+", rowId, cellCallback as any"),D(e,((o,d,r,s,I)=>{const $="Map"+gt(d,1);Q(te,d,$);const i=d+(j(r)?pe:t);v([[i],[a],[X,`, cell: ${d} | `+$,", cell as any"],[X]],(([a,d=t,r=t],$)=>F($,l+I,h,a,tt(e,o,$),we+d,n+", rowId, "+s+r))),F(1,l+I,c+h,a,at[1]+` the '${o}' Cell anywhere in `+Ke(e),t,n+", "+s)}))})),F(0,t,i+ce,ce,Be(1,6)),F(2,t,i+ce,X,Be(1,7),"tablesJson: "+ce,"tables"+ce),q(i,A,Be(1,8)+" changes"),q(u,O,qe(2,0,1)),q(c,L,qe(3,0),`tableId: ${n} | null`,"tableId"),q(c+m,G,qe(14,3,1),`tableId: ${n} | null`,"tableId"),q(b,J,qe(4,3,1),`tableId: ${n} | null`,"tableId"),q(C,z,qe(13,3,1),yt("tableId: TId",`cellId: ${f}<TId>`+pe,"descending: boolean","offset: number","limit: number"+pe),yt("tableId","cellId","descending","offset","limit"),1,"<TId extends TableId>"),q(p,B,qe(5,3),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),q(m,Z,qe(6,5,1),`tableId: ${n} | null, rowId: IdOrNull`,"tableId, rowId"),q(h,H,qe(7,5),`tableId: ${n} | null, rowId: IdOrNull, cellId: ${ht(E((e=>_(oe,e)?.[4]??t))," | ")} | null`,"tableId, rowId, cellId"),q($e+h,ne,ge+" whenever an invalid Cell change was attempted","tableId: IdOrNull, rowId: IdOrNull, cellId: IdOrNull","tableId, rowId, cellId"),y(1,K,...W(te)),S(ee,".set"+i+ye+"({",mt(E(((e,l,a)=>[`[${a}]: {`,...D(e,((e,l,a,n)=>`[${n}]: {[${x(ft(o),`'${o}'`)}]: ${x(ft(l),`'${l}'`)}${j(a)?t:`, [${x(ft(d),`'${d}'`)}]: `+(M(a)?x(ft(a),`'${a}'`):a)}},`)),"},"]))),"})")}if(!At(l)){const[e,l,n,r,s,I,$,c,i]=L(Y,X);y(1,K,e,l,n,s,I,$,c,i),ne=[e,l,n,I,$,c],v([[e],[a],[X,"values: "+l,"values"],[X],[X,"partialValues: "+l,"partialValues"]],(([e,l,a],n)=>F(n,t,f,e,Be(2,n),l,a))),F(0,t,w,n+Ve,Ue(g,xe)),F(5,t,g,"void",_e(g,xe),"valueCallback: "+s,"valueCallback as any"),O(((e,l,n,o,d)=>{const r="Map"+gt(l,1);Q(te,l,r),v([[l],[a],[X,`value: ${l} | `+r,", value as any"],[X]],(([l,a,n=t],r)=>F(r,d,g,l,lt(e,r),a,o+n)))})),F(0,t,f+ce,ce,Be(2,6)),F(2,t,f+ce,X,Be(2,7),"valuesJson: "+ce,"values"+ce),q(f,I,Be(2,8)+" changes"),q(w,$,qe(10,0,1)),q(g,c,qe(11,0),`valueId: ${n} | null`,"valueId"),q($e+g,i,ge+" whenever an invalid Value change was attempted","valueId: IdOrNull","valueId"),y(1,K,...W(te)),y(0,"tinybase","ValueChange"),S(ee,".set"+f+ye+"({",O(((e,l,a,n)=>[`[${n}]: {[${x(ft(o),`'${o}'`)}]: ${x(ft(l),`'${l}'`)}${j(a)?t:`, [${x(ft(d),`'${d}'`)}]: `+(M(a)?x(ft(a),`'${a}'`):a)}},`])),"})")}Z(te,((e,t)=>T(t,`(cell: ${e}${pe}) => `+e,`Takes a ${e} Cell value and returns another`))),y(null,"tinybase","DoRollback",Ie,"IdOrNull",ce,"Store"),F(0,t,ce,ce,Be(0,6)),F(2,t,ce,X,Be(0,7),"tablesAndValuesJson: "+ce,"tablesAndValuesJson"),F(7,t,ke,"Return",Se,re,"actions, doRollback","<Return>"),F(7,t,"start"+Re,X,Pe),F(7,t,"finish"+Re,X,Ae,de,"doRollback");const oe=G(Y,X);return q("Start"+Re,oe,ge+" just before the start of the "+ke,t,t,0),q("WillFinish"+Re,oe,ge+" just before "+Ee,t,t,0),q("DidFinish"+Re,oe,ge+" just after "+Ee,t,t,0),F(7,t,"call"+r,X,"Manually provoke a listener to be called","listenerId: Id","listenerId"),F(3,t,r,X,"Remove a listener that was previously added to "+xe,"listenerId: Id","listenerId"),B("getStore",t,"Store","store",at[0]+" the underlying Store object"),y(1,"tinybase","createStore"),y(1,K,X,`create${X} as create${X}Decl`,oe),x("store",["createStore()",...ee]),V("fluent","actions: () => Store",["actions();",`return ${Y};`]),V("proxy","listener: any",`(_: Store, ...params: any[]) => listener(${Y}, ...params)`),x(Y,["{",...z(1),"}"]),[s(...R(0),...k(),se+" interface "+X+" {",...z(0),"}",t,wt(`Creates a ${X} object`),se+" function create"+X+"(): "+X+";"),s(...R(1),se+" const create"+X+": typeof create"+X+"Decl = () => {",...P(),`return Object.freeze(${Y});`,"};"),ae,ne]},Gt=e=>s+e,Jt=e=>yt(Gt(e),Gt(e)+ne),zt="debugIds?: boolean",Wt="debugIds={debugIds}",Bt="then"+oe,Ft="Parameter",Ut=": (parameter: "+Ft+", store: Store) => ",_t="const contextValue = useContext(Context);",Zt=", based on a parameter",Ht=": ",Qt="<"+Ft+",>",qt=Ft+"ized"+le+"<"+Ft+">",Kt="rowId",Xt="rowId={rowId}",Yt=", separator, debugIds",el="separator?: ReactElement | string",tl="then?: (store: Store",ll=yt(tl+")"+Oe,Bt),al="then, then"+ne,nl=Kt+Ht+Ie,ol="View",dl=(e,...t)=>yt(...t,ie+": "+e,ie+oe,"mutator?: boolean"),rl=(...e)=>yt(...e,ie,ie+ne,"mutator"),sl=(e,l,a,n,o)=>{const[d,s,I,y,T,v,V,x]=Vt(),[R,k,P]=Dt(e,l,T),E=`./${gt(a)}.d`,D=`./${gt(a)}-ui-react.d`,O="tinybase/ui-react",N=gt(a,1),L=gt(N),M=N+"Or"+N+Ie,G=L+"Or"+N+Ie,J=L+`={${L}}`,z=U(),W=(e,l,a,n,o,d=t)=>(s(1,D,e+" as "+e+"Decl"),pt(z,e,[l,a,n,o,d])),B=(e,l,a,n,o,d=t)=>W("use"+e,l,a,n,o,d),F=(e,l,a,n,o=t,d=t,r=t,I=t,$=t)=>(s(1,O,`use${l} as use${l}Core`),B(e,yt(o,X,I),a,ne+`(${G}, use${l}Core, [`+(d||t)+($?"], ["+$:t)+"]);",n,r)),Z=(e,t,l,a)=>W(e,t,1,l,a),Q=(e=0)=>H(z,(([l,a,n,o,d],r)=>{const s=e?[se+` const ${r}: typeof ${r}Decl = ${d}(${l}): ${1==a?"any":a} =>`,n]:[se+` function ${r}${d}(${l}): ${1==a?"ComponentReturnType":a};`];return e||A(s,wt(o)),S(s,t),s}));s(null,"tinybase",Ie,"Store",le,Ft+"ized"+le),s(0,O,"ComponentReturnType"),s(null,O,"ExtraProps"),s(0,E,N);const q=I(M,N+" | "+Ie,`Used when you need to refer to a ${N} in a React hook or component`),K=I(me+he,vt(L+ue+N,L+`ById?: {[${L}Id: Id]: ${N}}`),`Used with the ${me} component, so that a `+N+" can be passed into the context of an application");s(0,"react","ReactElement","ComponentType"),s(1,"react","React"),s(1,D,q,K);const X=G+ue+q;T("{createContext, useContext, useMemo}","React"),T("Context",`createContext<[${N}?, {[${L}Id: Id]: ${N}}?]>([])`),B("Create"+N,`create: () => ${N}, create`+oe,N,"\n// eslint-disable-next-line react-hooks/exhaustive-deps\nuseMemo(create, createDeps)",`Create a ${N} within a React application with convenient memoization`);const ee=B(N,"id?: Id",N+pe,["{",_t,"return id == null ? contextValue[0] : contextValue[1]?.[id];","}"],`Get a reference to a ${N} from within a ${me} component context`),ne=y("useHook",G+`: ${q} | undefined, hook: (...params: any[]) => any, preParams: any[], postParams: any[] = []`,[`const ${L} = ${ee}(${G} as Id);`,`return hook(...preParams, ((${G} == null || typeof ${G} == 'string')`,`? ${L} : ${G})?.getStore(), ...postParams)`]),de=y("getProps","getProps: ((id: any) => ExtraProps) | undefined, id: Id","(getProps == null) ? ({} as ExtraProps) : getProps(id)"),re=y("wrap",yt("children: any","separator?: any","encloseWithId?: boolean","id?: Id"),["const separated = separator==null || !Array.isArray(children)"," ? children"," : children.map((child, c) => (c > 0 ? [separator, child] : child));","return encloseWithId ? [id, ':{', separated, '}'] : separated;"]),$e=T("NullComponent","() => null");if(!At(e)){const[e,l,a,o,d,g,f,w,T,v,V,x,S,P]=n;s(null,E,e,l,a,d,g,f,w,T,v,V,x,S),s(0,E,o),s(1,E,N),s(null,"tinybase",$,"IdOrNull");const A=y("tableView",`{${L}, rowComponent, getRowComponentProps`+Yt+"}: any, rowIds: Ids, tableId: Id, defaultRowComponent: React.ComponentType<any>",["const Row = rowComponent ?? defaultRowComponent;",`return ${re}(rowIds.map((rowId) => (`,"<Row","{..."+de+"(getRowComponentProps, rowId)}","key={rowId}","tableId={tableId}",Xt,J,Wt,"/>","))",Yt,", tableId,",");"]),O=y("getDefaultTableComponent","tableId: Id",ht(R(((e,t,l)=>`tableId == ${l} ? ${t}TableView : `)))+$e),M=y("getDefaultCellComponent","tableId: Id, cellId: Id",ht(R(((e,t,l)=>`tableId == ${l} ? ${ht(k(e,((e,l,a,n,o)=>`cellId == ${n} ? `+t+o+"CellView : ")))+$e} : `)))+$e);F(i,i,e,Be(1,0)+te);const G=F(u,u,a+Ve,Ue(c,xe)+te);F(Te+i+le,Te+i+le,qt,Be(1,9)+Zt,yt(Gt(i)+Ut+l,Gt(i)+oe),Jt(i),Qt,yt(tl,`tables: ${l})`+Oe,Bt),al),F(ae+i+le,ae+i+le,le,Be(1,12),t,t,t,ll,al);const z=I(h+he,vt("tableId?: TId","rowId: Id","cellId?: CId",L+ue+N,zt),Ze(Y+h),`<TId extends ${a}, CId extends ${o}<TId>>`),W=I(p+he,vt("tableId?: TId","rowId: Id",L+ue+N,"cellComponents?: {readonly [CId in "+o+`<TId>]?: ComponentType<${z}<TId, CId>>;}`,`getCellComponentProps?: (cellId: ${o}<TId>) => ExtraProps`,el,zt),Ze(Y+p),`<TId extends ${a}>`),B=I(c+he,vt("tableId?: TId",L+ue+N,`rowComponent?: ComponentType<${W}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps",el,zt),Ze(Y+c),`<TId extends ${a}>`),U=I("Sorted"+c+he,vt("tableId?: TId","cellId?: "+o+"<TId>","descending?: boolean","offset?: number","limit?: number",L+ue+N,`rowComponent?: ComponentType<${W}<TId>>`,"getRowComponentProps?: (rowId: Id) => ExtraProps",el,zt),Ze(Y+"sorted "+c),`<TId extends ${a}>`),H=I(i+he,vt(L+ue+N,"tableComponents?: {readonly [TId in "+a+`]?: ComponentType<${B}<TId>>;}`,`getTableComponentProps?: (tableId: ${a}) => ExtraProps`,el,zt),Ze(We(1,1)));s(1,D,H,B,U,W,z),Z(i+ol,"{"+L+", tableComponents, getTableComponentProps"+Yt+"}: "+H,[re+`(${G}(${L}).map((tableId) => {`,"const Table = (tableComponents?.[tableId] ?? "+O+"(tableId)) as React.ComponentType<TableProps<typeof tableId>>;","return <Table",`{...${de}(getTableComponentProps, tableId)}`,"tableId={tableId}","key={tableId}",J,Wt,"/>;","}), separator)"],Be(1,13)+te),R(((e,l,a)=>{const[n,o,d,r,I]=_(P,e);s(null,E,n,o,d,r,I),F(l+c,c,n,Ye(e)+te,t,a),F(l+c+m,c+m,$,Ue(h,"the whole of "+Ke(e))+te,t,a);const i=F(l+b,b,$,Ue(p,Ke(e))+te,t,a),u=F(l+C,C,$,Ue(p,Ke(e),1)+te,"cellId?: "+I+", descending?: boolean, offset?: number, limit?: number",a+", cellId, descending, offset, limit");F(l+p,p,d,et(e)+te,nl,yt(a,Kt));const g=F(l+m,m,I+Ve,Ue(h,Xe(e))+te,nl,yt(a,Kt));F(Te+l+c+le,Te+c+le,qt,Ye(e,9)+Zt,yt(Gt(c)+Ut+o,Gt(c)+oe),yt(a,Jt(c)),Qt,yt(tl,`table: ${o})`+Oe,Bt),al),F(ae+l+c+le,ae+c+le,le,Ye(e,12),t,a,t,ll,al),F(Te+l+p+le,Te+p+le,qt,et(e,9)+Zt,yt(nl,Gt(p)+Ut+r,Gt(p)+oe),yt(a,Kt,Jt(p)),Qt,yt(tl,`row: ${r})`+Oe,Bt),al),F("Add"+l+p+le,"Add"+p+le,qt,et(e,10)+Zt,yt(Gt(p)+Ut+r,Gt(p)+oe),yt(a,Jt(p)),Qt,"then?: ("+yt(nl+pe,"store: Store","row: "+r+")"+Oe,"then"+oe)+", reuseRowIds?: boolean",al+", reuseRowIds"),F(Te+l+Ce+p+le,Te+Ce+p+le,qt,et(e,11)+Zt,yt(nl,Gt(Ce+p)+Ut+r,Gt(Ce+p)+oe),yt(a,Kt,Jt(Ce+p)),Qt,yt(tl,`partialRow: ${r})`+Oe,Bt),al),F(ae+l+p+le,ae+p+le,le,et(e,12),nl,yt(a,Kt),t,ll,al);const f=Z(l+p+ol,"{rowId, "+L+", cellComponents, getCellComponentProps"+Yt+`}: ${W}<'${e}'>`,[re+`(${g}(rowId, ${L}).map((cellId) => {`,"const Cell = (cellComponents?.[cellId] ?? "+M+`(${a}, cellId)) as React.ComponentType<CellProps<typeof `+a+", typeof cellId>>;","return <Cell",`{...${de}(getCellComponentProps, cellId)} `,"key={cellId}",`tableId={${a}}`,Xt,"cellId={cellId}",J,Wt,"/>;","})"+Yt+", rowId)"],et(e,13)+te);Z(l+"Sorted"+c+ol,"{cellId, descending, offset, limit, ...props}: "+U+`<'${e}'>`,A+"(props, "+u+`(cellId, descending, offset, limit, props.${L}), ${a}, ${f});`,Ye(e,13)+", sorted"+te),Z(l+c+ol,`props: ${B}<'${e}'>`,A+"(props, "+i+`(props.${L}), ${a}, ${f});`,Ye(e,13)+te),k(e,((n,o,d,r,I)=>{const $="Map"+gt(o,1);s(0,E,$),s(1,E,$);const c=F(l+I+h,h,o+(j(d)?pe:t),tt(e,n)+te,nl,yt(a,Kt,r));F(Te+l+I+h+le,Te+h+le,qt,tt(e,n,9)+Zt,yt(nl,Gt(h)+Ut+o+" | "+$,Gt(h)+oe),yt(a,Kt,r,Jt(h)),Qt,yt(tl,`cell: ${o} | ${$})`+Oe,Bt),al),F(ae+l+I+h+le,ae+h+le,le,tt(e,n,12),yt(nl,"forceDel?: boolean"),yt(a,Kt,r,"forceDel"),t,ll,al),Z(l+I+h+ol,`{rowId, ${L}, debugIds}: `+z+`<'${e}', '${n}'>`,[re+`('' + ${c}(rowId, `+L+`) ?? '', undefined, debugIds, ${r})`],tt(e,n,13)+te)}))}));const Q=ht(R((e=>_(P,e)?.[4]??t))," | ");F(i+r,i+r,De,Be(1,8)+" changes",dl(d),rl()),F(u+r,u+r,De,qe(2,0,1),dl(g),rl()),F(c+r,c+r,De,qe(3,0),dl(f,`tableId: ${a} | null`),rl("tableId")),F(c+m+r,c+m+r,De,qe(14,3,1),dl(w,`tableId: ${a} | null`),rl("tableId")),F(b+r,b+r,De,qe(4,3,1),dl(T,`tableId: ${a} | null`),rl("tableId")),F(C+r,C+r,De,qe(13,3,1),dl(v,`tableId: ${a} | null`,"cellId: "+Q+pe,"descending: boolean","offset: number","limit: number"+pe),rl("tableId","cellId","descending","offset","limit")),F(p+r,p+r,De,qe(5,3),dl(V,`tableId: ${a} | null`,Kt+": IdOrNull"),rl("tableId",Kt)),F(m+r,m+r,De,qe(6,5,1),dl(x,`tableId: ${a} | null`,Kt+": IdOrNull"),rl("tableId",Kt)),F(h+r,h+r,De,qe(7,5),dl(S,`tableId: ${a} | null`,Kt+": IdOrNull",`cellId: ${Q} | null`),rl("tableId",Kt,"cellId"))}if(!At(l)){const[e,l,a,n,d,$]=o;s(null,E,...o),s(1,E,N);const c=y("getDefaultValueComponent","valueId: Id",ht(P(((e,t,l,a,n)=>`valueId == ${a} ? `+n+"ValueView : ")))+$e);F(f,f,e,Be(2,0)+te);const i=F(w,w,a+Ve,Ue(g,xe)+te);F(Te+f+le,Te+f+le,qt,Be(2,9)+Zt,yt(Gt(f)+Ut+l,Gt(f)+oe),Jt(f),Qt,yt(tl,`values: ${l})`+Oe,Bt),al),F(Te+Ce+f+le,Te+Ce+f+le,qt,Be(2,11)+Zt,yt(Gt(Ce+f)+Ut+l,Gt(Ce+f)+oe),Jt(Ce+f),Qt,yt(tl,`partialValues: ${l})`+Oe,Bt),al),F(ae+f+le,ae+f+le,le,Be(2,12),t,t,t,ll,al);const u=I(g+he,vt("valueId?: VId",L+ue+N,zt),Ze("a Value"),`<VId extends ${a}>`),p=I(f+he,vt(L+ue+N,"valueComponents?: {readonly [VId in "+a+`]?: ComponentType<${u}<VId>>;}`,`getValueComponentProps?: (valueId: ${a}) => ExtraProps`,el,zt),Ze(We(2,1)));s(1,D,p,u),Z(f+ol,"{"+L+", valueComponents, getValueComponentProps"+Yt+"}: "+p,[re+`(${i}(${L}).map((valueId) => {`,"const Value = valueComponents?.[valueId] ?? "+c+"(valueId);","return <Value",`{...${de}(getValueComponentProps, valueId)}`,"key={valueId}",J,Wt,"/>;","}), separator)"],Be(2,13)+te),P(((e,l,a,n,o)=>{const d="Map"+gt(l,1);s(0,E,d),s(1,E,d);const r=F(o+g,g,l,lt(e)+te,t,n);F(Te+o+g+le,Te+g+le,qt,lt(e,9)+Zt,yt(Gt(g)+Ut+l+" | "+d,Gt(g)+oe),yt(n,Jt(g)),Qt,yt(tl,`value: ${l} | ${d})`+Oe,Bt),al),F(ae+o+g+le,ae+g+le,le,lt(e,12),t,n,t,ll,al),Z(o+g+ol,`{${L}, debugIds}: ${u}<'${e}'>`,[re+`('' + ${r}(`+L+`) ?? '', undefined, debugIds, ${n})`],lt(e,13)+te)})),F(f+r,f+r,De,Be(2,8)+" changes",dl(n),rl()),F(w+r,w+r,De,qe(10,0,1),dl(d),rl()),F(g+r,g+r,De,qe(11,0),dl($,`valueId: ${a} | null`),rl("valueId"))}return Z(me,`{${L}, ${L}ById, children}: `+K+" & {children: React.ReactNode}",["{",_t,"return (","<Context."+me,"value={useMemo(",`() => [${L} ?? contextValue[0], {...contextValue[1], ...${L}ById}],`,`[${L}, ${L}ById, contextValue],`,")}>","{children}",`</Context.${me}>`,");","}"],"Wraps part of an application in a context that provides default objects to be used by hooks and components within"),[d(...v(0),...V(),...Q(0)),d(...v(1),...x(),...Q(1))]},Il=(e,l,a)=>{if(At(e)&&At(l))return[t,t,t,t];const[n,o,d,r]=Mt(e,l,a);return[n,o,...sl(e,l,a,d,r)]},$l={parser:"typescript",singleQuote:!0,trailingComma:"all",bracketSpacing:!1,jsdocSingleLineComment:!1},cl=Et((e=>{const t=()=>{const t=D(e.getTablesSchemaJson());return!At(t)||y(e.getTableIds(),(l=>{const a=e.getRowIds(l),n=U();if(y(a,(t=>y(e.getCellIds(l,t),(a=>{const o=e.getCell(l,t,a),d=q(n,a,(()=>[J(o),U(),[0],0])),[r,s,[I]]=d,$=q(s,o,(()=>0))+1;return $>I&&(d[2]=[$,o]),Q(s,o,$),d[3]++,r==J(o)})))))return t[l]={},B(n,(([e,,[,n],r],s)=>{t[l][s]={[o]:e,...r==x(a)?{[d]:n}:{}}})),1}))?t:{}},l=()=>{const t=D(e.getValuesSchemaJson());return At(t)&&e.forEachValue(((e,l)=>{t[e]={[o]:J(l)}})),t},a=e=>Il(t(),l(),e),n=async e=>{const t=["d.ts","ts","d.ts","tsx"];let l;try{l=(await import("prettier")).format}catch(e){l=e=>e}return V(a(e),((e,a)=>bt(l(e,{...$l,filepath:"_."+t[a]}))))};return kt({getStoreStats:t=>{let l=0,a=0,n=0;const o={};return e.forEachTable(((e,d)=>{l++;let r=0,s=0;const I={};d(((e,l)=>{r++;let a=0;l((()=>a++)),s+=a,t&&(I[e]={rowCells:a})})),a+=r,n+=s,t&&(o[e]={tableRows:r,tableCells:s,rows:I})})),{totalTables:l,totalRows:a,totalCells:n,totalValues:x(e.getValueIds()),jsonLength:Ct(e.getJson()),...t?{detail:{tables:o}}:{}}},getStoreTablesSchema:t,getStoreValuesSchema:l,getStoreApi:a,getPrettyStoreApi:n,getStore:()=>e})}));export{cl as createTools};
|
package/lib/tools.js.gz
CHANGED
|
Binary file
|
package/lib/types/store.d.ts
CHANGED
|
@@ -319,6 +319,20 @@ export type TableCallback = (
|
|
|
319
319
|
forEachRow: (rowCallback: RowCallback) => void,
|
|
320
320
|
) => void;
|
|
321
321
|
|
|
322
|
+
/**
|
|
323
|
+
* The TableCellCallback type describes a function that takes a Cell's Id and
|
|
324
|
+
* the count of times it appears across a whole Table.
|
|
325
|
+
*
|
|
326
|
+
* A TableCellCallback is provided when using the forEachTableCell method, so
|
|
327
|
+
* that you can do something based on every Cell used across a Table. See that
|
|
328
|
+
* method for specific examples.
|
|
329
|
+
*
|
|
330
|
+
* @param cellId The Id of the Cell that the callback can operate on.
|
|
331
|
+
* @param count The number of times this Cell is used across a whole Table.
|
|
332
|
+
* @category Callback
|
|
333
|
+
*/
|
|
334
|
+
export type TableCellCallback = (cellId: Id, count: number) => void;
|
|
335
|
+
|
|
322
336
|
/**
|
|
323
337
|
* The RowCallback type describes a function that takes a Row's Id and a
|
|
324
338
|
* callback to loop over each Cell within it.
|
|
@@ -498,10 +512,18 @@ export type TablesListener = (
|
|
|
498
512
|
*
|
|
499
513
|
* When called, a TableIdsListener is given a reference to the Store.
|
|
500
514
|
*
|
|
515
|
+
* Since v3.3, the listener is also passed a GetIdChanges function that can be
|
|
516
|
+
* used to query which Ids changed during the transaction.
|
|
517
|
+
*
|
|
501
518
|
* @param store A reference to the Store that changed.
|
|
519
|
+
* @param getIdChanges A function that returns information about the Id changes,
|
|
520
|
+
* since v3.3.
|
|
502
521
|
* @category Listener
|
|
503
522
|
*/
|
|
504
|
-
export type TableIdsListener = (
|
|
523
|
+
export type TableIdsListener = (
|
|
524
|
+
store: Store,
|
|
525
|
+
getIdChanges: GetIdChanges | undefined,
|
|
526
|
+
) => void;
|
|
505
527
|
|
|
506
528
|
/**
|
|
507
529
|
* The TableListener type describes a function that is used to listen to changes
|
|
@@ -530,6 +552,29 @@ export type TableListener = (
|
|
|
530
552
|
getCellChange: GetCellChange | undefined,
|
|
531
553
|
) => void;
|
|
532
554
|
|
|
555
|
+
/**
|
|
556
|
+
* The TableCellIdsListener type describes a function that is used to listen to
|
|
557
|
+
* changes to the Cell Ids that appear anywhere in a Table.
|
|
558
|
+
*
|
|
559
|
+
* A TableCellIdsListener is provided when using the addTableCellIdsListener
|
|
560
|
+
* method. See that method for specific examples.
|
|
561
|
+
*
|
|
562
|
+
* When called, a TableCellIdsListener is given a reference to the Store, the Id
|
|
563
|
+
* of the Table whose Cell Ids changed, and a GetIdChanges function that can be
|
|
564
|
+
* used to query which Ids changed during the transaction.
|
|
565
|
+
*
|
|
566
|
+
* @param store A reference to the Store that changed.
|
|
567
|
+
* @param tableId The Id of the Table that changed.
|
|
568
|
+
* @param getIdChanges A function that returns information about the Id changes.
|
|
569
|
+
* @category Listener
|
|
570
|
+
* @since v3.3
|
|
571
|
+
*/
|
|
572
|
+
export type TableCellIdsListener = (
|
|
573
|
+
store: Store,
|
|
574
|
+
tableId: Id,
|
|
575
|
+
getIdChanges: GetIdChanges | undefined,
|
|
576
|
+
) => void;
|
|
577
|
+
|
|
533
578
|
/**
|
|
534
579
|
* The RowIdsListener type describes a function that is used to listen to
|
|
535
580
|
* changes to the Row Ids in a Table.
|
|
@@ -540,11 +585,20 @@ export type TableListener = (
|
|
|
540
585
|
* When called, a RowIdsListener is given a reference to the Store, and the Id
|
|
541
586
|
* of the Table whose Row Ids changed.
|
|
542
587
|
*
|
|
588
|
+
* Since v3.3, the listener is also passed a GetIdChanges function that can be
|
|
589
|
+
* used to query which Ids changed during the transaction.
|
|
590
|
+
*
|
|
543
591
|
* @param store A reference to the Store that changed.
|
|
544
592
|
* @param tableId The Id of the Table that changed.
|
|
593
|
+
* @param getIdChanges A function that returns information about the Id changes,
|
|
594
|
+
* since v3.3.
|
|
545
595
|
* @category Listener
|
|
546
596
|
*/
|
|
547
|
-
export type RowIdsListener = (
|
|
597
|
+
export type RowIdsListener = (
|
|
598
|
+
store: Store,
|
|
599
|
+
tableId: Id,
|
|
600
|
+
getIdChanges: GetIdChanges | undefined,
|
|
601
|
+
) => void;
|
|
548
602
|
|
|
549
603
|
/**
|
|
550
604
|
* The SortedRowIdsListener type describes a function that is used to listen to
|
|
@@ -620,12 +674,22 @@ export type RowListener = (
|
|
|
620
674
|
* When called, a CellIdsListener is given a reference to the Store, the Id of
|
|
621
675
|
* the Table that changed, and the Id of the Row whose Cell Ids changed.
|
|
622
676
|
*
|
|
677
|
+
* Since v3.3, the listener is also passed a GetIdChanges function that can be
|
|
678
|
+
* used to query which Ids changed during the transaction.
|
|
679
|
+
*
|
|
623
680
|
* @param store A reference to the Store that changed.
|
|
624
681
|
* @param tableId The Id of the Table that changed.
|
|
625
682
|
* @param rowId The Id of the Row that changed.
|
|
683
|
+
* @param getIdChanges A function that returns information about the Id changes,
|
|
684
|
+
* since v3.3.
|
|
626
685
|
* @category Listener
|
|
627
686
|
*/
|
|
628
|
-
export type CellIdsListener = (
|
|
687
|
+
export type CellIdsListener = (
|
|
688
|
+
store: Store,
|
|
689
|
+
tableId: Id,
|
|
690
|
+
rowId: Id,
|
|
691
|
+
getIdChanges: GetIdChanges | undefined,
|
|
692
|
+
) => void;
|
|
629
693
|
|
|
630
694
|
/**
|
|
631
695
|
* The CellListener type describes a function that is used to listen to changes
|
|
@@ -699,10 +763,18 @@ export type ValuesListener = (
|
|
|
699
763
|
*
|
|
700
764
|
* When called, a ValueIdsListener is given a reference to the Store.
|
|
701
765
|
*
|
|
766
|
+
* Since v3.3, the listener is also passed a GetIdChanges function that can be
|
|
767
|
+
* used to query which Ids changed during the transaction.
|
|
768
|
+
*
|
|
702
769
|
* @param store A reference to the Store that changed.
|
|
770
|
+
* @param getIdChanges A function that returns information about the Id changes,
|
|
771
|
+
* since v3.3.
|
|
703
772
|
* @category Listener
|
|
704
773
|
*/
|
|
705
|
-
export type ValueIdsListener = (
|
|
774
|
+
export type ValueIdsListener = (
|
|
775
|
+
store: Store,
|
|
776
|
+
getIdChanges: GetIdChanges | undefined,
|
|
777
|
+
) => void;
|
|
706
778
|
|
|
707
779
|
/**
|
|
708
780
|
* The ValueListener type describes a function that is used to listen to changes
|
|
@@ -794,6 +866,23 @@ export type InvalidValueListener = (
|
|
|
794
866
|
invalidValues: any[],
|
|
795
867
|
) => void;
|
|
796
868
|
|
|
869
|
+
/**
|
|
870
|
+
* The GetIdChanges type describes a function that returns information about the
|
|
871
|
+
* changes to a set of Ids during a transaction.
|
|
872
|
+
*
|
|
873
|
+
* A GetIdChanges function is provided to every listener when called due Ids in
|
|
874
|
+
* the Store changing. It returns an object where each key is an Id that
|
|
875
|
+
* changed. The listener can then easily identify which Ids have been added
|
|
876
|
+
* (those with the value `1`), and which have been removed (those with the value
|
|
877
|
+
* `-1`).
|
|
878
|
+
*
|
|
879
|
+
* @returns An object keyed by Id with a numerical value. 1 means the Id was
|
|
880
|
+
* added, and 1 means it was removed.
|
|
881
|
+
* @category Listener
|
|
882
|
+
* @since v3.3
|
|
883
|
+
*/
|
|
884
|
+
export type GetIdChanges = () => {[id: Id]: 1 | -1};
|
|
885
|
+
|
|
797
886
|
/**
|
|
798
887
|
* The GetCellChange type describes a function that returns information about
|
|
799
888
|
* any Cell's changes during a transaction.
|
|
@@ -989,6 +1078,11 @@ export type StoreListenerStats = {
|
|
|
989
1078
|
* The number of TableListener functions registered with the Store.
|
|
990
1079
|
*/
|
|
991
1080
|
table?: number;
|
|
1081
|
+
/**
|
|
1082
|
+
* The number of TableCellIdsListener functions registered with the Store,
|
|
1083
|
+
* since v3.3.
|
|
1084
|
+
*/
|
|
1085
|
+
tableCellIds?: number;
|
|
992
1086
|
/**
|
|
993
1087
|
* The number of RowIdsListener functions registered with the Store.
|
|
994
1088
|
*/
|
|
@@ -1129,6 +1223,7 @@ export type StoreListenerStats = {
|
|
|
1129
1223
|
* |Tables|getTables|setTables|delTables|addTablesListener|
|
|
1130
1224
|
* |Table Ids|getTableIds|-|-|addTableIdsListener|
|
|
1131
1225
|
* |Table|getTable|setTable|delTable|addTableListener|
|
|
1226
|
+
* |Table Cell Ids|getTableCellIds|-|-|addTableCellIdsListener|
|
|
1132
1227
|
* |Row Ids|getRowIds|-|-|addRowIdsListener|
|
|
1133
1228
|
* |Row Ids (sorted)|getSortedRowIds|-|-|addSortedRowIdsListener|
|
|
1134
1229
|
* |Row|getRow|setRow|delRow|addRowListener|
|
|
@@ -1318,6 +1413,43 @@ export interface Store {
|
|
|
1318
1413
|
*/
|
|
1319
1414
|
getTable(tableId: Id): Table;
|
|
1320
1415
|
|
|
1416
|
+
/**
|
|
1417
|
+
* The getTableCellIds method returns the Ids of every Cell used across the
|
|
1418
|
+
* whole Table.
|
|
1419
|
+
*
|
|
1420
|
+
* Note that this returns a copy of, rather than a reference, to the list of
|
|
1421
|
+
* Ids, so changes made to the list are not made to the Store itself.
|
|
1422
|
+
*
|
|
1423
|
+
* @param tableId The Id of the Table in the Store.
|
|
1424
|
+
* @returns An array of the Ids of every Cell used across the whole Table.
|
|
1425
|
+
* @example
|
|
1426
|
+
* This example retrieves the Cell Ids used across a whole Table.
|
|
1427
|
+
*
|
|
1428
|
+
* ```js
|
|
1429
|
+
* const store = createStore().setTables({
|
|
1430
|
+
* pets: {
|
|
1431
|
+
* fido: {species: 'dog', color: 'brown'},
|
|
1432
|
+
* felix: {species: 'cat', legs: 4},
|
|
1433
|
+
* cujo: {dangerous: true},
|
|
1434
|
+
* },
|
|
1435
|
+
* });
|
|
1436
|
+
* console.log(store.getTableCellIds('pets'));
|
|
1437
|
+
* // -> ['species', 'color', 'legs', 'dangerous']
|
|
1438
|
+
* ```
|
|
1439
|
+
* @example
|
|
1440
|
+
* This example retrieves the Cell Ids used across a Table that does not
|
|
1441
|
+
* exist, returning an empty array.
|
|
1442
|
+
*
|
|
1443
|
+
* ```js
|
|
1444
|
+
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
1445
|
+
* console.log(store.getTableCellIds('species'));
|
|
1446
|
+
* // -> []
|
|
1447
|
+
* ```
|
|
1448
|
+
* @category Getter
|
|
1449
|
+
* @since v3.3
|
|
1450
|
+
*/
|
|
1451
|
+
getTableCellIds(tableId: Id): Ids;
|
|
1452
|
+
|
|
1321
1453
|
/**
|
|
1322
1454
|
* The getRowIds method returns the Ids of every Row in a given Table.
|
|
1323
1455
|
*
|
|
@@ -1497,7 +1629,7 @@ export interface Store {
|
|
|
1497
1629
|
getRow(tableId: Id, rowId: Id): Row;
|
|
1498
1630
|
|
|
1499
1631
|
/**
|
|
1500
|
-
* The getCellIds method returns the Ids of every Cell in a given Row
|
|
1632
|
+
* The getCellIds method returns the Ids of every Cell in a given Row in a
|
|
1501
1633
|
* given Table.
|
|
1502
1634
|
*
|
|
1503
1635
|
* Note that this returns a copy of, rather than a reference, to the list of
|
|
@@ -1519,8 +1651,8 @@ export interface Store {
|
|
|
1519
1651
|
* // -> ['species', 'color']
|
|
1520
1652
|
* ```
|
|
1521
1653
|
* @example
|
|
1522
|
-
* This example retrieves the Cell Ids of a
|
|
1523
|
-
*
|
|
1654
|
+
* This example retrieves the Cell Ids of a Row that does not exist, returning
|
|
1655
|
+
* an empty array.
|
|
1524
1656
|
*
|
|
1525
1657
|
* ```js
|
|
1526
1658
|
* const store = createStore().setTables({pets: {fido: {species: 'dog'}}});
|
|
@@ -1687,6 +1819,32 @@ export interface Store {
|
|
|
1687
1819
|
*/
|
|
1688
1820
|
hasTable(tableId: Id): boolean;
|
|
1689
1821
|
|
|
1822
|
+
/**
|
|
1823
|
+
* The hasTableCell method returns a boolean indicating whether a given Cell
|
|
1824
|
+
* exists anywhere in a Table, not just in a specific Row.
|
|
1825
|
+
*
|
|
1826
|
+
* @param tableId The Id of a possible Table in the Store.
|
|
1827
|
+
* @param cellId The Id of a possible Cell in the Table.
|
|
1828
|
+
* @returns Whether a Cell with that Id exists anywhere in that Table.
|
|
1829
|
+
* @example
|
|
1830
|
+
* This example shows two simple Cell existence checks.
|
|
1831
|
+
*
|
|
1832
|
+
* ```js
|
|
1833
|
+
* const store = createStore().setTables({
|
|
1834
|
+
* pets: {fido: {species: 'dog'}, felix: {legs: 4}},
|
|
1835
|
+
* });
|
|
1836
|
+
* console.log(store.hasTableCell('pets', 'species'));
|
|
1837
|
+
* // -> true
|
|
1838
|
+
* console.log(store.hasTableCell('pets', 'legs'));
|
|
1839
|
+
* // -> true
|
|
1840
|
+
* console.log(store.hasTableCell('pets', 'color'));
|
|
1841
|
+
* // -> false
|
|
1842
|
+
* ```
|
|
1843
|
+
* @category Getter
|
|
1844
|
+
* @since v3.3
|
|
1845
|
+
*/
|
|
1846
|
+
hasTableCell(tableId: Id, cellId: Id): boolean;
|
|
1847
|
+
|
|
1690
1848
|
/**
|
|
1691
1849
|
* The hasRow method returns a boolean indicating whether a given Row exists
|
|
1692
1850
|
* in the Store.
|
|
@@ -1710,7 +1868,7 @@ export interface Store {
|
|
|
1710
1868
|
|
|
1711
1869
|
/**
|
|
1712
1870
|
* The hasCell method returns a boolean indicating whether a given Cell exists
|
|
1713
|
-
* in
|
|
1871
|
+
* in a given Row in a given Table.
|
|
1714
1872
|
*
|
|
1715
1873
|
* @param tableId The Id of a possible Table in the Store.
|
|
1716
1874
|
* @param rowId The Id of a possible Row in the Table.
|
|
@@ -3291,6 +3449,36 @@ export interface Store {
|
|
|
3291
3449
|
*/
|
|
3292
3450
|
forEachTable(tableCallback: TableCallback): void;
|
|
3293
3451
|
|
|
3452
|
+
/**
|
|
3453
|
+
* The forEachTableCell method takes a function that it will then call for
|
|
3454
|
+
* each Cell used across the whole Table.
|
|
3455
|
+
*
|
|
3456
|
+
* This method is useful for iterating over the Cell structure of the Table in
|
|
3457
|
+
* a functional style. The `tableCellCallback` parameter is a
|
|
3458
|
+
* TableCellCallback function that will be called with the Id of each Cell and
|
|
3459
|
+
* the count of Rows in the Table in which it appears.
|
|
3460
|
+
*
|
|
3461
|
+
* @param tableId The Id of the Table containing the Cells to iterate over.
|
|
3462
|
+
* @param tableCellCallback The function that should be called for every Cell
|
|
3463
|
+
* Id used across the whole Table.
|
|
3464
|
+
* @example
|
|
3465
|
+
* This example iterates over each Cell Id used across the whole Table.
|
|
3466
|
+
*
|
|
3467
|
+
* ```js
|
|
3468
|
+
* const store = createStore().setTables({
|
|
3469
|
+
* pets: {fido: {species: 'dog'}, felix: {species: 'cat', legs: 4}},
|
|
3470
|
+
* });
|
|
3471
|
+
* store.forEachTableCell('pets', (cellId, count) => {
|
|
3472
|
+
* console.log(`${cellId}: ${count}`);
|
|
3473
|
+
* });
|
|
3474
|
+
* // -> 'species: 2'
|
|
3475
|
+
* // -> 'legs: 1'
|
|
3476
|
+
* ```
|
|
3477
|
+
* @category Iterator
|
|
3478
|
+
* @since v3.3
|
|
3479
|
+
*/
|
|
3480
|
+
forEachTableCell(tableId: Id, tableCellCallback: TableCellCallback): void;
|
|
3481
|
+
|
|
3294
3482
|
/**
|
|
3295
3483
|
* The forEachRow method takes a function that it will then call for each Row
|
|
3296
3484
|
* in a specified Table.
|
|
@@ -3603,6 +3791,111 @@ export interface Store {
|
|
|
3603
3791
|
mutator?: boolean,
|
|
3604
3792
|
): Id;
|
|
3605
3793
|
|
|
3794
|
+
/**
|
|
3795
|
+
* The addTableCellIdsListener method registers a listener function with the
|
|
3796
|
+
* Store that will be called whenever the Cell Ids that appear anywhere in a
|
|
3797
|
+
* Table change.
|
|
3798
|
+
*
|
|
3799
|
+
* The provided listener is a TableCellIdsListener function, and will be
|
|
3800
|
+
* called with a reference to the Store and the Id of the Table that changed.
|
|
3801
|
+
*
|
|
3802
|
+
* By default, such a listener is only called when a Cell Id is added or
|
|
3803
|
+
* removed from the whole of the Table. To listen to all changes in the Table,
|
|
3804
|
+
* use the addTableListener method.
|
|
3805
|
+
*
|
|
3806
|
+
* You can either listen to a single Table (by specifying its Id as the
|
|
3807
|
+
* method's first parameter) or changes to any Table (by providing a `null`
|
|
3808
|
+
* wildcard).
|
|
3809
|
+
*
|
|
3810
|
+
* Use the optional mutator parameter to indicate that there is code in the
|
|
3811
|
+
* listener that will mutate Store data. If set to `false` (or omitted), such
|
|
3812
|
+
* mutations will be silently ignored. All relevant mutator listeners (with
|
|
3813
|
+
* this flag set to `true`) are called _before_ any non-mutator listeners
|
|
3814
|
+
* (since the latter may become relevant due to changes made in the former).
|
|
3815
|
+
* The changes made by mutator listeners do not fire other mutating listeners,
|
|
3816
|
+
* though they will fire non-mutator listeners.
|
|
3817
|
+
*
|
|
3818
|
+
* @param tableId The Id of the Table to listen to, or `null` as a wildcard.
|
|
3819
|
+
* @param listener The function that will be called whenever the Cell Ids that
|
|
3820
|
+
* appear anywhere in a Table change.
|
|
3821
|
+
* @param mutator An optional boolean that indicates that the listener mutates
|
|
3822
|
+
* Store data.
|
|
3823
|
+
* @returns A unique Id for the listener that can later be used to call it
|
|
3824
|
+
* explicitly, or to remove it.
|
|
3825
|
+
* @example
|
|
3826
|
+
* This example registers a listener that responds to any change to the Cell
|
|
3827
|
+
* Ids that appear anywhere in a Table.
|
|
3828
|
+
*
|
|
3829
|
+
* ```js
|
|
3830
|
+
* const store = createStore().setTables({
|
|
3831
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
3832
|
+
* });
|
|
3833
|
+
* const listenerId = store.addTableCellIdsListener('pets', (store) => {
|
|
3834
|
+
* console.log('Cell Ids in pets table changed');
|
|
3835
|
+
* console.log(store.getTableCellIds('pets'));
|
|
3836
|
+
* });
|
|
3837
|
+
*
|
|
3838
|
+
* store.setRow('pets', 'felix', {species: 'cat', legs: 4});
|
|
3839
|
+
* // -> 'Cell Ids in pets table changed'
|
|
3840
|
+
* // -> ['species', 'color', 'legs']
|
|
3841
|
+
*
|
|
3842
|
+
* store.delListener(listenerId);
|
|
3843
|
+
* ```
|
|
3844
|
+
* @example
|
|
3845
|
+
* This example registers a listener that responds to any change to the Cell
|
|
3846
|
+
* Ids that appear anywhere in any Table.
|
|
3847
|
+
*
|
|
3848
|
+
* ```js
|
|
3849
|
+
* const store = createStore().setTables({
|
|
3850
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
3851
|
+
* species: {dog: {price: 5}},
|
|
3852
|
+
* });
|
|
3853
|
+
* const listenerId = store.addTableCellIdsListener(
|
|
3854
|
+
* null,
|
|
3855
|
+
* (store, tableId) => {
|
|
3856
|
+
* console.log(`Cell Ids in ${tableId} table changed`);
|
|
3857
|
+
* console.log(store.getTableCellIds(tableId));
|
|
3858
|
+
* },
|
|
3859
|
+
* );
|
|
3860
|
+
*
|
|
3861
|
+
* store.setRow('pets', 'felix', {species: 'cat', legs: 4});
|
|
3862
|
+
* // -> 'Cell Ids in pets table changed'
|
|
3863
|
+
* // -> ['species', 'color', 'legs']
|
|
3864
|
+
*
|
|
3865
|
+
* store.setRow('species', 'cat', {price: 4, friendly: true});
|
|
3866
|
+
* // -> 'Cell Ids in species table changed'
|
|
3867
|
+
* // -> ['price', 'friendly']
|
|
3868
|
+
*
|
|
3869
|
+
* store.delListener(listenerId);
|
|
3870
|
+
* ```
|
|
3871
|
+
* @example
|
|
3872
|
+
* This example registers a listener that responds to the Cell Ids that appear
|
|
3873
|
+
* anywhere in a Table, and which also mutates the Store itself.
|
|
3874
|
+
*
|
|
3875
|
+
* ```js
|
|
3876
|
+
* const store = createStore().setTables({
|
|
3877
|
+
* pets: {fido: {species: 'dog', color: 'brown'}},
|
|
3878
|
+
* });
|
|
3879
|
+
* const listenerId = store.addTableCellIdsListener(
|
|
3880
|
+
* 'pets',
|
|
3881
|
+
* (store, tableId) => store.setCell('meta', 'update', tableId, true),
|
|
3882
|
+
* true, // mutator
|
|
3883
|
+
* );
|
|
3884
|
+
*
|
|
3885
|
+
* store.setRow('pets', 'felix', {species: 'cat', legs: 4});
|
|
3886
|
+
* console.log(store.getTable('meta'));
|
|
3887
|
+
* // -> {update: {pets: true}}
|
|
3888
|
+
*
|
|
3889
|
+
* store.delListener(listenerId);
|
|
3890
|
+
* ```
|
|
3891
|
+
* @category Listener
|
|
3892
|
+
*/
|
|
3893
|
+
addTableCellIdsListener(
|
|
3894
|
+
tableId: IdOrNull,
|
|
3895
|
+
listener: TableCellIdsListener,
|
|
3896
|
+
mutator?: boolean,
|
|
3897
|
+
): Id;
|
|
3898
|
+
|
|
3606
3899
|
/**
|
|
3607
3900
|
* The addRowIdsListener method registers a listener function with the Store
|
|
3608
3901
|
* that will be called whenever the Row Ids in a Table change.
|
|
@@ -3777,7 +4070,7 @@ export interface Store {
|
|
|
3777
4070
|
* store.delListener(listenerId);
|
|
3778
4071
|
* ```
|
|
3779
4072
|
* @example
|
|
3780
|
-
* This
|
|
4073
|
+
* This example registers a listener that responds to any change to a
|
|
3781
4074
|
* paginated section of the sorted Row Ids of a specific Table.
|
|
3782
4075
|
*
|
|
3783
4076
|
* ```js
|
package/lib/types/tools.d.ts
CHANGED
|
@@ -433,7 +433,7 @@ export interface Tools {
|
|
|
433
433
|
* // -> `export type Tables = {pets?: {[rowId: Id]: {price?: number}}};`
|
|
434
434
|
*
|
|
435
435
|
* const tsLines = ts.split('\n');
|
|
436
|
-
* console.log(tsLines[
|
|
436
|
+
* console.log(tsLines[81]);
|
|
437
437
|
* // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
|
|
438
438
|
* ```
|
|
439
439
|
* @example
|
|
@@ -454,7 +454,7 @@ export interface Tools {
|
|
|
454
454
|
* // -> 'export type Tables = {pets?: {[rowId: Id]: {price: number}}};'
|
|
455
455
|
*
|
|
456
456
|
* const tsLines = ts.split('\n');
|
|
457
|
-
* console.log(tsLines[
|
|
457
|
+
* console.log(tsLines[83]);
|
|
458
458
|
* // -> ' hasPetsTable: (): boolean => store.hasTable(PETS),'
|
|
459
459
|
* ```
|
|
460
460
|
* @category Modelling
|