tinybase 2.0.0-beta.3 → 2.0.0-beta.5
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/checkpoints.d.ts +1 -1
- package/lib/checkpoints.js +1 -1
- package/lib/checkpoints.js.gz +0 -0
- package/lib/debug/checkpoints.d.ts +1 -1
- package/lib/debug/checkpoints.js +19 -7
- package/lib/debug/indexes.js +18 -7
- package/lib/debug/metrics.js +18 -7
- package/lib/debug/persisters.d.ts +1 -1
- package/lib/debug/queries.d.ts +93 -83
- package/lib/debug/queries.js +29 -29
- package/lib/debug/relationships.d.ts +1 -1
- package/lib/debug/relationships.js +18 -7
- package/lib/debug/store.js +42 -22
- package/lib/debug/tinybase.js +72 -51
- package/lib/debug/ui-react.d.ts +30 -9
- package/lib/indexes.js +1 -1
- package/lib/indexes.js.gz +0 -0
- package/lib/metrics.js +1 -1
- package/lib/metrics.js.gz +0 -0
- package/lib/persisters.d.ts +1 -1
- package/lib/queries.d.ts +93 -83
- package/lib/queries.js +1 -1
- package/lib/queries.js.gz +0 -0
- package/lib/relationships.d.ts +1 -1
- package/lib/relationships.js +1 -1
- package/lib/relationships.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/ui-react.d.ts +30 -9
- package/lib/umd/checkpoints.js +1 -1
- package/lib/umd/checkpoints.js.gz +0 -0
- package/lib/umd/indexes.js +1 -1
- package/lib/umd/indexes.js.gz +0 -0
- package/lib/umd/metrics.js +1 -1
- package/lib/umd/metrics.js.gz +0 -0
- package/lib/umd/queries.js +1 -1
- package/lib/umd/queries.js.gz +0 -0
- package/lib/umd/relationships.js +1 -1
- package/lib/umd/relationships.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/package.json +20 -19
- package/readme.md +11 -11
package/lib/debug/ui-react.d.ts
CHANGED
|
@@ -14,10 +14,11 @@
|
|
|
14
14
|
* @see Building UIs With Metrics guide
|
|
15
15
|
* @see Building UIs With Indexes guide
|
|
16
16
|
* @see Building UIs With Relationships guide
|
|
17
|
+
* @see Building UIs With Queries guide
|
|
17
18
|
* @see Building UIs With Checkpoints guide
|
|
18
19
|
* @see Countries demo
|
|
19
20
|
* @see Todo App demos
|
|
20
|
-
* @see
|
|
21
|
+
* @see Drawing demo
|
|
21
22
|
* @packageDocumentation
|
|
22
23
|
* @module ui-react
|
|
23
24
|
*/
|
|
@@ -154,6 +155,7 @@ export type RelationshipsOrRelationshipsId = Relationships | Id;
|
|
|
154
155
|
* parameter or a prop, allowing you to pass in either the Store or its Id.
|
|
155
156
|
*
|
|
156
157
|
* @category Identity
|
|
158
|
+
* @since v2.0.0
|
|
157
159
|
*/
|
|
158
160
|
export type QueriesOrQueriesId = Queries | Id;
|
|
159
161
|
|
|
@@ -2187,6 +2189,7 @@ export function useRowIdsListener(
|
|
|
2187
2189
|
* // -> 0
|
|
2188
2190
|
* ```
|
|
2189
2191
|
* @category Store hooks
|
|
2192
|
+
* @since v2.0.0
|
|
2190
2193
|
*/
|
|
2191
2194
|
export function useSortedRowIdsListener(
|
|
2192
2195
|
tableId: Id,
|
|
@@ -4236,7 +4239,7 @@ export function useLinkedRowIdsListener(
|
|
|
4236
4239
|
* // -> '<span>brown</span>'
|
|
4237
4240
|
* ```
|
|
4238
4241
|
* @category Queries hooks
|
|
4239
|
-
* @since v2.0.0
|
|
4242
|
+
* @since v2.0.0
|
|
4240
4243
|
*/
|
|
4241
4244
|
export function useCreateQueries(
|
|
4242
4245
|
store: Store,
|
|
@@ -4304,6 +4307,7 @@ export function useCreateQueries(
|
|
|
4304
4307
|
* // -> '<span>0</span>'
|
|
4305
4308
|
* ```
|
|
4306
4309
|
* @category Queries hooks
|
|
4310
|
+
* @since v2.0.0
|
|
4307
4311
|
*/
|
|
4308
4312
|
export function useQueries(id?: Id): Queries | undefined;
|
|
4309
4313
|
|
|
@@ -4420,6 +4424,7 @@ export function useQueries(id?: Id): Queries | undefined;
|
|
|
4420
4424
|
* // -> '<span>{"fido":{"color":"brown"},"cujo":{"color":"black"}}</span>'
|
|
4421
4425
|
* ```
|
|
4422
4426
|
* @category Queries hooks
|
|
4427
|
+
* @since v2.0.0
|
|
4423
4428
|
*/
|
|
4424
4429
|
export function useResultTable(
|
|
4425
4430
|
queryId: Id,
|
|
@@ -4540,6 +4545,7 @@ export function useResultTable(
|
|
|
4540
4545
|
* // -> '<span>["fido","cujo"]</span>'
|
|
4541
4546
|
* ```
|
|
4542
4547
|
* @category Queries hooks
|
|
4548
|
+
* @since v2.0.0
|
|
4543
4549
|
*/
|
|
4544
4550
|
export function useResultRowIds(
|
|
4545
4551
|
queryId: Id,
|
|
@@ -4688,6 +4694,7 @@ export function useResultRowIds(
|
|
|
4688
4694
|
* // -> '<span>["cujo","fido"]</span>'
|
|
4689
4695
|
* ```
|
|
4690
4696
|
* @category Queries hooks
|
|
4697
|
+
* @since v2.0.0
|
|
4691
4698
|
*/
|
|
4692
4699
|
export function useResultSortedRowIds(
|
|
4693
4700
|
queryId: Id,
|
|
@@ -4815,6 +4822,7 @@ export function useResultSortedRowIds(
|
|
|
4815
4822
|
* // -> '<span>{"color":"brown"}</span>'
|
|
4816
4823
|
* ```
|
|
4817
4824
|
* @category Queries hooks
|
|
4825
|
+
* @since v2.0.0
|
|
4818
4826
|
*/
|
|
4819
4827
|
export function useResultRow(
|
|
4820
4828
|
queryId: Id,
|
|
@@ -4945,6 +4953,7 @@ export function useResultRow(
|
|
|
4945
4953
|
* // -> '<span>["species","color"]</span>'
|
|
4946
4954
|
* ```
|
|
4947
4955
|
* @category Queries hooks
|
|
4956
|
+
* @since v2.0.0
|
|
4948
4957
|
*/
|
|
4949
4958
|
export function useResultCellIds(
|
|
4950
4959
|
queryId: Id,
|
|
@@ -5071,6 +5080,7 @@ export function useResultCellIds(
|
|
|
5071
5080
|
* // -> '<span>brown</span>'
|
|
5072
5081
|
* ```
|
|
5073
5082
|
* @category Queries hooks
|
|
5083
|
+
* @since v2.0.0
|
|
5074
5084
|
*/
|
|
5075
5085
|
export function useResultCell(
|
|
5076
5086
|
queryId: Id,
|
|
@@ -5147,6 +5157,7 @@ export function useResultCell(
|
|
|
5147
5157
|
* // -> 0
|
|
5148
5158
|
* ```
|
|
5149
5159
|
* @category Queries hooks
|
|
5160
|
+
* @since v2.0.0
|
|
5150
5161
|
*/
|
|
5151
5162
|
export function useResultTableListener(
|
|
5152
5163
|
queryId: IdOrNull,
|
|
@@ -5223,6 +5234,7 @@ export function useResultTableListener(
|
|
|
5223
5234
|
* // -> 0
|
|
5224
5235
|
* ```
|
|
5225
5236
|
* @category Queries hooks
|
|
5237
|
+
* @since v2.0.0
|
|
5226
5238
|
*/
|
|
5227
5239
|
export function useResultRowIdsListener(
|
|
5228
5240
|
queryId: IdOrNull,
|
|
@@ -5306,6 +5318,7 @@ export function useResultRowIdsListener(
|
|
|
5306
5318
|
* // -> 0
|
|
5307
5319
|
* ```
|
|
5308
5320
|
* @category Queries hooks
|
|
5321
|
+
* @since v2.0.0
|
|
5309
5322
|
*/
|
|
5310
5323
|
export function useResultSortedRowIdsListener(
|
|
5311
5324
|
queryId: Id,
|
|
@@ -5392,6 +5405,7 @@ export function useResultSortedRowIdsListener(
|
|
|
5392
5405
|
* // -> 0
|
|
5393
5406
|
* ```
|
|
5394
5407
|
* @category Queries hooks
|
|
5408
|
+
* @since v2.0.0
|
|
5395
5409
|
*/
|
|
5396
5410
|
export function useResultRowListener(
|
|
5397
5411
|
queryId: IdOrNull,
|
|
@@ -5475,6 +5489,7 @@ export function useResultRowListener(
|
|
|
5475
5489
|
* // -> 0
|
|
5476
5490
|
* ```
|
|
5477
5491
|
* @category Queries hooks
|
|
5492
|
+
* @since v2.0.0
|
|
5478
5493
|
*/
|
|
5479
5494
|
export function useResultCellIdsListener(
|
|
5480
5495
|
queryId: IdOrNull,
|
|
@@ -5560,6 +5575,7 @@ export function useResultCellIdsListener(
|
|
|
5560
5575
|
* // -> 0
|
|
5561
5576
|
* ```
|
|
5562
5577
|
* @category Queries hooks
|
|
5578
|
+
* @since v2.0.0
|
|
5563
5579
|
*/
|
|
5564
5580
|
export function useResultCellListener(
|
|
5565
5581
|
queryId: IdOrNull,
|
|
@@ -7283,8 +7299,8 @@ export type ForwardCheckpointsProps = {
|
|
|
7283
7299
|
|
|
7284
7300
|
/**
|
|
7285
7301
|
* ProviderProps props are used with the Provider component, so that Store
|
|
7286
|
-
* Metrics, Indexes, Relationships, and Checkpoints objects can be
|
|
7287
|
-
* the context of an application and used throughout.
|
|
7302
|
+
* Metrics, Indexes, Relationships, Queries, and Checkpoints objects can be
|
|
7303
|
+
* passed into the context of an application and used throughout.
|
|
7288
7304
|
*
|
|
7289
7305
|
* One of each type of object can be provided as a default within the context.
|
|
7290
7306
|
* Additionally, multiple of each type of object can be provided in an Id-keyed
|
|
@@ -7335,12 +7351,12 @@ export type ProviderProps = {
|
|
|
7335
7351
|
readonly relationshipsById?: {[relationshipsId: Id]: Relationships};
|
|
7336
7352
|
/**
|
|
7337
7353
|
* A default single Queries object that will be available within the Provider
|
|
7338
|
-
* context.
|
|
7354
|
+
* context, since v2.0.0.
|
|
7339
7355
|
*/
|
|
7340
7356
|
readonly queries?: Queries;
|
|
7341
7357
|
/**
|
|
7342
7358
|
* An object containing multiple Queries objects that will be available within
|
|
7343
|
-
* the Provider context by their Id.
|
|
7359
|
+
* the Provider context by their Id, since v2.0.0.
|
|
7344
7360
|
*/
|
|
7345
7361
|
readonly queriesById?: {[queriesId: Id]: Queries};
|
|
7346
7362
|
/**
|
|
@@ -7367,9 +7383,9 @@ export type ComponentReturnType = ReactElement<any, any> | null;
|
|
|
7367
7383
|
* The Provider component is used to wrap part of an application in a context
|
|
7368
7384
|
* that provides default objects to be used by hooks and components within.
|
|
7369
7385
|
*
|
|
7370
|
-
* Store, Metrics, Indexes, Relationships, and Checkpoints objects can
|
|
7371
|
-
* into the context of an application and used throughout. One of each
|
|
7372
|
-
* object can be provided as a default within the context. Additionally,
|
|
7386
|
+
* Store, Metrics, Indexes, Relationships, Queries, and Checkpoints objects can
|
|
7387
|
+
* be passed into the context of an application and used throughout. One of each
|
|
7388
|
+
* type of object can be provided as a default within the context. Additionally,
|
|
7373
7389
|
* multiple of each type of object can be provided in an Id-keyed map to the
|
|
7374
7390
|
* `___ById` props.
|
|
7375
7391
|
*
|
|
@@ -7792,6 +7808,7 @@ export function RowView(props: RowProps): ComponentReturnType;
|
|
|
7792
7808
|
* // -> '<div><span>felix: cat</span><span><b>fido</b>: dog</span></div>'
|
|
7793
7809
|
* ```
|
|
7794
7810
|
* @category Store components
|
|
7811
|
+
* @since v2.0.0
|
|
7795
7812
|
*/
|
|
7796
7813
|
export function SortedTableView(props: SortedTableProps): ComponentReturnType;
|
|
7797
7814
|
|
|
@@ -8888,6 +8905,7 @@ export function LinkedRowsView(props: LinkedRowsProps): ComponentReturnType;
|
|
|
8888
8905
|
* // -> '<span></span>'
|
|
8889
8906
|
* ```
|
|
8890
8907
|
* @category Queries components
|
|
8908
|
+
* @since v2.0.0
|
|
8891
8909
|
*/
|
|
8892
8910
|
export function ResultCellView(props: ResultCellProps): ComponentReturnType;
|
|
8893
8911
|
|
|
@@ -9034,6 +9052,7 @@ export function ResultCellView(props: ResultCellProps): ComponentReturnType;
|
|
|
9034
9052
|
* // -> '<div><span><b>species</b>: dog</span><span>color: brown</span></div>'
|
|
9035
9053
|
* ```
|
|
9036
9054
|
* @category Queries components
|
|
9055
|
+
* @since v2.0.0
|
|
9037
9056
|
*/
|
|
9038
9057
|
export function ResultRowView(props: ResultRowProps): ComponentReturnType;
|
|
9039
9058
|
|
|
@@ -9171,6 +9190,7 @@ export function ResultRowView(props: ResultRowProps): ComponentReturnType;
|
|
|
9171
9190
|
* // -> '<div><span>felix: black</span><span><b>fido</b>: brown</span></div>'
|
|
9172
9191
|
* ```
|
|
9173
9192
|
* @category Queries components
|
|
9193
|
+
* @since v2.0.0
|
|
9174
9194
|
*/
|
|
9175
9195
|
export function ResultSortedTableView(
|
|
9176
9196
|
props: ResultSortedTableProps,
|
|
@@ -9295,6 +9315,7 @@ export function ResultSortedTableView(
|
|
|
9295
9315
|
* // -> '<div><span><b>fido</b>: brown</span><span>felix: black</span></div>'
|
|
9296
9316
|
* ```
|
|
9297
9317
|
* @category Queries components
|
|
9318
|
+
* @since v2.0.0
|
|
9298
9319
|
*/
|
|
9299
9320
|
export function ResultTableView(props: ResultTableProps): ComponentReturnType;
|
|
9300
9321
|
|
package/lib/indexes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=e=>typeof e,t=e(""),n=(e,t)=>((e,t)=>e.every(t))(e,((n,s)=>0==s||t(e[s-1],n)<=0)),s=(e,t)=>e.sort(t),
|
|
1
|
+
const e=e=>typeof e,t=e(""),n=(e,t)=>((e,t)=>e.every(t))(e,((n,s)=>0==s||t(e[s-1],n)<=0)),s=(e,t)=>e.sort(t),r=(e,t)=>e.forEach(t),o=e=>e.length,c=(e,...t)=>e.push(...t),l=e=>null==e,d=(e,t,n)=>l(e)?n?.():t(e),i=(e,t)=>e?.has(t)??!1,a=e=>l(e)||0==(e=>e.size)(e),u=e=>[...e?.values()??[]],h=e=>e.clear(),f=(e,t)=>e?.forEach(t),I=(e,t)=>e?.delete(t),g=e=>new Map(e),S=e=>[...e?.keys()??[]],w=(e,t)=>e?.get(t),L=(e,t)=>f(e,((e,n)=>t(n,e))),v=(e,t,n)=>l(n)?(I(e,t),e):e?.set(t,n),x=(e,t,n)=>(i(e,t)||v(e,t,n()),w(e,t)),p=(e,t,n,s,r=0)=>d((n?x:w)(e,t[r],r>o(t)-2?n:g),(c=>{if(r>o(t)-2)return s?.(c)&&v(e,t[r]),c;const l=p(c,t,n,s,r+1);return a(c)&&v(e,t[r]),l})),E=e=>new Set(e),R=(e,t)=>e?.add(t),b=(e,t,n)=>{const s=e.hasRow,c=g(),p=g(),b=g(),y=g(),T=g(),k=(t,n,...s)=>{const o=x(T,t,E);return r(s,(t=>R(o,t)&&n&&e.callListener(t))),s},z=(t,...n)=>d(w(T,t),(s=>{r(0==o(n)?u(s):n,(t=>{e.delListener(t),I(s,t)})),a(s)&&v(T,t)})),C=(e,n)=>{v(c,e,n),i(p,e)||(v(p,e,t()),v(b,e,g()),v(y,e,g()))},D=e=>{v(c,e),v(p,e),v(b,e),v(y,e),z(e)};return[()=>e,()=>S(c),e=>L(p,e),e=>i(p,e),e=>w(c,e),e=>w(p,e),(e,t)=>v(p,e,t),C,(t,o,c,d,a)=>{C(t,o);const u=g(),I=g(),S=w(b,t),x=w(y,t),p=t=>{const r=n=>e.getCell(o,t,n),c=w(S,t),i=s(o,t)?n(d(r,t)):void 0;if(c!=i&&v(u,t,[c,i]),!l(a)){const e=w(x,t),n=s(o,t)?a(r,t):void 0;e!=n&&v(I,t,n)}},E=e=>{c((()=>{f(u,(([,e],t)=>v(S,t,e))),f(I,((e,t)=>v(x,t,e)))}),u,I,S,x,e),h(u),h(I)};L(S,p),e.hasTable(o)&&r(e.getRowIds(o),(e=>{i(S,e)||p(e)})),E(!0),z(t),k(t,0,e.addRowListener(o,null,((e,t,n)=>p(n))),e.addTableListener(o,(()=>E())))},D,()=>L(T,D),k,z]},y=(n,s)=>e(n)==t?e=>e(n):n??(()=>s??""),T=(e,t)=>e<t?-1:1,k=/^\d+$/,z=e=>{let t;const[n,s]=(()=>{const e=[];let t=0;return[()=>e.shift()??""+t++,t=>{k.test(t)&&o(e)<1e3&&c(e,t)}]})(),i=g();return[(s,r,o)=>{t??=e();const c=n();return v(i,c,[s,r,o]),R(p(r,o??[""],E),c),c},(e,n,...s)=>r(((e,t=[""])=>{const n=[],s=(e,l)=>l==o(t)?c(n,e):null===t[l]?f(e,(e=>s(e,l+1))):r([t[l],null],(t=>s(w(e,t),l+1)));return s(e,0),n})(e,n),(e=>f(e,(e=>w(i,e)[0](t,...n??[],...s))))),e=>d(w(i,e),(([,t,n])=>(p(t,n??[""],void 0,(t=>(I(t,e),a(t)?1:0))),v(i,e),s(e),n))),(e,n,s)=>d(w(i,e),(([e,,c=[]])=>{const d=(...i)=>{const a=o(i);a==o(c)?e(t,...i,...s(i)):l(c[a])?r(n[a](...i),(e=>d(...i,e))):d(...i,c[a])};d()}))]},C=Object.freeze,D=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((e=>{const t=g(),r=g(),[o,c,h,x,p,k,D,,M,j,O]=b(e,g,(e=>l(e)?"":e+"")),[W,$,m]=z((()=>A)),q=(t,n,s)=>{const r=p(t);f(s,((t,s)=>n(s,(n=>f(t,(t=>n(t,(n=>e.forEachCell(r,t,n)))))))))},A={setIndexDefinition:(e,o,c,u,h,S=T)=>{const x=l(h)?void 0:([e],[t])=>h(e,t);return M(e,o,((o,c,h,p,b,y)=>{let T=0;const z=E(),C=E(),M=k(e);if(f(c,(([e,t],n)=>{l(e)||(R(z,e),d(w(M,e),(t=>{I(t,n),a(t)&&(v(M,e),T=1)}))),l(t)||(R(z,t),i(M,t)||(v(M,t,E()),T=1),R(w(M,t),n),l(u)||R(C,t))})),o(),a(b)||(y?L(M,(e=>R(C,e))):L(h,(e=>d(w(p,e),(e=>R(C,e))))),f(C,(e=>{const t=(t,n)=>S(w(b,t),w(b,n),e),r=[...w(M,e)];n(r,t)||(v(M,e,E(s(r,t))),R(z,e))}))),(T||y)&&!l(x)){const t=[...M];n(t,x)||(D(e,g(s(t,x))),T=1)}T&&$(t,[e]),f(z,(t=>$(r,[e,t])))}),y(c),d(u,y)),A},delIndexDefinition:e=>(j(e),A),getStore:o,getIndexIds:c,forEachIndex:e=>h(((t,n)=>e(t,(e=>q(t,e,n))))),forEachSlice:(e,t)=>q(e,t,k(e)),hasIndex:x,hasSlice:(e,t)=>i(k(e),t),getTableId:p,getSliceIds:e=>S(k(e)),getSliceRowIds:(e,t)=>u(w(k(e),t)),addSliceIdsListener:(e,n)=>W(n,t,[e]),addSliceRowIdsListener:(e,t,n)=>W(n,r,[e,t]),delListener:e=>(m(e),A),destroy:O,getListenerStats:()=>({})};return C(A)}));export{D as createIndexes};
|
package/lib/indexes.js.gz
CHANGED
|
Binary file
|
package/lib/metrics.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const e=e=>typeof e,t=e(""),n=e(e),r=(e,t)=>e.forEach(t),s=e=>o(e,((e,t)=>e+t),0),i=e=>e.length,o=(e,t,n)=>e.reduce(t,n),c=(e,...t)=>e.push(...t),a=Math.max,d=Math.min,l=isFinite,u=e=>null==e,h=(e,t,n)=>u(e)?n?.():t(e),
|
|
1
|
+
const e=e=>typeof e,t=e(""),n=e(e),r=(e,t)=>e.forEach(t),s=e=>o(e,((e,t)=>e+t),0),i=e=>e.length,o=(e,t,n)=>e.reduce(t,n),c=(e,...t)=>e.push(...t),a=Math.max,d=Math.min,l=isFinite,u=e=>null==e,h=(e,t,n)=>u(e)?n?.():t(e),f=()=>{},g=e=>e.size,v=(e,t)=>e?.has(t)??!1,M=e=>u(e)||0==g(e),L=e=>[...e?.values()??[]],m=e=>e.clear(),w=(e,t)=>e?.forEach(t),p=(e,t)=>e?.delete(t),b=e=>new Map(e),x=(e,t)=>e?.get(t),y=(e,t)=>w(e,((e,n)=>t(n,e))),E=(e,t,n)=>u(n)?(p(e,t),e):e?.set(t,n),I=(e,t,n)=>(v(e,t)||E(e,t,n()),x(e,t)),R=(e,t,n,r,s=0)=>h((n?I:x)(e,t[s],s>i(t)-2?n:b),(o=>{if(s>i(t)-2)return r?.(o)&&E(e,t[s]),o;const c=R(o,t,n,r,s+1);return M(o)&&E(e,t[s]),c})),S=b([["avg",[(e,t)=>s(e)/t,(e,t,n)=>e+(t-e)/(n+1),(e,t,n)=>e+(e-t)/(n-1),(e,t,n,r)=>e+(t-n)/r]],["max",[e=>a(...e),(e,t)=>a(t,e),(e,t)=>t==e?void 0:e,(e,t,n)=>n==e?void 0:a(t,e)]],["min",[e=>d(...e),(e,t)=>d(t,e),(e,t)=>t==e?void 0:e,(e,t,n)=>n==e?void 0:d(t,e)]],["sum",[e=>s(e),(e,t)=>e+t,(e,t)=>e-t,(e,t,n)=>e-n+t]]]),T=e=>new Set(e),k=(e,t)=>e?.add(t),z=(e,t,n)=>{const s=e.hasRow,o=b(),c=b(),a=b(),d=b(),l=b(),f=(t,n,...s)=>{const i=I(l,t,T);return r(s,(t=>k(i,t)&&n&&e.callListener(t))),s},g=(t,...n)=>h(x(l,t),(s=>{r(0==i(n)?L(s):n,(t=>{e.delListener(t),p(s,t)})),M(s)&&E(l,t)})),R=(e,n)=>{E(o,e,n),v(c,e)||(E(c,e,t()),E(a,e,b()),E(d,e,b()))},S=e=>{E(o,e),E(c,e),E(a,e),E(d,e),g(e)};return[()=>e,()=>[...o?.keys()??[]],e=>y(c,e),e=>v(c,e),e=>x(o,e),e=>x(c,e),(e,t)=>E(c,e,t),R,(t,i,o,c,l)=>{R(t,i);const h=b(),M=b(),L=x(a,t),p=x(d,t),I=t=>{const r=n=>e.getCell(i,t,n),o=x(L,t),a=s(i,t)?n(c(r,t)):void 0;if(o!=a&&E(h,t,[o,a]),!u(l)){const e=x(p,t),n=s(i,t)?l(r,t):void 0;e!=n&&E(M,t,n)}},S=e=>{o((()=>{w(h,(([,e],t)=>E(L,t,e))),w(M,((e,t)=>E(p,t,e)))}),h,M,L,p,e),m(h),m(M)};y(L,I),e.hasTable(i)&&r(e.getRowIds(i),(e=>{v(L,e)||I(e)})),S(!0),g(t),f(t,0,e.addRowListener(i,null,((e,t,n)=>I(n))),e.addTableListener(i,(()=>S())))},S,()=>y(l,S),f,g]},D=(n,r)=>e(n)==t?e=>e(n):n??(()=>r??""),N=/^\d+$/,j=e=>{let t;const[n,s]=(()=>{const e=[];let t=0;return[()=>e.shift()??""+t++,t=>{N.test(t)&&i(e)<1e3&&c(e,t)}]})(),o=b();return[(r,s,i)=>{t??=e();const c=n();return E(o,c,[r,s,i]),k(R(s,i??[""],T),c),c},(e,n,...s)=>r(((e,t=[""])=>{const n=[],s=(e,o)=>o==i(t)?c(n,e):null===t[o]?w(e,(e=>s(e,o+1))):r([t[o],null],(t=>s(x(e,t),o+1)));return s(e,0),n})(e,n),(e=>w(e,(e=>x(o,e)[0](t,...n??[],...s))))),e=>h(x(o,e),(([,t,n])=>(R(t,n??[""],void 0,(t=>(p(t,e),M(t)?1:0))),E(o,e),s(e),n))),(e,n,s)=>h(x(o,e),(([e,,o=[]])=>{const c=(...a)=>{const d=i(a);d==i(o)?e(t,...a,...s(a)):u(o[d])?r(n[d](...a),(e=>c(...a,e))):c(...a,o[d])};c()}))]},C=Object.freeze,F=(e=>{const t=new WeakMap;return n=>(t.has(n)||t.set(n,e(n)),t.get(n))})((t=>{const r=b(),[s,i,o,c,a,d,h,,v,m,p]=z(t,f,(e=>isNaN(e)||u(e)||!0===e||!1===e||""===e?void 0:1*e)),[y,E,I]=j((()=>R)),R={setMetricDefinition:(t,s,i,o,c,a,f)=>{const m=e(i)==n?[i,c,a,f]:x(S,i)??x(S,"sum");return v(t,s,((e,n,s,i,o,c)=>{const a=d(t),f=g(i);c||=u(a),e();let v=((e,t,n,r,s,i=!1)=>{if(M(n))return;const[o,c,a,d]=s;return i||=u(e),w(r,(([n,r])=>{i||(e=u(n)?c?.(e,r,t++):u(r)?a?.(e,n,t--):d?.(e,r,n,t),i||=u(e))})),i?o(L(n),g(n)):e})(a,f,i,n,m,c);l(v)||(v=void 0),v!=a&&(h(t,v),E(r,[t],v,a))}),D(o,1)),R},delMetricDefinition:e=>(m(e),R),getStore:s,getMetricIds:i,forEachMetric:o,hasMetric:c,getTableId:a,getMetric:d,addMetricListener:(e,t)=>y(t,r,[e]),delListener:e=>(I(e),R),destroy:p,getListenerStats:()=>({})};return C(R)}));export{F as createMetrics};
|
package/lib/metrics.js.gz
CHANGED
|
Binary file
|