tinybase 4.3.10 → 4.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/persisters/persister-partykit-client.cjs +1 -1
- package/lib/cjs/persisters/persister-partykit-client.cjs.gz +0 -0
- package/lib/cjs/persisters/persister-partykit-server.cjs +1 -1
- package/lib/cjs/persisters/persister-partykit-server.cjs.gz +0 -0
- package/lib/cjs/ui-react-dom-debug.cjs +1 -1
- package/lib/cjs/ui-react-dom-debug.cjs.gz +0 -0
- package/lib/cjs/ui-react-dom.cjs +1 -1
- package/lib/cjs/ui-react-dom.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-partykit-client.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-partykit-client.cjs.gz +0 -0
- package/lib/cjs-es6/persisters/persister-partykit-server.cjs +1 -1
- package/lib/cjs-es6/persisters/persister-partykit-server.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react-dom-debug.cjs +1 -1
- package/lib/cjs-es6/ui-react-dom-debug.cjs.gz +0 -0
- package/lib/cjs-es6/ui-react-dom.cjs +1 -1
- package/lib/cjs-es6/ui-react-dom.cjs.gz +0 -0
- package/lib/debug/persisters/persister-partykit-client.js +29 -19
- package/lib/debug/persisters/persister-partykit-server.js +155 -64
- package/lib/debug/ui-react-dom.js +45 -30
- package/lib/es6/persisters/persister-partykit-client.js +1 -1
- package/lib/es6/persisters/persister-partykit-client.js.gz +0 -0
- package/lib/es6/persisters/persister-partykit-server.js +1 -1
- package/lib/es6/persisters/persister-partykit-server.js.gz +0 -0
- package/lib/es6/ui-react-dom-debug.js +1 -1
- package/lib/es6/ui-react-dom-debug.js.gz +0 -0
- package/lib/es6/ui-react-dom.js +1 -1
- package/lib/es6/ui-react-dom.js.gz +0 -0
- package/lib/persisters/persister-partykit-client.js +1 -1
- package/lib/persisters/persister-partykit-client.js.gz +0 -0
- package/lib/persisters/persister-partykit-server.js +1 -1
- package/lib/persisters/persister-partykit-server.js.gz +0 -0
- package/lib/types/persisters/persister-indexed-db.d.ts +4 -5
- package/lib/types/persisters/persister-partykit-client.d.ts +18 -7
- package/lib/types/persisters/persister-partykit-server.d.ts +335 -7
- package/lib/types/tools.d.ts +4 -6
- package/lib/types/ui-react-dom.d.ts +13 -2
- package/lib/types/ui-react.d.ts +4 -4
- package/lib/types/with-schemas/persisters/persister-indexed-db.d.ts +4 -5
- package/lib/types/with-schemas/persisters/persister-partykit-client.d.ts +18 -7
- package/lib/types/with-schemas/persisters/persister-partykit-server.d.ts +359 -7
- package/lib/types/with-schemas/tools.d.ts +4 -6
- package/lib/types/with-schemas/ui-react-dom.d.ts +21 -4
- package/lib/types/with-schemas/ui-react.d.ts +4 -4
- package/lib/ui-react-dom.js +1 -1
- package/lib/ui-react-dom.js.gz +0 -0
- package/lib/umd/persisters/persister-partykit-client.js +1 -1
- package/lib/umd/persisters/persister-partykit-client.js.gz +0 -0
- package/lib/umd/persisters/persister-partykit-server.js +1 -1
- package/lib/umd/persisters/persister-partykit-server.js.gz +0 -0
- package/lib/umd/ui-react-dom-debug.js +1 -1
- package/lib/umd/ui-react-dom-debug.js.gz +0 -0
- package/lib/umd/ui-react-dom.js +1 -1
- package/lib/umd/ui-react-dom.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-partykit-client.js +1 -1
- package/lib/umd-es6/persisters/persister-partykit-client.js.gz +0 -0
- package/lib/umd-es6/persisters/persister-partykit-server.js +1 -1
- package/lib/umd-es6/persisters/persister-partykit-server.js.gz +0 -0
- package/lib/umd-es6/ui-react-dom-debug.js +1 -1
- package/lib/umd-es6/ui-react-dom-debug.js.gz +0 -0
- package/lib/umd-es6/ui-react-dom.js +1 -1
- package/lib/umd-es6/ui-react-dom.js.gz +0 -0
- package/package.json +10 -10
- package/readme.md +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("react"),t=require("./ui-react");const l=e=>typeof e,r=l(""),o=l(!0),a=l(0),n="Value",s="currentTarget",i="value",d=isFinite,u=e=>null==e,{PureComponent:c,Fragment:m,createElement:h,useCallback:b,useLayoutEffect:p,useRef:g,useState:f}=e,w=(e,...t)=>u(e)?{}:e(...t),v=(e,t)=>e.map(t),I=Object,C=(e=[])=>I.fromEntries(e),y=(e,t)=>v(I.entries(e),(([e,l])=>t(l,e))),x="M20 80l5-15l40-40l10 10l-40 40l-15 5m5-15l10 10",k='content:url("',O=k+"data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' stroke-width='4' stroke='white' fill='none'>",R='</svg>")',S=k+"data:image/svg+xml,%3csvg viewBox='0 0 680 680' xmlns='http://www.w3.org/2000/svg' style='width:680px%3bheight:680px'%3e %3cpath stroke='white' stroke-width='80' fill='none' d='M340 617a84 241 90 11.01 0zM131 475a94 254 70 10428-124 114 286 70 01-428 124zm0-140a94 254 70 10428-124 114 286 70 01-428 124zm-12-127a94 254 70 00306 38 90 260 90 01-306-38zm221 3a74 241 90 11.01 0z' /%3e %3cpath fill='%23d81b60' d='M131 475a94 254 70 10428-124 114 286 70 01-428 124zm0-140a94 254 70 10428-124 114 286 70 01-428 124z' /%3e %3cpath d='M249 619a94 240 90 00308-128 114 289 70 01-308 128zM119 208a94 254 70 00306 38 90 260 90 01-306-38zm221 3a74 241 90 11.01 0z' /%3e%3c/svg%3e\")",T=v([[20,20,20,60],[20,20,60,20],[20,60,60,20],[60,20,20,60],[30,30,40,40]],(([e,t,l,r])=>O+`<rect x='20' y='20' width='60' height='60' fill='grey'/><rect x='${e}' y='${t}' width='${l}' height='${r}' fill='white'/>`+R)),N=O+"<path d='M20 20l60 60M20 80l60-60' />"+R,V=O+`<path d='${x}' />`+R,P=O+`<path d='${x}M20 20l60 60' />`+R;var j=Object.defineProperty,z=Object.defineProperties,q=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,$=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable,F=(e,t,l)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[t]=l,H=(e,t)=>{for(var l in t||(t={}))$.call(t,l)&&F(e,l,t[l]);if(M)for(var l of M(t))E.call(t,l)&&F(e,l,t[l]);return e},B=(e,t)=>z(e,q(t));const D="*::-webkit-scrollbar";((e,t="")=>{e.join(t)})(y(B(H(B(H(B(H({"*":"all:revert","*::before":"all:revert","*::after":"all:revert",[D]:"width:0.5rem;height:0.5rem;",[D+"-track"]:"background:#111",[D+"-thumb"]:"background:#999;border:1px solid #111",[D+"-thumb:hover"]:"background:#fff",[D+"-corner"]:"background:#111",img:"width:1rem;height:1rem;background:#111;border:0;vertical-align:text-bottom",">img":"padding:0.25rem;bottom:0;right:0;position:fixed;"+S},C(v(["bottom:0;left:0","top:0;right:0"],((e,t)=>[`>img[data-position='${t}']`,e])))),{main:"display:flex;flex-direction:column;background:#111d;color:#fff;position:fixed;"}),C(v(["bottom:0;left:0;width:35vw;height:100vh","top:0;right:0;width:100vw;height:30vh","bottom:0;left:0;width:100vw;height:30vh","top:0;right:0;width:35vw;height:100vh","top:0;right:0;width:100vw;height:100vh"],((e,t)=>[`main[data-position='${t}']`,e])))),{header:"display:flex;padding:0.25rem;background:#000;align-items:center","header>img:nth-of-type(1)":S,"header>img:nth-of-type(6)":N}),C(v(T,((e,t)=>[`header>img[data-id='${t}']`,e])))),{"header>span":"flex:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;margin-left:0.25rem",article:"padding:0.25rem 0.25rem 0.25rem 0.5rem;overflow:auto;flex:1",details:"margin-left:0.75rem;width:fit-content;","details img":"display:none","details[open]>summary img":"display:unset;background:none;margin-left:0.25rem","details[open]>summary img.edit":V,"details[open]>summary img.done":P,summary:"margin-left:-0.75rem;line-height:1.25rem;user-select:none;width:fit-content",table:"border-collapse:collapse;table-layout:fixed;margin-bottom:0.5rem","table input":"background:#111;color:unset;padding:0 0.25rem;border:0;font-size:unset;vertical-align:top;margin:0",'table input[type="number"]':"width:4rem","table tbody button":"font-size:0;background:#fff;border-radius:50%;margin:0 0.125rem 0 0;width:0.85rem;color:#111","table button:first-letter":"font-size:0.75rem",thead:"background:#222","th:nth-of-type(1)":"min-width:2rem;","th.sorted":"background:#000","table caption":"text-align:left;white-space:nowrap;line-height:1.25rem",button:"width:1.5rem;border:none;background:none;color:#fff;padding:0","button[disabled]":"color:#777","button.next":"margin-right:0.5rem","th,td":"overflow:hidden;text-overflow:ellipsis;padding:0.25rem 0.5rem;max-width:12rem;white-space:nowrap;border-width:1px 0;border-style:solid;border-color:#777;text-align:left","span.warn":"margin:0.25rem;color:#d81b60"}),((e,t)=>e?`& ${t}{${e}}`:"")));const A=(e,t,l,o)=>e==r?t:e==a?l:o;var L=Object.defineProperty,G=Object.defineProperties,J=Object.getOwnPropertyDescriptors,K=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,W=(e,t,l)=>t in e?L(e,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[t]=l,X=(e,t)=>{for(var l in t||(t={}))Q.call(t,l)&&W(e,l,t[l]);if(K)for(var l of K(t))U.call(t,l)&&W(e,l,t[l]);return e},Y=(e,t)=>G(e,J(t)),Z=(e,t)=>{var l={};for(var r in e)Q.call(e,r)&&t.indexOf(r)<0&&(l[r]=e[r]);if(null!=e&&K)for(var r of K(e))t.indexOf(r)<0&&U.call(e,r)&&(l[r]=e[r]);return l};const{useCallback:_,useMemo:ee,useState:te}=e,le="editable",re=(e,l)=>v(t.useTableCellIds(e,l),(t=>e+"."+t)),oe=(e,t,l)=>{const r=_(e,t);return l?r:void 0},ae=(...e)=>ee((()=>e),e),ne=(e,t)=>ee((()=>({store:e,tableId:t})),[e,t]),se=(e,t)=>ee((()=>({queries:e,queryId:t})),[e,t]),ie=(e,t=!1,l,r=0,o,a,n,s)=>{const[[i,d,u],c]=te([e,t,r]),m=_((e=>{c(e),null==s||s(e)}),[s]),b=oe((e=>m([e,e==i&&!d,u])),[m,i,d,u],l),p=_((e=>m([i,d,e])),[m,i,d]),g=!0===n?ge:n;return[[i,d,u],b,ee((()=>!1===n?null:h(g,{offset:u,limit:o,total:a,onChange:p})),[n,g,u,o,a,p])]},de=(e,t,o)=>ee((()=>{const a=null!=t?t:e;return C(y(Array.isArray(a)?C(v(a,(e=>[e,e]))):a,((e,t)=>{return[t,X(X({},{label:t,component:o}),(a=e,l(a)==r?{label:e}:e))];var a})))}),[t,o,e]),ue=({className:e,headerRow:t,idColumn:l,params:[r,o,a,n,s,i]})=>h("table",{className:e},i?h("caption",null,i):null,!1===t?null:h("thead",null,h("tr",null,!1===l?null:h(ce,{sort:null!=n?n:[],label:"Id",onClick:s}),y(r,(({label:e},t)=>h(ce,{key:t,cellId:t,label:e,sort:null!=n?n:[],onClick:s}))))),h("tbody",null,v(a,(e=>h("tr",{key:e},!1===l?null:h("th",null,e),y(r,(({component:t,getComponentProps:l},r)=>h("td",{key:r},h(t,Y(X(X({},w(l,e,r)),o),{rowId:e,cellId:r})))))))))),ce=({cellId:e,sort:[t,l],label:r=(null!=e?e:""),onClick:o})=>h("th",{onClick:oe((()=>null==o?void 0:o(e)),[o,e],o),className:u(l)||t!=e?void 0:`sorted ${l?"de":"a"}scending`},u(l)||t!=e?null:(l?"↓":"↑")+" ",r),me=({localRowId:l,params:[r,o,a,n,s,i,d]})=>{const c=t.useRemoteRowId(s,l,i);return h("tr",null,!1===r?null:h(e.Fragment,null,h("th",null,l),h("th",null,c)),y(o,(({component:e,getComponentProps:t},r)=>{const[o,s]=r.split(".",2),i=o===a?l:o===n?c:null;return u(i)?null:h("td",{key:r},h(e,Y(X({},w(t,i,s)),{store:d,tableId:o,rowId:i,cellId:s})))})))},he=({thing:e,onThingChange:t,className:n,hasSchema:u})=>{const[c,m]=te(),[b,p]=te(),[g,f]=te(),[w,v]=te(),[I,C]=te();b!==e&&(m((e=>{const t=l(e);return(e=>e==r||e==o)(t)||t==a&&d(e)?t:void 0})(e)),p(e),f(e+""),v(Number(e)||0),C(!!e));const y=_(((e,l)=>{l(e),p(e),t(e)}),[t]);return h("div",{className:n},h("button",{className:c,onClick:_((()=>{if(!(null==u?void 0:u())){const e=A(c,a,o,r),l=A(e,g,w,I);m(e),p(l),t(l)}}),[u,t,g,w,I,c])},c),A(c,h("input",{key:c,value:g,onChange:_((e=>y(e[s][i]+"",f)),[y])}),h("input",{key:c,type:"number",value:w,onChange:_((e=>y(Number(e[s][i]||0),v)),[y])}),h("input",{key:c,type:"checkbox",checked:I,onChange:_((e=>y(!!e[s].checked,C)),[y])})))},be=({tableId:e,rowId:l,cellId:r,store:o,className:a})=>{var n;return h(he,{thing:t.useCell(e,l,r,o),onThingChange:t.useSetCellCallback(e,l,r,(e=>e),[],o),className:null!=a?a:le+"Cell",hasSchema:null==(n=t.useStoreOrStoreById(o))?void 0:n.hasTablesSchema})},pe=({valueId:e,store:l,className:r})=>{var o;return h(he,{thing:t.useValue(e,l),onThingChange:t.useSetValueCallback(e,(e=>e),[],l),className:null!=r?r:le+n,hasSchema:null==(o=t.useStoreOrStoreById(l))?void 0:o.hasValuesSchema})},ge=({onChange:t,total:l,offset:r=0,limit:o=l,singular:a="row",plural:n=a+"s"})=>{(r>l||r<0)&&(r=0,t(0));const s=oe((()=>t(r-o)),[t,r,o],r>0),i=oe((()=>t(r+o)),[t,r,o],r+o<l);return h(e.Fragment,null,l>o&&h(e.Fragment,null,h("button",{className:"previous",disabled:0==r,onClick:s},"←"),h("button",{className:"next",disabled:r+o>=l,onClick:i},"→"),r+1," to ",Math.min(l,r+o)," of "),l," ",1!=l?n:a)};(class extends c{constructor(e){super(e),this.componentDidCatch=(e,t)=>console.error(e,t.componentStack),this.state={e:0}}render(){return this.state.e?h("span",{className:"warn"},"Inspector error: please see console for details."):this.props.children}}).getDerivedStateFromError=()=>({e:1});const fe=e=>new Map(e);fe(),fe(),exports.EditableCellView=be,exports.EditableValueView=pe,exports.RelationshipInHtmlTable=({relationshipId:l,relationships:r,editable:o,customCells:a,className:n,headerRow:s,idColumn:i=!0})=>{const[d,u,c,m]=((e,t)=>[e,null==e?void 0:e.getStore(),null==e?void 0:e.getLocalTableId(t),null==e?void 0:e.getRemoteTableId(t)])(t.useRelationshipsOrRelationshipsById(r),l),b=de([...re(c,u),...re(m,u)],a,o?be:t.CellView),p=ae(i,b,c,m,l,d,u);return h("table",{className:n},!1===s?null:h("thead",null,h("tr",null,!1===i?null:h(e.Fragment,null,h("th",null,c,".Id"),h("th",null,m,".Id")),y(b,(({label:e},t)=>h("th",{key:t},e))))),h("tbody",null,v(t.useRowIds(c,u),(e=>h(me,{key:e,localRowId:e,params:p})))))},exports.ResultSortedTableInHtmlTable=e=>{var l=e,{queryId:r,cellId:o,descending:a,offset:n,limit:s,queries:i,sortOnClick:d,paginator:u=!1,customCells:c,onChange:m}=l,b=Z(l,["queryId","cellId","descending","offset","limit","queries","sortOnClick","paginator","customCells","onChange"]);const[p,g,f]=ie(o,a,d,n,s,t.useResultRowCount(r,i),u,m);return h(ue,Y(X({},b),{params:ae(de(t.useResultTableCellIds(r,i),c,t.ResultCellView),se(i,r),t.useResultSortedRowIds(r,...p,s,i),p,g,f)}))},exports.ResultTableInHtmlTable=e=>{var l=e,{queryId:r,queries:o,customCells:a}=l,n=Z(l,["queryId","queries","customCells"]);return h(ue,Y(X({},n),{params:ae(de(t.useResultTableCellIds(r,o),a,t.ResultCellView),se(o,r),t.useResultRowIds(r,o))}))},exports.SliceInHtmlTable=e=>{var l=e,{indexId:r,sliceId:o,indexes:a,editable:n,customCells:s}=l,i=Z(l,["indexId","sliceId","indexes","editable","customCells"]);const[d,u,c]=((e,t)=>[e,null==e?void 0:e.getStore(),null==e?void 0:e.getTableId(t)])(t.useIndexesOrIndexesById(a),r);return h(ue,Y(X({},i),{params:ae(de(t.useTableCellIds(c,u),s,n?be:t.CellView),ne(u,c),t.useSliceRowIds(r,o,d))}))},exports.SortedTableInHtmlTable=e=>{var l=e,{tableId:r,cellId:o,descending:a,offset:n,limit:s,store:i,editable:d,sortOnClick:u,paginator:c=!1,onChange:m,customCells:b}=l,p=Z(l,["tableId","cellId","descending","offset","limit","store","editable","sortOnClick","paginator","onChange","customCells"]);const[g,f,w]=ie(o,a,u,n,s,t.useRowCount(r,i),c,m);return h(ue,Y(X({},p),{params:ae(de(t.useTableCellIds(r,i),b,d?be:t.CellView),ne(i,r),t.useSortedRowIds(r,...g,s,i),g,f,w)}))},exports.SortedTablePaginator=ge,exports.StoreInspector=e=>null,exports.TableInHtmlTable=e=>{var l=e,{tableId:r,store:o,editable:a,customCells:n}=l,s=Z(l,["tableId","store","editable","customCells"]);return h(ue,Y(X({},s),{params:ae(de(t.useTableCellIds(r,o),n,a?be:t.CellView),ne(o,r),t.useRowIds(r,o))}))},exports.ValuesInHtmlTable=({store:e,editable:l=!1,valueComponent:r=(l?pe:t.ValueView),getValueComponentProps:o,className:a,headerRow:s,idColumn:i})=>h("table",{className:a},!1===s?null:h("thead",null,h("tr",null,!1===i?null:h("th",null,"Id"),h("th",null,n))),h("tbody",null,v(t.useValueIds(e),(t=>h("tr",{key:t},!1===i?null:h("th",null,t),h("td",null,h(r,Y(X({},w(o,t)),{valueId:t,store:e}))))))));
|
|
1
|
+
"use strict";var e=require("react"),t=require("./ui-react");const l=e=>typeof e,r=l(""),o=l(!0),a=l(0),n="Value",s="currentTarget",i="value",d=isFinite,u=e=>null==e,{PureComponent:c,Fragment:m,createElement:h,useCallback:p,useLayoutEffect:b,useRef:g,useState:w}=e,f=(e,...t)=>u(e)?{}:e(...t),v=(e,t)=>e.map(t),I=Object,y=(e=[])=>I.fromEntries(e),C=(e,t)=>v(I.entries(e),(([e,l])=>t(l,e))),x="M20 80l5-15l40-40l10 10l-40 40l-15 5m5-15l10 10",k='content:url("',T=k+"data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' stroke-width='4' stroke='white' fill='none'>",O='</svg>")',R=k+"data:image/svg+xml,%3csvg viewBox='0 0 680 680' xmlns='http://www.w3.org/2000/svg' style='width:680px%3bheight:680px'%3e %3cpath stroke='white' stroke-width='80' fill='none' d='M340 617a84 241 90 11.01 0zM131 475a94 254 70 10428-124 114 286 70 01-428 124zm0-140a94 254 70 10428-124 114 286 70 01-428 124zm-12-127a94 254 70 00306 38 90 260 90 01-306-38zm221 3a74 241 90 11.01 0z' /%3e %3cpath fill='%23d81b60' d='M131 475a94 254 70 10428-124 114 286 70 01-428 124zm0-140a94 254 70 10428-124 114 286 70 01-428 124z' /%3e %3cpath d='M249 619a94 240 90 00308-128 114 289 70 01-308 128zM119 208a94 254 70 00306 38 90 260 90 01-306-38zm221 3a74 241 90 11.01 0z' /%3e%3c/svg%3e\")",S=v([[20,20,20,60],[20,20,60,20],[20,60,60,20],[60,20,20,60],[30,30,40,40]],(([e,t,l,r])=>T+`<rect x='20' y='20' width='60' height='60' fill='grey'/><rect x='${e}' y='${t}' width='${l}' height='${r}' fill='white'/>`+O)),N=T+"<path d='M20 20l60 60M20 80l60-60' />"+O,V=T+`<path d='${x}' />`+O,P=T+`<path d='${x}M20 20l60 60' />`+O;var j=Object.defineProperty,z=Object.defineProperties,q=Object.getOwnPropertyDescriptors,M=Object.getOwnPropertySymbols,$=Object.prototype.hasOwnProperty,E=Object.prototype.propertyIsEnumerable,F=(e,t,l)=>t in e?j(e,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[t]=l,H=(e,t)=>{for(var l in t||(t={}))$.call(t,l)&&F(e,l,t[l]);if(M)for(var l of M(t))E.call(t,l)&&F(e,l,t[l]);return e},B=(e,t)=>z(e,q(t));const D="*::-webkit-scrollbar";((e,t="")=>{e.join(t)})(C(B(H(B(H(B(H({"*":"all:revert","*::before":"all:revert","*::after":"all:revert",[D]:"width:0.5rem;height:0.5rem;",[D+"-track"]:"background:#111",[D+"-thumb"]:"background:#999;border:1px solid #111",[D+"-thumb:hover"]:"background:#fff",[D+"-corner"]:"background:#111",img:"width:1rem;height:1rem;background:#111;border:0;vertical-align:text-bottom",">img":"padding:0.25rem;bottom:0;right:0;position:fixed;"+R},y(v(["bottom:0;left:0","top:0;right:0"],((e,t)=>[`>img[data-position='${t}']`,e])))),{main:"display:flex;flex-direction:column;background:#111d;color:#fff;position:fixed;"}),y(v(["bottom:0;left:0;width:35vw;height:100vh","top:0;right:0;width:100vw;height:30vh","bottom:0;left:0;width:100vw;height:30vh","top:0;right:0;width:35vw;height:100vh","top:0;right:0;width:100vw;height:100vh"],((e,t)=>[`main[data-position='${t}']`,e])))),{header:"display:flex;padding:0.25rem;background:#000;align-items:center","header>img:nth-of-type(1)":R,"header>img:nth-of-type(6)":N}),y(v(S,((e,t)=>[`header>img[data-id='${t}']`,e])))),{"header>span":"flex:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;margin-left:0.25rem",article:"padding:0.25rem 0.25rem 0.25rem 0.5rem;overflow:auto;flex:1",details:"margin-left:0.75rem;width:fit-content;","details img":"display:none","details[open]>summary img":"display:unset;background:none;margin-left:0.25rem","details[open]>summary img.edit":V,"details[open]>summary img.done":P,summary:"margin-left:-0.75rem;line-height:1.25rem;user-select:none;width:fit-content",table:"border-collapse:collapse;table-layout:fixed;margin-bottom:0.5rem","table input":"background:#111;color:unset;padding:0 0.25rem;border:0;font-size:unset;vertical-align:top;margin:0",'table input[type="number"]':"width:4rem","table tbody button":"font-size:0;background:#fff;border-radius:50%;margin:0 0.125rem 0 0;width:0.85rem;color:#111","table button:first-letter":"font-size:0.75rem",thead:"background:#222","th:nth-of-type(1)":"min-width:2rem;","th.sorted":"background:#000","table caption":"text-align:left;white-space:nowrap;line-height:1.25rem",button:"width:1.5rem;border:none;background:none;color:#fff;padding:0","button[disabled]":"color:#777","button.next":"margin-right:0.5rem","th,td":"overflow:hidden;text-overflow:ellipsis;padding:0.25rem 0.5rem;max-width:12rem;white-space:nowrap;border-width:1px 0;border-style:solid;border-color:#777;text-align:left","span.warn":"margin:0.25rem;color:#d81b60"}),((e,t)=>e?`& ${t}{${e}}`:"")));const A=(e,t,l,o)=>e==r?t:e==a?l:o;var L=Object.defineProperty,G=Object.defineProperties,J=Object.getOwnPropertyDescriptors,K=Object.getOwnPropertySymbols,Q=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,W=(e,t,l)=>t in e?L(e,t,{enumerable:!0,configurable:!0,writable:!0,value:l}):e[t]=l,X=(e,t)=>{for(var l in t||(t={}))Q.call(t,l)&&W(e,l,t[l]);if(K)for(var l of K(t))U.call(t,l)&&W(e,l,t[l]);return e},Y=(e,t)=>G(e,J(t)),Z=(e,t)=>{var l={};for(var r in e)Q.call(e,r)&&t.indexOf(r)<0&&(l[r]=e[r]);if(null!=e&&K)for(var r of K(e))t.indexOf(r)<0&&U.call(e,r)&&(l[r]=e[r]);return l};const{useCallback:_,useMemo:ee,useState:te}=e,le="editable",re=(e,l)=>v(t.useTableCellIds(e,l),(t=>e+"."+t)),oe=(e,t,l)=>{const r=_(e,t);return l?r:void 0},ae=(...e)=>ee((()=>e),e),ne=(e,t)=>ee((()=>({store:e,tableId:t})),[e,t]),se=(e,t)=>ee((()=>({queries:e,queryId:t})),[e,t]),ie=(e,t=!1,l,r=0,o,a,n,s)=>{const[[i,d,u],c]=te([e,t,r]),m=_((e=>{c(e),null==s||s(e)}),[s]),p=oe((e=>m([e,e==i&&!d,u])),[m,i,d,u],l),b=_((e=>m([i,d,e])),[m,i,d]),g=!0===n?ge:n;return[[i,d,u],p,ee((()=>!1===n?null:h(g,{offset:u,limit:o,total:a,onChange:b})),[n,g,u,o,a,b])]},de=(e,t,o)=>ee((()=>{const a=null!=t?t:e;return y(C(Array.isArray(a)?y(v(a,(e=>[e,e]))):a,((e,t)=>{return[t,X(X({},{label:t,component:o}),(a=e,l(a)==r?{label:e}:e))];var a})))}),[t,o,e]),ue=({className:e,headerRow:t,idColumn:l,params:[r,o,a,n,s,i]})=>h("table",{className:e},i?h("caption",null,i):null,!1===t?null:h("thead",null,h("tr",null,!1===l?null:h(ce,{sort:null!=n?n:[],label:"Id",onClick:s}),C(r,(({label:e},t)=>h(ce,{key:t,cellId:t,label:e,sort:null!=n?n:[],onClick:s}))))),h("tbody",null,v(a,(e=>h("tr",{key:e},!1===l?null:h("th",null,e),C(r,(({component:t,getComponentProps:l},r)=>h("td",{key:r},h(t,Y(X(X({},f(l,e,r)),o),{rowId:e,cellId:r})))))))))),ce=({cellId:e,sort:[t,l],label:r=(null!=e?e:""),onClick:o})=>h("th",{onClick:oe((()=>null==o?void 0:o(e)),[o,e],o),className:u(l)||t!=e?void 0:`sorted ${l?"de":"a"}scending`},u(l)||t!=e?null:(l?"↓":"↑")+" ",r),me=({localRowId:l,params:[r,o,a,n,s,i,d]})=>{const c=t.useRemoteRowId(s,l,i);return h("tr",null,!1===r?null:h(e.Fragment,null,h("th",null,l),h("th",null,c)),C(o,(({component:e,getComponentProps:t},r)=>{const[o,s]=r.split(".",2),i=o===a?l:o===n?c:null;return u(i)?null:h("td",{key:r},h(e,Y(X({},f(t,i,s)),{store:d,tableId:o,rowId:i,cellId:s})))})))},he=({thing:e,onThingChange:t,className:n,hasSchema:u,showType:c=!0})=>{const[m,p]=te(),[b,g]=te(),[w,f]=te(),[v,I]=te(),[y,C]=te();b!==e&&(p((e=>{const t=l(e);return(e=>e==r||e==o)(t)||t==a&&d(e)?t:void 0})(e)),g(e),f(e+""),I(Number(e)||0),C(!!e));const x=_(((e,l)=>{l(e),g(e),t(e)}),[t]),k=_((()=>{if(!(null==u?void 0:u())){const e=A(m,a,o,r),l=A(e,w,v,y);p(e),g(l),t(l)}}),[u,t,w,v,y,m]);return h("div",{className:n},c?h("button",{className:m,onClick:k},m):null,A(m,h("input",{key:m,value:w,onChange:_((e=>x(e[s][i]+"",f)),[x])}),h("input",{key:m,type:"number",value:v,onChange:_((e=>x(Number(e[s][i]||0),I)),[x])}),h("input",{key:m,type:"checkbox",checked:y,onChange:_((e=>x(!!e[s].checked,C)),[x])})))},pe=({tableId:e,rowId:l,cellId:r,store:o,className:a,showType:n})=>{var s;return h(he,{thing:t.useCell(e,l,r,o),onThingChange:t.useSetCellCallback(e,l,r,(e=>e),[],o),className:null!=a?a:le+"Cell",showType:n,hasSchema:null==(s=t.useStoreOrStoreById(o))?void 0:s.hasTablesSchema})},be=({valueId:e,store:l,className:r,showType:o})=>{var a;return h(he,{thing:t.useValue(e,l),onThingChange:t.useSetValueCallback(e,(e=>e),[],l),className:null!=r?r:le+n,showType:o,hasSchema:null==(a=t.useStoreOrStoreById(l))?void 0:a.hasValuesSchema})},ge=({onChange:t,total:l,offset:r=0,limit:o=l,singular:a="row",plural:n=a+"s"})=>{(r>l||r<0)&&(r=0,t(0));const s=oe((()=>t(r-o)),[t,r,o],r>0),i=oe((()=>t(r+o)),[t,r,o],r+o<l);return h(e.Fragment,null,l>o&&h(e.Fragment,null,h("button",{className:"previous",disabled:0==r,onClick:s},"←"),h("button",{className:"next",disabled:r+o>=l,onClick:i},"→"),r+1," to ",Math.min(l,r+o)," of "),l," ",1!=l?n:a)};(class extends c{constructor(e){super(e),this.componentDidCatch=(e,t)=>console.error(e,t.componentStack),this.state={e:0}}render(){return this.state.e?h("span",{className:"warn"},"Inspector error: please see console for details."):this.props.children}}).getDerivedStateFromError=()=>({e:1});const we=e=>new Map(e);we(),we(),exports.EditableCellView=pe,exports.EditableValueView=be,exports.RelationshipInHtmlTable=({relationshipId:l,relationships:r,editable:o,customCells:a,className:n,headerRow:s,idColumn:i=!0})=>{const[d,u,c,m]=((e,t)=>[e,null==e?void 0:e.getStore(),null==e?void 0:e.getLocalTableId(t),null==e?void 0:e.getRemoteTableId(t)])(t.useRelationshipsOrRelationshipsById(r),l),p=de([...re(c,u),...re(m,u)],a,o?pe:t.CellView),b=ae(i,p,c,m,l,d,u);return h("table",{className:n},!1===s?null:h("thead",null,h("tr",null,!1===i?null:h(e.Fragment,null,h("th",null,c,".Id"),h("th",null,m,".Id")),C(p,(({label:e},t)=>h("th",{key:t},e))))),h("tbody",null,v(t.useRowIds(c,u),(e=>h(me,{key:e,localRowId:e,params:b})))))},exports.ResultSortedTableInHtmlTable=e=>{var l=e,{queryId:r,cellId:o,descending:a,offset:n,limit:s,queries:i,sortOnClick:d,paginator:u=!1,customCells:c,onChange:m}=l,p=Z(l,["queryId","cellId","descending","offset","limit","queries","sortOnClick","paginator","customCells","onChange"]);const[b,g,w]=ie(o,a,d,n,s,t.useResultRowCount(r,i),u,m);return h(ue,Y(X({},p),{params:ae(de(t.useResultTableCellIds(r,i),c,t.ResultCellView),se(i,r),t.useResultSortedRowIds(r,...b,s,i),b,g,w)}))},exports.ResultTableInHtmlTable=e=>{var l=e,{queryId:r,queries:o,customCells:a}=l,n=Z(l,["queryId","queries","customCells"]);return h(ue,Y(X({},n),{params:ae(de(t.useResultTableCellIds(r,o),a,t.ResultCellView),se(o,r),t.useResultRowIds(r,o))}))},exports.SliceInHtmlTable=e=>{var l=e,{indexId:r,sliceId:o,indexes:a,editable:n,customCells:s}=l,i=Z(l,["indexId","sliceId","indexes","editable","customCells"]);const[d,u,c]=((e,t)=>[e,null==e?void 0:e.getStore(),null==e?void 0:e.getTableId(t)])(t.useIndexesOrIndexesById(a),r);return h(ue,Y(X({},i),{params:ae(de(t.useTableCellIds(c,u),s,n?pe:t.CellView),ne(u,c),t.useSliceRowIds(r,o,d))}))},exports.SortedTableInHtmlTable=e=>{var l=e,{tableId:r,cellId:o,descending:a,offset:n,limit:s,store:i,editable:d,sortOnClick:u,paginator:c=!1,onChange:m,customCells:p}=l,b=Z(l,["tableId","cellId","descending","offset","limit","store","editable","sortOnClick","paginator","onChange","customCells"]);const[g,w,f]=ie(o,a,u,n,s,t.useRowCount(r,i),c,m);return h(ue,Y(X({},b),{params:ae(de(t.useTableCellIds(r,i),p,d?pe:t.CellView),ne(i,r),t.useSortedRowIds(r,...g,s,i),g,w,f)}))},exports.SortedTablePaginator=ge,exports.StoreInspector=e=>null,exports.TableInHtmlTable=e=>{var l=e,{tableId:r,store:o,editable:a,customCells:n}=l,s=Z(l,["tableId","store","editable","customCells"]);return h(ue,Y(X({},s),{params:ae(de(t.useTableCellIds(r,o),n,a?pe:t.CellView),ne(o,r),t.useRowIds(r,o))}))},exports.ValuesInHtmlTable=({store:e,editable:l=!1,valueComponent:r=(l?be:t.ValueView),getValueComponentProps:o,className:a,headerRow:s,idColumn:i})=>h("table",{className:a},!1===s?null:h("thead",null,h("tr",null,!1===i?null:h("th",null,"Id"),h("th",null,n))),h("tbody",null,v(t.useValueIds(e),(t=>h("tr",{key:t},!1===i?null:h("th",null,t),h("td",null,h(r,Y(X({},f(o,t)),{valueId:t,store:e}))))))));
|
|
Binary file
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const getTypeOf = (thing) => typeof thing;
|
|
2
2
|
const EMPTY_STRING = '';
|
|
3
3
|
const STRING = getTypeOf(EMPTY_STRING);
|
|
4
|
+
const strStartsWith = (str, prefix) => str.startsWith(prefix);
|
|
4
5
|
|
|
5
6
|
const isInstanceOf = (thing, cls) => thing instanceof cls;
|
|
6
7
|
const isUndefined = (thing) => thing == void 0;
|
|
@@ -30,12 +31,17 @@ const jsonParse = JSON.parse;
|
|
|
30
31
|
const SET_CHANGES = 's';
|
|
31
32
|
const STORE_PATH = '/store';
|
|
32
33
|
const PUT = 'PUT';
|
|
33
|
-
const
|
|
34
|
-
type + (isString(payload) ? payload : jsonString(payload));
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
34
|
+
const construct = (prefix, type, payload) =>
|
|
35
|
+
prefix + type + (isString(payload) ? payload : jsonString(payload));
|
|
36
|
+
const deconstruct = (prefix, message, stringified) => {
|
|
37
|
+
const prefixSize = size(prefix);
|
|
38
|
+
return strStartsWith(message, prefix)
|
|
39
|
+
? [
|
|
40
|
+
message[prefixSize],
|
|
41
|
+
(stringified ? jsonParse : String)(slice(message, prefixSize + 1)),
|
|
42
|
+
]
|
|
43
|
+
: void 0;
|
|
44
|
+
};
|
|
39
45
|
|
|
40
46
|
const collHas = (coll, keyOrValue) => coll?.has(keyOrValue) ?? false;
|
|
41
47
|
const collDel = (coll, keyOrValue) => coll?.delete(keyOrValue);
|
|
@@ -191,10 +197,6 @@ const createCustomPersister = (
|
|
|
191
197
|
};
|
|
192
198
|
|
|
193
199
|
const MESSAGE = 'message';
|
|
194
|
-
const DEFAULT_CONFIG = {
|
|
195
|
-
storeProtocol: 'https',
|
|
196
|
-
storePath: STORE_PATH,
|
|
197
|
-
};
|
|
198
200
|
const createPartyKitPersister = (
|
|
199
201
|
store,
|
|
200
202
|
connection,
|
|
@@ -202,8 +204,11 @@ const createPartyKitPersister = (
|
|
|
202
204
|
onIgnoredError,
|
|
203
205
|
) => {
|
|
204
206
|
const {host, room} = connection.partySocketOptions;
|
|
205
|
-
const {
|
|
206
|
-
|
|
207
|
+
const {
|
|
208
|
+
storeProtocol = 'https',
|
|
209
|
+
storePath = STORE_PATH,
|
|
210
|
+
messagePrefix = EMPTY_STRING,
|
|
211
|
+
} = {
|
|
207
212
|
...(isString(configOrStoreProtocol)
|
|
208
213
|
? {storeProtocol: configOrStoreProtocol}
|
|
209
214
|
: configOrStoreProtocol),
|
|
@@ -228,18 +233,23 @@ const createPartyKitPersister = (
|
|
|
228
233
|
const getPersisted = async () => await getOrSetStore();
|
|
229
234
|
const setPersisted = async (getContent, getTransactionChanges) => {
|
|
230
235
|
if (getTransactionChanges) {
|
|
231
|
-
connection.send(
|
|
236
|
+
connection.send(
|
|
237
|
+
construct(messagePrefix, SET_CHANGES, getTransactionChanges()),
|
|
238
|
+
);
|
|
232
239
|
} else {
|
|
233
240
|
await getOrSetStore(getContent());
|
|
234
241
|
}
|
|
235
242
|
};
|
|
236
243
|
const addPersisterListener = (listener) => {
|
|
237
|
-
const messageListener = (event) =>
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
244
|
+
const messageListener = (event) =>
|
|
245
|
+
ifNotUndefined(
|
|
246
|
+
deconstruct(messagePrefix, event.data, 1),
|
|
247
|
+
([type, payload]) => {
|
|
248
|
+
if (type == SET_CHANGES) {
|
|
249
|
+
listener(void 0, () => payload);
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
);
|
|
243
253
|
connection.addEventListener(MESSAGE, messageListener);
|
|
244
254
|
return messageListener;
|
|
245
255
|
};
|
|
@@ -3,6 +3,7 @@ const EMPTY_STRING = '';
|
|
|
3
3
|
const STRING = getTypeOf(EMPTY_STRING);
|
|
4
4
|
const T = 't';
|
|
5
5
|
const V = 'v';
|
|
6
|
+
const strStartsWith = (str, prefix) => str.startsWith(prefix);
|
|
6
7
|
|
|
7
8
|
const promise = Promise;
|
|
8
9
|
const isInstanceOf = (thing, cls) => thing instanceof cls;
|
|
@@ -42,12 +43,17 @@ const jsonParse = JSON.parse;
|
|
|
42
43
|
const SET_CHANGES = 's';
|
|
43
44
|
const STORE_PATH = '/store';
|
|
44
45
|
const PUT = 'PUT';
|
|
45
|
-
const
|
|
46
|
-
type + (isString(payload) ? payload : jsonString(payload));
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
const construct = (prefix, type, payload) =>
|
|
47
|
+
prefix + type + (isString(payload) ? payload : jsonString(payload));
|
|
48
|
+
const deconstruct = (prefix, message, stringified) => {
|
|
49
|
+
const prefixSize = size(prefix);
|
|
50
|
+
return strStartsWith(message, prefix)
|
|
51
|
+
? [
|
|
52
|
+
message[prefixSize],
|
|
53
|
+
(stringified ? jsonParse : String)(slice(message, prefixSize + 1)),
|
|
54
|
+
]
|
|
55
|
+
: void 0;
|
|
56
|
+
};
|
|
51
57
|
|
|
52
58
|
const collForEach = (coll, cb) => coll?.forEach(cb);
|
|
53
59
|
|
|
@@ -61,15 +67,16 @@ const RESPONSE_HEADERS = objNew(
|
|
|
61
67
|
'*',
|
|
62
68
|
]),
|
|
63
69
|
);
|
|
64
|
-
const
|
|
65
|
-
await storage.get(
|
|
66
|
-
|
|
70
|
+
const hasStore = async (that) =>
|
|
71
|
+
await that.party.storage.get(
|
|
72
|
+
(that.config.storagePrefix ?? EMPTY_STRING) + HAS_STORE,
|
|
73
|
+
);
|
|
74
|
+
const loadStore = async (that) => {
|
|
67
75
|
const tables = {};
|
|
68
76
|
const values = {};
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const [type, ids] = deconstructMessage(key);
|
|
77
|
+
const storagePrefix = that.config.storagePrefix ?? EMPTY_STRING;
|
|
78
|
+
mapForEach(await that.party.storage.list(), (key, cellOrValue) =>
|
|
79
|
+
ifNotUndefined(deconstruct(storagePrefix, key), ([type, ids]) => {
|
|
73
80
|
if (type == T) {
|
|
74
81
|
const [tableId, rowId, cellId] = jsonParse('[' + ids + ']');
|
|
75
82
|
objEnsure(objEnsure(tables, tableId, objNew), rowId, objNew)[cellId] =
|
|
@@ -77,98 +84,182 @@ const loadStoreFromStorage = async (storage, prefix) => {
|
|
|
77
84
|
} else if (type == V) {
|
|
78
85
|
values[ids] = cellOrValue;
|
|
79
86
|
}
|
|
80
|
-
}
|
|
81
|
-
|
|
87
|
+
}),
|
|
88
|
+
);
|
|
82
89
|
return [tables, values];
|
|
83
90
|
};
|
|
84
|
-
const
|
|
85
|
-
|
|
91
|
+
const saveStore = async (
|
|
92
|
+
that,
|
|
93
|
+
transactionChanges,
|
|
94
|
+
initialSave,
|
|
95
|
+
requestOrConnection,
|
|
96
|
+
) => {
|
|
97
|
+
const storage = that.party.storage;
|
|
98
|
+
const storagePrefix = that.config.storagePrefix ?? EMPTY_STRING;
|
|
99
|
+
const promises = [storage.put(storagePrefix + HAS_STORE, 1)];
|
|
86
100
|
const keyPrefixesToDelete = [];
|
|
87
101
|
objMap(transactionChanges[0], (table, tableId) =>
|
|
88
102
|
isUndefined(table)
|
|
89
|
-
?
|
|
103
|
+
? !initialSave &&
|
|
104
|
+
that.canDelTable(tableId, requestOrConnection) &&
|
|
105
|
+
arrayUnshift(
|
|
90
106
|
keyPrefixesToDelete,
|
|
91
|
-
|
|
107
|
+
constructStorageKey(storagePrefix, T, tableId),
|
|
92
108
|
)
|
|
93
|
-
:
|
|
109
|
+
: that.canSetTable(tableId, initialSave, requestOrConnection) &&
|
|
110
|
+
objMap(table, (row, rowId) =>
|
|
94
111
|
isUndefined(row)
|
|
95
|
-
?
|
|
112
|
+
? !initialSave &&
|
|
113
|
+
that.canDelRow(tableId, rowId, requestOrConnection) &&
|
|
114
|
+
arrayPush(
|
|
96
115
|
keyPrefixesToDelete,
|
|
97
|
-
|
|
116
|
+
constructStorageKey(storagePrefix, T, tableId, rowId),
|
|
98
117
|
)
|
|
99
|
-
:
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
118
|
+
: that.canSetRow(
|
|
119
|
+
tableId,
|
|
120
|
+
rowId,
|
|
121
|
+
initialSave,
|
|
122
|
+
requestOrConnection,
|
|
123
|
+
) &&
|
|
124
|
+
objMap(row, (cell, cellId) =>
|
|
125
|
+
isUndefined(cell)
|
|
126
|
+
? !initialSave &&
|
|
127
|
+
that.canDelCell(
|
|
128
|
+
tableId,
|
|
129
|
+
rowId,
|
|
130
|
+
cellId,
|
|
131
|
+
requestOrConnection,
|
|
132
|
+
) &&
|
|
133
|
+
arrayPush(
|
|
134
|
+
promises,
|
|
135
|
+
storage.delete(
|
|
136
|
+
constructStorageKey(
|
|
137
|
+
storagePrefix,
|
|
138
|
+
T,
|
|
139
|
+
tableId,
|
|
140
|
+
rowId,
|
|
141
|
+
cellId,
|
|
142
|
+
),
|
|
143
|
+
),
|
|
144
|
+
)
|
|
145
|
+
: that.canSetCell(
|
|
146
|
+
tableId,
|
|
147
|
+
rowId,
|
|
148
|
+
cellId,
|
|
149
|
+
cell,
|
|
150
|
+
initialSave,
|
|
151
|
+
requestOrConnection,
|
|
152
|
+
) &&
|
|
153
|
+
arrayPush(
|
|
154
|
+
promises,
|
|
155
|
+
storage.put(
|
|
156
|
+
constructStorageKey(
|
|
157
|
+
storagePrefix,
|
|
158
|
+
T,
|
|
159
|
+
tableId,
|
|
160
|
+
rowId,
|
|
161
|
+
cellId,
|
|
162
|
+
),
|
|
163
|
+
cell,
|
|
164
|
+
),
|
|
165
|
+
),
|
|
106
166
|
),
|
|
107
167
|
),
|
|
108
168
|
);
|
|
109
169
|
objMap(transactionChanges[1], (value, valueId) =>
|
|
110
|
-
|
|
170
|
+
isUndefined(value)
|
|
171
|
+
? !initialSave &&
|
|
172
|
+
that.canDelValue(valueId, requestOrConnection) &&
|
|
173
|
+
arrayPush(promises, storage.delete(storagePrefix + V + valueId))
|
|
174
|
+
: that.canSetValue(valueId, value, initialSave, requestOrConnection) &&
|
|
175
|
+
arrayPush(promises, storage.put(storagePrefix + V + valueId, value)),
|
|
111
176
|
);
|
|
112
177
|
if (!arrayIsEmpty(keyPrefixesToDelete)) {
|
|
113
178
|
mapForEach(await storage.list(), (key) =>
|
|
114
179
|
arrayEvery(
|
|
115
180
|
keyPrefixesToDelete,
|
|
116
181
|
(keyPrefixToDelete) =>
|
|
117
|
-
!key
|
|
118
|
-
(
|
|
182
|
+
!strStartsWith(key, keyPrefixToDelete) ||
|
|
183
|
+
(arrayPush(promises, storage.delete(key)) && 0),
|
|
119
184
|
),
|
|
120
185
|
);
|
|
121
186
|
}
|
|
122
187
|
await promiseAll(promises);
|
|
123
188
|
};
|
|
124
|
-
const
|
|
125
|
-
type
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
);
|
|
189
|
+
const constructStorageKey = (storagePrefix, type, ...ids) =>
|
|
190
|
+
construct(storagePrefix, type, slice(jsonString(ids), 1, -1));
|
|
191
|
+
const createResponse = async (that, status, body = null) =>
|
|
192
|
+
new Response(body, {
|
|
193
|
+
status,
|
|
194
|
+
headers: that.config.responseHeaders ?? RESPONSE_HEADERS,
|
|
195
|
+
});
|
|
131
196
|
class TinyBasePartyKitServer {
|
|
132
197
|
constructor(party) {
|
|
133
198
|
this.party = party;
|
|
134
199
|
this.config = {};
|
|
135
|
-
this.createResponse = (status, body = null) =>
|
|
136
|
-
new Response(body, {
|
|
137
|
-
status,
|
|
138
|
-
headers: this.config.responseHeaders ?? RESPONSE_HEADERS,
|
|
139
|
-
});
|
|
140
200
|
}
|
|
141
201
|
async onRequest(request) {
|
|
142
|
-
const storage = this.party.storage;
|
|
143
|
-
const prefix = this.config.storagePrefix ?? EMPTY_STRING;
|
|
144
202
|
const storePath = this.config.storePath ?? STORE_PATH;
|
|
145
203
|
if (new URL(request.url).pathname.endsWith(storePath)) {
|
|
146
|
-
const
|
|
204
|
+
const hasExistingStore = await hasStore(this);
|
|
147
205
|
const text = await request.text();
|
|
148
206
|
if (request.method == PUT) {
|
|
149
|
-
if (
|
|
150
|
-
return
|
|
207
|
+
if (hasExistingStore) {
|
|
208
|
+
return createResponse(this, 205);
|
|
151
209
|
}
|
|
152
|
-
await
|
|
153
|
-
return
|
|
210
|
+
await saveStore(this, jsonParse(text), true, request);
|
|
211
|
+
return createResponse(this, 201);
|
|
154
212
|
}
|
|
155
|
-
return
|
|
213
|
+
return createResponse(
|
|
214
|
+
this,
|
|
156
215
|
200,
|
|
157
|
-
|
|
158
|
-
? jsonString(await loadStoreFromStorage(storage, prefix))
|
|
159
|
-
: EMPTY_STRING,
|
|
216
|
+
hasExistingStore ? jsonString(await loadStore(this)) : EMPTY_STRING,
|
|
160
217
|
);
|
|
161
218
|
}
|
|
162
|
-
return
|
|
219
|
+
return createResponse(this, 404);
|
|
163
220
|
}
|
|
164
|
-
async onMessage(message,
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
221
|
+
async onMessage(message, connection) {
|
|
222
|
+
const messagePrefix = this.config.messagePrefix ?? EMPTY_STRING;
|
|
223
|
+
await ifNotUndefined(
|
|
224
|
+
deconstruct(messagePrefix, message, 1),
|
|
225
|
+
async ([type, payload]) => {
|
|
226
|
+
if (type == SET_CHANGES && (await hasStore(this))) {
|
|
227
|
+
await saveStore(this, payload, false, connection);
|
|
228
|
+
this.party.broadcast(construct(messagePrefix, SET_CHANGES, payload));
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
canSetTable(_tableId, _initialSave, _requestOrConnection) {
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
canDelTable(_tableId, _connection) {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
canSetRow(_tableId, _rowId, _initialSave, _requestOrConnection) {
|
|
240
|
+
return true;
|
|
241
|
+
}
|
|
242
|
+
canDelRow(_tableId, _rowId, _connection) {
|
|
243
|
+
return true;
|
|
244
|
+
}
|
|
245
|
+
canSetCell(
|
|
246
|
+
_tableId,
|
|
247
|
+
_rowId,
|
|
248
|
+
_cellId,
|
|
249
|
+
_cell,
|
|
250
|
+
_initialSave,
|
|
251
|
+
_requestOrConnection,
|
|
252
|
+
) {
|
|
253
|
+
return true;
|
|
254
|
+
}
|
|
255
|
+
canDelCell(_tableId, _rowId, _cellId, _connection) {
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
canSetValue(_valueId, _value, _initialSave, _requestOrConnection) {
|
|
259
|
+
return true;
|
|
260
|
+
}
|
|
261
|
+
canDelValue(_valueId, _connection) {
|
|
262
|
+
return true;
|
|
172
263
|
}
|
|
173
264
|
}
|
|
174
265
|
|
|
@@ -589,7 +589,13 @@ const RelationshipInHtmlRow = ({
|
|
|
589
589
|
),
|
|
590
590
|
);
|
|
591
591
|
};
|
|
592
|
-
const EditableThing = ({
|
|
592
|
+
const EditableThing = ({
|
|
593
|
+
thing,
|
|
594
|
+
onThingChange,
|
|
595
|
+
className,
|
|
596
|
+
hasSchema,
|
|
597
|
+
showType = true,
|
|
598
|
+
}) => {
|
|
593
599
|
const [thingType, setThingType] = useState();
|
|
594
600
|
const [currentThing, setCurrentThing] = useState();
|
|
595
601
|
const [stringThing, setStringThing] = useState();
|
|
@@ -610,37 +616,37 @@ const EditableThing = ({thing, onThingChange, className, hasSchema}) => {
|
|
|
610
616
|
},
|
|
611
617
|
[onThingChange],
|
|
612
618
|
);
|
|
619
|
+
const handleTypeChange = useCallback(() => {
|
|
620
|
+
if (!hasSchema?.()) {
|
|
621
|
+
const nextType = getTypeCase(thingType, NUMBER, BOOLEAN, STRING);
|
|
622
|
+
const thing2 = getTypeCase(
|
|
623
|
+
nextType,
|
|
624
|
+
stringThing,
|
|
625
|
+
numberThing,
|
|
626
|
+
booleanThing,
|
|
627
|
+
);
|
|
628
|
+
setThingType(nextType);
|
|
629
|
+
setCurrentThing(thing2);
|
|
630
|
+
onThingChange(thing2);
|
|
631
|
+
}
|
|
632
|
+
}, [
|
|
633
|
+
hasSchema,
|
|
634
|
+
onThingChange,
|
|
635
|
+
stringThing,
|
|
636
|
+
numberThing,
|
|
637
|
+
booleanThing,
|
|
638
|
+
thingType,
|
|
639
|
+
]);
|
|
613
640
|
return /* @__PURE__ */ createElement(
|
|
614
641
|
'div',
|
|
615
642
|
{className},
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
onClick: useCallback(() => {
|
|
621
|
-
if (!hasSchema?.()) {
|
|
622
|
-
const nextType = getTypeCase(thingType, NUMBER, BOOLEAN, STRING);
|
|
623
|
-
const thing2 = getTypeCase(
|
|
624
|
-
nextType,
|
|
625
|
-
stringThing,
|
|
626
|
-
numberThing,
|
|
627
|
-
booleanThing,
|
|
628
|
-
);
|
|
629
|
-
setThingType(nextType);
|
|
630
|
-
setCurrentThing(thing2);
|
|
631
|
-
onThingChange(thing2);
|
|
632
|
-
}
|
|
633
|
-
}, [
|
|
634
|
-
hasSchema,
|
|
635
|
-
onThingChange,
|
|
636
|
-
stringThing,
|
|
637
|
-
numberThing,
|
|
638
|
-
booleanThing,
|
|
643
|
+
showType
|
|
644
|
+
? /* @__PURE__ */ createElement(
|
|
645
|
+
'button',
|
|
646
|
+
{className: thingType, onClick: handleTypeChange},
|
|
639
647
|
thingType,
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
thingType,
|
|
643
|
-
),
|
|
648
|
+
)
|
|
649
|
+
: null,
|
|
644
650
|
getTypeCase(
|
|
645
651
|
thingType,
|
|
646
652
|
/* @__PURE__ */ createElement('input', {
|
|
@@ -943,7 +949,14 @@ const ResultSortedTableInHtmlTable = ({
|
|
|
943
949
|
),
|
|
944
950
|
});
|
|
945
951
|
};
|
|
946
|
-
const EditableCellView = ({
|
|
952
|
+
const EditableCellView = ({
|
|
953
|
+
tableId,
|
|
954
|
+
rowId,
|
|
955
|
+
cellId,
|
|
956
|
+
store,
|
|
957
|
+
className,
|
|
958
|
+
showType,
|
|
959
|
+
}) =>
|
|
947
960
|
/* @__PURE__ */ createElement(EditableThing, {
|
|
948
961
|
thing: useCell(tableId, rowId, cellId, store),
|
|
949
962
|
onThingChange: useSetCellCallback(
|
|
@@ -955,13 +968,15 @@ const EditableCellView = ({tableId, rowId, cellId, store, className}) =>
|
|
|
955
968
|
store,
|
|
956
969
|
),
|
|
957
970
|
className: className ?? EDITABLE + CELL,
|
|
971
|
+
showType,
|
|
958
972
|
hasSchema: useStoreOrStoreById(store)?.hasTablesSchema,
|
|
959
973
|
});
|
|
960
|
-
const EditableValueView = ({valueId, store, className}) =>
|
|
974
|
+
const EditableValueView = ({valueId, store, className, showType}) =>
|
|
961
975
|
/* @__PURE__ */ createElement(EditableThing, {
|
|
962
976
|
thing: useValue(valueId, store),
|
|
963
977
|
onThingChange: useSetValueCallback(valueId, (value) => value, [], store),
|
|
964
978
|
className: className ?? EDITABLE + VALUE,
|
|
979
|
+
showType,
|
|
965
980
|
hasSchema: useStoreOrStoreById(store)?.hasValuesSchema,
|
|
966
981
|
});
|
|
967
982
|
const SortedTablePaginator = ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const t=t=>typeof t,e=
|
|
1
|
+
const t=t=>typeof t,e="",n=t(e),o=(t,e)=>t instanceof e,r=t=>null==t,l=(t,e,n)=>r(t)?null==n?void 0:n():e(t),i=e=>t(e)==n,s=t=>t.length,u=Object,a=u.keys,c=u.freeze,d=t=>(t=>o(t,u)&&t.constructor==u)(t)&&0==(t=>s(a(t)))(t),v=t=>JSON.stringify(t,((t,e)=>o(e,Map)?u.fromEntries([...e]):e)),y=JSON.parse,f="/store",p=t=>new Map(t),h=(t,e)=>null==t?void 0:t.get(e),m=(t,e,n)=>{return r(n)?(l=e,null==(o=t)||o.delete(l),t):null==t?void 0:t.set(e,n);var o,l},P=(t,e,n)=>{var o,r,l;return r=e,null!=(l=null==(o=t)?void 0:o.has(r))&&l||m(t,e,n()),h(t,e)};var b=(t,e,n)=>new Promise(((o,r)=>{var l=t=>{try{s(n.next(t))}catch(t){r(t)}},i=t=>{try{s(n.throw(t))}catch(t){r(t)}},s=t=>t.done?o(t.value):Promise.resolve(t.value).then(l,i);s((n=n.apply(t,e)).next())}));const O=p(),g=p();var S=Object.defineProperty,w=Object.defineProperties,j=Object.getOwnPropertyDescriptors,A=Object.getOwnPropertySymbols,L=Object.prototype.hasOwnProperty,x=Object.prototype.propertyIsEnumerable,C=(t,e,n)=>e in t?S(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,E=(t,e)=>{for(var n in e||(e={}))L.call(e,n)&&C(t,n,e[n]);if(A)for(var n of A(e))x.call(e,n)&&C(t,n,e[n]);return t},T=(t,e,n)=>new Promise(((o,r)=>{var l=t=>{try{s(n.next(t))}catch(t){r(t)}},i=t=>{try{s(n.throw(t))}catch(t){r(t)}},s=t=>t.done?o(t.value):Promise.resolve(t.value).then(l,i);s((n=n.apply(t,e)).next())}));const k="message",D=(t,n,o,u)=>{var a;const{host:p,room:S}=n.partySocketOptions,{storeProtocol:A="https",storePath:L=f,messagePrefix:x=e}=E({},i(o)?{storeProtocol:o}:o),C=A+"://"+p+"/parties/"+(null!=(a=n.name)?a:"main")+"/"+S+L,D=t=>T(void 0,null,(function*(){return yield(yield fetch(C,(e=E({},t?{method:"PUT",body:v(t)}:{}),n={mode:"cors",cache:"no-store"},w(e,j(n))))).json();var e,n}));return((t,e,n,o,i,s,u=[])=>{let a,v,y,f=0,p=0;P(O,u,(()=>0)),P(g,u,(()=>[]));const S=t=>b(void 0,null,(function*(){return 2!=f&&(f=1,yield w.schedule((()=>b(void 0,null,(function*(){yield t(),f=0}))))),w})),w={load:(n,o)=>b(void 0,null,(function*(){return yield S((()=>b(void 0,null,(function*(){try{t.setContent(yield e())}catch(e){t.setContent([n,o])}}))))})),startAutoLoad:(...n)=>b(void 0,[...n],(function*(n={},r={}){return w.stopAutoLoad(),yield w.load(n,r),p=1,y=o(((n,o)=>b(void 0,null,(function*(){if(o){const e=o();yield S((()=>b(void 0,null,(function*(){return t.setTransactionChanges(e)}))))}else yield S((()=>b(void 0,null,(function*(){var o;try{t.setContent(null!=(o=null==n?void 0:n())?o:yield e())}catch(t){null==s||s(t)}}))))})))),w})),stopAutoLoad:()=>(p&&(i(y),y=void 0,p=0),w),save:e=>b(void 0,null,(function*(){return 1!=f&&(f=2,yield w.schedule((()=>b(void 0,null,(function*(){try{yield n(t.getContent,e)}catch(t){null==s||s(t)}f=0}))))),w})),startAutoSave:()=>b(void 0,null,(function*(){return yield w.stopAutoSave().save(),a=t.addDidFinishTransactionListener(((t,e)=>{const[n,o]=e();d(n)&&d(o)||w.save((()=>[n,o]))})),w})),stopAutoSave:()=>(l(a,t.delListener),w),schedule:(...t)=>b(void 0,null,(function*(){return((t,...e)=>{t.push(...e)})(h(g,u),...t),yield b(void 0,null,(function*(){if(!h(O,u)){for(m(O,u,1);!r((t=h(g,u),v=t.shift()));)try{yield v()}catch(t){null==s||s(t)}m(O,u,0)}var t})),w})),getStore:()=>t,destroy:()=>w.stopAutoLoad().stopAutoSave(),getStats:()=>({})};return c(w)})(t,(()=>T(void 0,null,(function*(){return yield D()}))),((t,e)=>T(void 0,null,(function*(){var o,r;e?n.send((o=x,r=e(),o+"s"+(i(r)?r:v(r)))):yield D(t())}))),(t=>{const e=e=>l(((t,e,n)=>{const o=s(t);return((t,e)=>t.startsWith(e))(e,t)?[e[o],y((r=e,l=o+1,r.slice(l,void 0)))]:void 0;var r,l})(x,e.data),(([e,n])=>{"s"==e&&t(void 0,(()=>n))}));return n.addEventListener(k,e),e}),(t=>{n.removeEventListener(k,t)}),u)};export{D as createPartyKitPersister};
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=e=>typeof e,t=e(
|
|
1
|
+
const e=e=>typeof e,t="",n=e(t),r="t",l=(e,t)=>e.startsWith(t),s=Promise,i=e=>null==e,a=(e,t,n)=>i(e)?null==n?void 0:n():t(e),o=(e,t,n)=>e.slice(t,n),u=e=>e.length,c=(e,t)=>e.map(t),h=(e,...t)=>e.push(...t),d=Object,v=(e=[])=>d.fromEntries(e),f=(e,t)=>c(d.entries(e),(([e,n])=>t(n,e))),y=(e,t,n)=>(((e,t)=>!i(((e,t)=>a(e,(e=>e[t])))(e,t)))(e,t)||(e[t]=n()),e[t]),p=e=>JSON.stringify(e,((e,t)=>t instanceof Map?d.fromEntries([...t]):t)),g=JSON.parse,S=(t,r,l)=>t+r+(e(l)==n?l:p(l)),m=(e,t,n)=>{const r=u(e);return l(t,e)?[t[r],(n?g:String)(o(t,r+1))]:void 0},w=(e,t)=>((e,t)=>null==e?void 0:e.forEach(t))(e,((e,n)=>t(n,e)));var P=(e,t,n)=>new Promise(((r,l)=>{var s=e=>{try{a(n.next(e))}catch(e){l(e)}},i=e=>{try{a(n.throw(e))}catch(e){l(e)}},a=e=>e.done?r(e.value):Promise.resolve(e.value).then(s,i);a((n=n.apply(e,t)).next())}));const x="hasStore",D=v(c(["Origin","Methods","Headers"],(e=>["Access-Control-Allow-"+e,"*"]))),R=e=>P(void 0,null,(function*(){var n;return yield e.party.storage.get((null!=(n=e.config.storagePrefix)?n:t)+x)})),b=(e,n,a,o)=>P(void 0,null,(function*(){var c;const d=e.party.storage,v=null!=(c=e.config.storagePrefix)?c:t,y=[d.put(v+x,1)],p=[];f(n[0],((t,n)=>i(t)?!a&&e.canDelTable(n,o)&&((e,...t)=>e.unshift(...t))(p,C(v,r,n)):e.canSetTable(n,a,o)&&f(t,((t,l)=>i(t)?!a&&e.canDelRow(n,l,o)&&h(p,C(v,r,n,l)):e.canSetRow(n,l,a,o)&&f(t,((t,s)=>i(t)?!a&&e.canDelCell(n,l,s,o)&&h(y,d.delete(C(v,r,n,l,s))):e.canSetCell(n,l,s,t,a,o)&&h(y,d.put(C(v,r,n,l,s),t)))))))),f(n[1],((t,n)=>i(t)?!a&&e.canDelValue(n,o)&&h(y,d.delete(v+"v"+n)):e.canSetValue(n,t,a,o)&&h(y,d.put(v+"v"+n,t)))),0!=u(p)&&w(yield d.list(),(e=>p.every((t=>!l(e,t)||h(y,d.delete(e))&&0)))),yield(e=>{return t=function*(){return s.all(e)},new Promise(((e,n)=>{var r=e=>{try{s(t.next(e))}catch(e){n(e)}},l=e=>{try{s(t.throw(e))}catch(e){n(e)}},s=t=>t.done?e(t.value):Promise.resolve(t.value).then(r,l);s((t=t.apply(void 0,null)).next())}));var t})(y)})),C=(e,t,...n)=>S(e,t,o(p(n),1,-1)),T=(e,t,n=null)=>P(void 0,null,(function*(){var r;return new Response(n,{status:t,headers:null!=(r=e.config.responseHeaders)?r:D})}));class O{constructor(e){this.party=e,this.config={}}onRequest(e){return P(this,null,(function*(){var n;const l=null!=(n=this.config.storePath)?n:"/store";if(new URL(e.url).pathname.endsWith(l)){const n=yield R(this),l=yield e.text();return"PUT"==e.method?n?T(this,205):(yield b(this,g(l),!0,e),T(this,201)):T(this,200,n?p(yield(s=this,P(void 0,null,(function*(){var e;const n={},l={},i=null!=(e=s.config.storagePrefix)?e:t;return w(yield s.party.storage.list(),((e,t)=>a(m(i,e),(([e,s])=>{if(e==r){const[e,r,l]=g("["+s+"]");y(y(n,e,v),r,v)[l]=t}else"v"==e&&(l[s]=t)})))),[n,l]})))):t)}var s;return T(this,404)}))}onMessage(e,n){return P(this,null,(function*(){var r;const l=null!=(r=this.config.messagePrefix)?r:t;yield a(m(l,e,1),(e=>P(this,[e],(function*([e,t]){"s"==e&&(yield R(this))&&(yield b(this,t,!1,n),this.party.broadcast(S(l,"s",t)))}))))}))}canSetTable(e,t,n){return!0}canDelTable(e,t){return!0}canSetRow(e,t,n,r){return!0}canDelRow(e,t,n){return!0}canSetCell(e,t,n,r,l,s){return!0}canDelCell(e,t,n,r){return!0}canSetValue(e,t,n,r){return!0}canDelValue(e,t){return!0}}export{O as TinyBasePartyKitServer};
|
|
Binary file
|