Skip to content

Commit baad65b

Browse files
committed
[demos] Fix ESM version ranges
1 parent 48469c8 commit baad65b

File tree

78 files changed

+264
-263
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+264
-263
lines changed

docs/demos/car-analysis/article.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"tinybase/ui-react": "https://esm.sh/[email protected]/ui-react",
55
"tinybase/ui-react-dom": "https://esm.sh/[email protected]/ui-react-dom",
66
"tinybase/ui-react-inspector": "https://esm.sh/[email protected]/ui-react-inspector",
7-
"react": "https://esm.sh/[email protected]",
8-
"react/jsx-runtime": "https://esm.sh/[email protected]/jsx-runtime",
9-
"react-dom/client": "https://esm.sh/[email protected]/client"
7+
"react": "https://esm.sh/react@^19.0.0",
8+
"react/jsx-runtime": "https://esm.sh/react@^19.0.0/jsx-runtime",
9+
"react-dom/client": "https://esm.sh/react-dom@^19.0.0/client"
1010
}
1111
}</script><style>#loading{animation:spin 1s infinite linear;height:2rem;margin:40vh auto;width:2rem}#loading::before{content:url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" height="2rem" viewBox="0 0 100 100"><path d="M50 10A40 40 0 1 1 10 50" stroke="black" fill="none" stroke-width="4" /></svg>')}@keyframes spin{from{transform:rotate(0)}to{transform:rotate(360deg)}}body{display:flex;height:100vh}aside{background:#ddd;flex:0;padding:.5rem .5rem 0}main{background:#fff;flex:1;max-height:100vh;padding:.5rem}input{height:1.5rem;margin:0 .25rem 0 0;vertical-align:bottom}hr{margin:.5rem 0 .1rem}table{width:100%;table-layout:fixed;font-size:inherit;line-height:inherit;border-collapse:collapse;align-self:flex-start;margin:.5rem}table caption{text-align:left;height:1.75rem}table caption button{border:0;margin-right:.25rem}table td,table th{overflow:hidden;white-space:nowrap;text-overflow:ellipsis}table th{padding:.25rem;cursor:pointer;border:solid #ddd;border-width:1px 0;text-align:left}table td{border-bottom:1px solid #eee}table td span{border-left:2px solid transparent;padding:.25rem;line-height:1.75rem}svg{stroke:#666;stroke-width:1;fill:#333}svg text{stroke:#fff;stroke-width:4;paint-order:stroke;font-size:12}svg path{fill:none}svg circle{stroke-width:2;fill:#fff;opacity:0}svg circle+text{text-anchor:middle;display:none}svg circle:hover{opacity:1}svg circle:hover+text{display:block}.MPG{stroke-width:2;stroke:#ffb300;border-color:#ffb300;fill:#ffb300}.Cylinders{stroke-width:2;stroke:#803e75;border-color:#803e75;fill:#803e75}.Displacement{stroke-width:2;stroke:#ff6800;border-color:#ff6800;fill:#ff6800}.Horsepower{stroke-width:2;stroke:#a6bdd7;border-color:#a6bdd7;fill:#a6bdd7}.Weight{stroke-width:2;stroke:#c10020;border-color:#c10020;fill:#c10020}.Acceleration{stroke-width:2;stroke:#98ce62;border-color:#98ce62;fill:#98ce62}select{border:1px solid #ccc;display:block;font:inherit;letter-spacing:inherit;width:10rem}select option{border-left:2px solid transparent}@font-face{font-family:Inter;src:url(https://tinybase.org/fonts/inter.woff2) format('woff2')}*{box-sizing:border-box}body{color:#333;font-family:Inter,sans-serif;letter-spacing:-.04rem;font-size:.8rem;line-height:1.4rem;margin:0;user-select:none}</style></head><body></body><script type="module">import{Fragment as C,jsx as e,jsxs as b}from"react/jsx-runtime";import{useCallback as A,useEffect as G,useMemo as R,useRef as O,useState as y}from"react";import{createRoot as T}from"react-dom/client";import{createQueries as D,createStore as L}from"tinybase";import{Provider as N,useCreateQueries as k,useCreateStore as P,useQueries as q,useResultCell as H,useResultSortedRowIds as _,useResultTable as j}from"tinybase/ui-react";import{ResultSortedTableInHtmlTable as Q}from"tinybase/ui-react-dom";import{Inspector as B}from"tinybase/ui-react-inspector";const F=["Manufacturer","Name","Year","Region"],Y=["MPG","Cylinders","Displacement","Horsepower","Weight","Acceleration"],I={Maximum:"max",Average:"avg",Minimum:"min"},w=11,M=5,z=/^[\d\.]+$/,$=s=>Math.round(s*100)/100,U=()=>{const s=P(L),a=k(s,D),[t,o]=y(!0);return R(async()=>{await X(s),o(!1)},[]),b(N,{store:s,queries:a,children:[t?e(W,{}):e(V,{}),e(B,{})]})},W=()=>e("div",{id:"loading"});addEventListener("load",()=>T(document.body).render(e(U,{})));const X=async s=>{const a=(await(await fetch("https://tinybase.org/assets/cars.tsv")).text()).split(`
1212
`),t=a.shift().split(&quot; &quot;);s.transaction(()=&gt;a.forEach((o,i)=&gt;{const n=o.split(&quot; &quot;);n.length==t.length&amp;&amp;n.forEach((c,p)=&gt;{c!=&quot;&quot;&amp;&amp;(z.test(c)&amp;&amp;(c=parseFloat(c)),s.setCell(&quot;cars&quot;,i,t[p],c))})}))},V=()=&gt;{const[s,a]=y([&quot;Manufacturer&quot;]),[t,o]=y([&quot;MPG&quot;,&quot;Horsepower&quot;]),[i,n]=y(&quot;Average&quot;),[c,p]=y(!1),h=J(s,t,i);return b(C,{children:[b(&quot;aside&quot;,{children:[e(&quot;b&quot;,{children:&quot;Dimensions&quot;}),e(S,{options:F,selected:s,onOptionsChange:a}),e(&quot;hr&quot;,{}),e(&quot;b&quot;,{children:&quot;Measures&quot;}),e(S,{options:Y,selected:t,onOptionsChange:o}),e(&quot;hr&quot;,{}),e(&quot;b&quot;,{children:&quot;Aggregate&quot;}),e(S,{options:Object.keys(I),selected:[i],onOptionsChange:n,multiple:!1}),e(&quot;hr&quot;,{}),e(&quot;input&quot;,{id:&quot;showTable&quot;,type:&quot;checkbox&quot;,checked:c,onChange:A(({target:d})=&gt;p(d.checked),[])}),e(&quot;label&quot;,{for:&quot;showTable&quot;,children:&quot;Show table&quot;}),e(&quot;br&quot;,{}),e(&quot;small&quot;,{children:e(&quot;a&quot;,{href:&quot;https://github.com/vega/vega-datasets/blob/next/data/cars.json&quot;,children:&quot;Source&quot;})})]}),c?e(K,{queryId:h,columns:[...s,...t]}):e(ee,{queryId:h,dimensions:s,measures:t})]})},J=(s,a,t)=&gt;R(()=&gt;(q().setQueryDefinition(&quot;query&quot;,&quot;cars&quot;,({select:o,group:i})=&gt;{s.forEach(n=&gt;o(n)),a.forEach(n=&gt;{o(n),i(n,I[t])})}),&quot;query&quot;),[s,a,t]),K=({queryId:s,columns:a})=&gt;e(Q,{queryId:s,sortOnClick:!0,paginator:!0,limit:10,idColumn:!1,customCells:R(()=&gt;Object.fromEntries(a.map(t=&gt;[t,{component:Z}])),[...a])}),Z=({queryId:s,rowId:a,cellId:t})=&gt;{const o=H(s,a,t);return e(&quot;span&quot;,{className:t,children:Number.isFinite(o)?$(o):o})},ee=({queryId:s,dimensions:a,measures:t})=&gt;{const o=O(null),[{width:i=0,height:n=0},c]=y({});G(()=&gt;{const r=new ResizeObserver(([{contentRect:u}])=&gt;c(u));return r.observe(o.current),()=&gt;r.disconnect()},[o]);const[p,h,d]=te(s,a,t),[l,m,x,v,E]=se(i,n,p,d);return i==0||n==0?e(&quot;main&quot;,{ref:o}):e(&quot;main&quot;,{ref:o,children:b(&quot;svg&quot;,{xmlns:&quot;http://www.w3.org/2000/svg&quot;,viewBox:`0 0 ${i} ${n}`,children:[e(&quot;path&quot;,{d:`M${l(0)} ${m(0)}H${l(E)}`}),e(C,{children:x.map((r,u)=&gt;{const f=l(u)-w/2,g=m(0)+M;return r&amp;&amp;e(&quot;text&quot;,{transform:`translate(${f} ${g}) rotate(90)`,children:r},u)})}),e(C,{children:v.map(r=&gt;{const u=l(0)-M,f=m(r)+w/2;return e(&quot;text&quot;,{transform:`translate(${u} ${f})`,&quot;text-anchor&quot;:&quot;end&quot;,children:r},r)})}),h.map((r,u)=&gt;b(&quot;g&quot;,{className:t[u],children:[e(&quot;path&quot;,{d:r.map((f,g)=&gt;`${g==0?&quot;M&quot;:&quot;L&quot;}${l(g)} ${m(f)}`).join(&quot;&quot;)}),r.map((f,g)=&gt;b(C,{children:[e(&quot;circle&quot;,{cx:l(g),cy:m(f),r:M}),b(&quot;text&quot;,{x:l(g),y:m(f)-w,children:[p[g],&quot; &quot;,t[u],&quot;: &quot;,$(f)]})]}))]},u))]})})},te=(s,a,t)=&gt;{const o=j(s),i=_(s,t[0]??void 0);return R(()=&gt;{const n=[1],c=[],p=t.map(()=&gt;[]);return i.forEach(h=&gt;{const d=o[h];c.push(a.map(l=&gt;d[l]).join(&quot;, &quot;)),t.forEach((l,m)=&gt;{n.push(d[l]),p[m].push(d[l])})}),[c,p,Math.max(...n)]},[o,i,t,a])},se=(s,a,t,o)=&gt;R(()=&gt;{const i=a/4,n=s/15,c=s-n-M,p=a-i-M,h=t.length-1,d=t.map((r,u)=&gt;u%Math.ceil(w*h/c)==0?r:null),l=Math.pow(10,Math.floor(Math.log10(o))),m=Math.ceil(o/l)*l,x=Math.ceil(o/l),v=x&lt;=2?5:x&lt;=5?2:1,E=Array(v*x+1).fill().map((r,u)=&gt;u*l/v);return[r=&gt;n+r*c/h,r=&gt;M+p-r*p/m,d,E,h,m]},[s,a,t,o]),S=({options:s,selected:a,onOptionsChange:t,multiple:o=!0})=&gt;{const i=A(({target:n})=&gt;t(o?[...n.selectedOptions].map(c=&gt;c.value):n.value),[t]);return e(&quot;select&quot;,{multiple:o,size:s.length,onChange:i,children:s.map(n=&gt;e(&quot;option&quot;,{value:n,selected:a.includes(n),className:n,children:n}))})};&lt;/script&gt;&lt;/html&gt;"></iframe><p>In this demo, we build an app that showcases the query capabilities of TinyBase v2.0, grouping and sorting dimensional data for lightweight analytical usage.</p><p>The data from this demo is derived from <code>cars.json</code> in the <a href="https://github.com/vega/vega-datasets">Vega datasets</a> - thank you <a href="https://idl.cs.washington.edu/">UW Interactive Data Lab</a>!</p><h3 id="an-overview-of-the-data">An Overview Of The Data</h3><p>Before looking at code, let&#x27;s familiarize ourselves with the data used in this application.</p><p>The raw data is loaded from a TSV file into one single <a href="/api/store/type-aliases/store/table/"><code>Table</code></a> object: <code>cars</code>, and comprises almost 400 records of cars made in the 1970s and 1980s.</p><p>For each, the data includes the manufacturer, the car name, year, and region. These <a href="/api/store/type-aliases/store/cell/"><code>Cell</code></a> values are &#x27;dimensions&#x27; with which the data can be grouped.</p><p>Each record also includes a number of quantitative fields, including the car&#x27;s miles-per-gallon (MPG), the number of cylinders, their displacement, its horsepower, weight, and acceleration. These <a href="/api/store/type-aliases/store/cell/"><code>Cell</code></a> values are &#x27;measures&#x27; which can be aggregated together - in this basic app, to find their average, maximum, or minimum.</p><p>The app is oriented around one single query. As the user picks different dimensions or measures in the app&#x27;s sidebar, that query is re-run and the results (either in graphical or tabular form) reactively update immediately.</p><h3 id="boilerplate">Boilerplate</h3><p>First, we create the import aliases for TinyBase and React modules we&#x27;ll need:</p><pre><code><span class="tag"><span class="tag"><span class="punctuation">&lt;</span>script</span> <span class="attr-name">type</span><span class="attr-value"><span class="punctuation">=</span><span class="punctuation">"</span>importmap<span class="punctuation">"</span></span><span class="punctuation">></span></span><span class="script"><span class="language-javascript">
@@ -16,9 +16,9 @@
1616
<span class="string-property">"tinybase/ui-react"</span><span class="operator">:</span> <span class="string">"https://esm.sh/[email protected]/ui-react"</span><span class="punctuation">,</span>
1717
<span class="string-property">"tinybase/ui-react-dom"</span><span class="operator">:</span> <span class="string">"https://esm.sh/[email protected]/ui-react-dom"</span><span class="punctuation">,</span>
1818
<span class="string-property">"tinybase/ui-react-inspector"</span><span class="operator">:</span> <span class="string">"https://esm.sh/[email protected]/ui-react-inspector"</span><span class="punctuation">,</span>
19-
<span class="string-property">"react"</span><span class="operator">:</span> <span class="string">"https://esm.sh/[email protected]"</span><span class="punctuation">,</span>
20-
<span class="string-property">"react/jsx-runtime"</span><span class="operator">:</span> <span class="string">"https://esm.sh/[email protected]/jsx-runtime"</span><span class="punctuation">,</span>
21-
<span class="string-property">"react-dom/client"</span><span class="operator">:</span> <span class="string">"https://esm.sh/[email protected]/client"</span>
19+
<span class="string-property">"react"</span><span class="operator">:</span> <span class="string">"https://esm.sh/react@^19.0.0"</span><span class="punctuation">,</span>
20+
<span class="string-property">"react/jsx-runtime"</span><span class="operator">:</span> <span class="string">"https://esm.sh/react@^19.0.0/jsx-runtime"</span><span class="punctuation">,</span>
21+
<span class="string-property">"react-dom/client"</span><span class="operator">:</span> <span class="string">"https://esm.sh/react-dom@^19.0.0/client"</span>
2222
<span class="punctuation">}</span>
2323
<span class="punctuation">}</span>
2424
</span></span><span class="tag"><span class="tag"><span class="punctuation">&lt;/</span>script</span><span class="punctuation">></span></span>

0 commit comments

Comments
 (0)