tinybase 8.4.0-beta.0 → 8.4.0-beta.1

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.
Files changed (31) hide show
  1. package/@types/ui-solid-dom/index.d.ts +2013 -0
  2. package/@types/ui-solid-dom/with-schemas/index.d.ts +2064 -0
  3. package/@types/ui-solid-inspector/index.d.ts +73 -0
  4. package/@types/ui-solid-inspector/with-schemas/index.d.ts +73 -0
  5. package/min/ui-solid/index.js +1 -1
  6. package/min/ui-solid/index.js.gz +0 -0
  7. package/min/ui-solid/with-schemas/index.js +1 -1
  8. package/min/ui-solid/with-schemas/index.js.gz +0 -0
  9. package/min/ui-solid-dom/index.js +1 -0
  10. package/min/ui-solid-dom/index.js.gz +0 -0
  11. package/min/ui-solid-dom/with-schemas/index.js +1 -0
  12. package/min/ui-solid-dom/with-schemas/index.js.gz +0 -0
  13. package/min/ui-solid-inspector/index.js +1 -0
  14. package/min/ui-solid-inspector/index.js.gz +0 -0
  15. package/min/ui-solid-inspector/with-schemas/index.js +1 -0
  16. package/min/ui-solid-inspector/with-schemas/index.js.gz +0 -0
  17. package/min/ui-svelte-inspector/index.js +1 -1
  18. package/min/ui-svelte-inspector/index.js.gz +0 -0
  19. package/min/ui-svelte-inspector/with-schemas/index.js +1 -1
  20. package/min/ui-svelte-inspector/with-schemas/index.js.gz +0 -0
  21. package/package.json +73 -1
  22. package/readme.md +14 -14
  23. package/releases.md +98 -62
  24. package/ui-solid/index.js +208 -104
  25. package/ui-solid/with-schemas/index.js +208 -104
  26. package/ui-solid-dom/index.js +1575 -0
  27. package/ui-solid-dom/with-schemas/index.js +1575 -0
  28. package/ui-solid-inspector/index.js +5621 -0
  29. package/ui-solid-inspector/with-schemas/index.js +5621 -0
  30. package/ui-svelte-inspector/index.js +6 -2
  31. package/ui-svelte-inspector/with-schemas/index.js +6 -2
@@ -0,0 +1,1575 @@
1
+ import {
2
+ createContext,
3
+ createEffect,
4
+ createMemo,
5
+ createRenderEffect,
6
+ createSignal,
7
+ onCleanup,
8
+ untrack,
9
+ useContext,
10
+ } from 'solid-js';
11
+ import {
12
+ addEventListener,
13
+ className,
14
+ createComponent,
15
+ effect,
16
+ insert,
17
+ memo,
18
+ mergeProps,
19
+ setAttribute,
20
+ template,
21
+ } from 'solid-js/web';
22
+ import {CellView, ResultCellView, ValueView} from '../../ui-solid/with-schemas/index.js';
23
+
24
+ const getTypeOf = (thing) => typeof thing;
25
+ const TINYBASE = 'tinybase';
26
+ const EMPTY_STRING = '';
27
+ const DOT = '.';
28
+ const STRING = getTypeOf(EMPTY_STRING);
29
+ const BOOLEAN = getTypeOf(true);
30
+ const NUMBER = getTypeOf(0);
31
+ const FUNCTION = getTypeOf(getTypeOf);
32
+ const OBJECT = 'object';
33
+ const ARRAY = 'array';
34
+ const NULL = 'null';
35
+ const LISTENER = 'Listener';
36
+ const RESULT = 'Result';
37
+ const GET = 'get';
38
+ const SET = 'set';
39
+ const ADD = 'add';
40
+ const HAS = 'Has';
41
+ const _HAS = 'has';
42
+ const IDS = 'Ids';
43
+ const TABLE = 'Table';
44
+ const ROW = 'Row';
45
+ const ROW_COUNT = ROW + 'Count';
46
+ const ROW_IDS = ROW + IDS;
47
+ const SORTED_ROW_IDS = 'Sorted' + ROW + IDS;
48
+ const CELL = 'Cell';
49
+ const CELL_IDS = CELL + IDS;
50
+ const VALUE = 'Value';
51
+ const VALUE_IDS = VALUE + IDS;
52
+ const SLICE = 'Slice';
53
+ const REMOTE_ROW_ID = 'Remote' + ROW + 'Id';
54
+ const CURRENT_TARGET = 'currentTarget';
55
+ const _VALUE = 'value';
56
+ const EXTRA = 'extra';
57
+ const strSplit = (str, separator = EMPTY_STRING, limit) =>
58
+ str.split(separator, limit);
59
+
60
+ const getIfNotFunction = (predicate) => (value, then, otherwise) =>
61
+ predicate(value)
62
+ ? /* istanbul ignore next */
63
+ otherwise?.()
64
+ : then(value);
65
+ const GLOBAL = globalThis;
66
+ const math = Math;
67
+ const mathMin = math.min;
68
+ const isFiniteNumber = isFinite;
69
+ const isNullish = (thing) => thing == null;
70
+ const isUndefined = (thing) => thing === void 0;
71
+ const isNull = (thing) => thing === null;
72
+ const isTrue = (thing) => thing === true;
73
+ const isFalse = (thing) => thing === false;
74
+ const ifNotNullish = getIfNotFunction(isNullish);
75
+ const ifNotUndefined = getIfNotFunction(isUndefined);
76
+ const isTypeStringOrBoolean = (type) => type == STRING || type == BOOLEAN;
77
+ const isString = (thing) => getTypeOf(thing) == STRING;
78
+ const isFunction = (thing) => getTypeOf(thing) == FUNCTION;
79
+ const isArray = (thing) => Array.isArray(thing);
80
+ const size = (arrayOrString) => arrayOrString.length;
81
+ const getUndefined = () => void 0;
82
+ const getArg = (value) => value;
83
+ const tryReturn = (tryF, catchReturn) => {
84
+ try {
85
+ return tryF();
86
+ } catch {
87
+ /* istanbul ignore next */
88
+ return catchReturn;
89
+ }
90
+ };
91
+
92
+ const arrayEvery = (array, cb) => array.every(cb);
93
+ const arrayIsEqual = (array1, array2) =>
94
+ size(array1) === size(array2) &&
95
+ arrayEvery(array1, (value1, index) => array2[index] === value1);
96
+ const arrayOrValueEqual = (value1, value2) =>
97
+ isArray(value1) && isArray(value2)
98
+ ? arrayIsEqual(value1, value2)
99
+ : value1 === value2;
100
+ const arrayMap = (array, cb) => array.map(cb);
101
+
102
+ const object = Object;
103
+ const getPrototypeOf = (obj) => object.getPrototypeOf(obj);
104
+ const objEntries = object.entries;
105
+ const isObject = (obj) =>
106
+ !isNullish(obj) &&
107
+ ifNotNullish(
108
+ getPrototypeOf(obj),
109
+ (objPrototype) =>
110
+ objPrototype == object.prototype ||
111
+ isNullish(getPrototypeOf(objPrototype)),
112
+
113
+ /* istanbul ignore next */
114
+ () => true,
115
+ );
116
+ const objIds = object.keys;
117
+ const objNew = (entries = []) => object.fromEntries(entries);
118
+ const objGet = (obj, id) => ifNotUndefined(obj, (obj2) => obj2[id]);
119
+ const objToArray = (obj, cb) =>
120
+ arrayMap(objEntries(obj), ([id, value]) => cb(value, id));
121
+ const objMap = (obj, cb) =>
122
+ objNew(objToArray(obj, (value, id) => [id, cb(value, id)]));
123
+ const objSize = (obj) => size(objIds(obj));
124
+
125
+ /* istanbul ignore next */
126
+ const objIsEqual = (
127
+ obj1,
128
+ obj2,
129
+ isEqual = (value1, value2) => value1 === value2,
130
+ ) => {
131
+ const entries1 = objEntries(obj1);
132
+ return (
133
+ size(entries1) === objSize(obj2) &&
134
+ arrayEvery(entries1, ([index, value1]) =>
135
+ isObject(value1)
136
+ ? /* istanbul ignore next */
137
+ isObject(obj2[index])
138
+ ? objIsEqual(obj2[index], value1, isEqual)
139
+ : false
140
+ : isEqual(value1, obj2[index]),
141
+ )
142
+ );
143
+ };
144
+
145
+ const getValue = (value) => (isFunction(value) ? value() : value);
146
+ const getProps = (getProps2, ...ids) =>
147
+ isUndefined(getProps2) ? {} : getProps2(...ids);
148
+ const getRelationshipsStoreTableIds = (relationships, relationshipId) => [
149
+ relationships,
150
+ relationships?.getStore(),
151
+ relationships?.getLocalTableId(relationshipId),
152
+ relationships?.getRemoteTableId(relationshipId),
153
+ ];
154
+ const getIndexStoreTableId = (indexes, indexId) => [
155
+ indexes,
156
+ indexes?.getStore(),
157
+ indexes?.getTableId(indexId),
158
+ ];
159
+
160
+ const TINYBASE_CONTEXT = TINYBASE + '_uisc';
161
+ const EMPTY_CONTEXT = () => [];
162
+ const EMPTY_CONTEXT_VALUE = {value: EMPTY_CONTEXT};
163
+ const GLOBAL_CONTEXT = GLOBAL;
164
+ const Context = GLOBAL_CONTEXT[TINYBASE_CONTEXT]
165
+ ? /* istanbul ignore next */
166
+ GLOBAL_CONTEXT[TINYBASE_CONTEXT]
167
+ : (GLOBAL_CONTEXT[TINYBASE_CONTEXT] = createContext(EMPTY_CONTEXT_VALUE));
168
+ const useThing = (id, offset) => {
169
+ const contextValue = useContext(Context)?.value ?? EMPTY_CONTEXT;
170
+ return () => {
171
+ const resolvedContextValue = contextValue();
172
+ const resolvedId = getValue(id);
173
+ return isUndefined(resolvedId)
174
+ ? resolvedContextValue[offset * 2]
175
+ : isString(resolvedId)
176
+ ? objGet(resolvedContextValue[offset * 2 + 1], resolvedId)
177
+ : resolvedId;
178
+ };
179
+ };
180
+ const useThingOrThingById = (thingOrThingId, offset) => {
181
+ const thing = useThing(thingOrThingId, offset);
182
+ return () => {
183
+ const resolvedThingOrThingId = getValue(thingOrThingId);
184
+ return isUndefined(resolvedThingOrThingId) ||
185
+ isString(resolvedThingOrThingId)
186
+ ? thing()
187
+ : resolvedThingOrThingId;
188
+ };
189
+ };
190
+
191
+ const OFFSET_STORE = 0;
192
+ const OFFSET_INDEXES = 2;
193
+ const OFFSET_RELATIONSHIPS = 3;
194
+ const OFFSET_QUERIES = 4;
195
+
196
+ const EMPTY_ARRAY = [];
197
+ const DEFAULTS = [
198
+ {},
199
+ [],
200
+ [EMPTY_ARRAY, void 0, EMPTY_ARRAY],
201
+ {},
202
+ void 0,
203
+ void 0,
204
+ false,
205
+ 0,
206
+ ];
207
+ const IS_EQUALS = [
208
+ objIsEqual,
209
+ arrayIsEqual,
210
+ (
211
+ [backwardIds1, currentId1, forwardIds1],
212
+ [backwardIds2, currentId2, forwardIds2],
213
+ ) =>
214
+ currentId1 === currentId2 &&
215
+ arrayIsEqual(backwardIds1, backwardIds2) &&
216
+ arrayIsEqual(forwardIds1, forwardIds2),
217
+ (paramValues1, paramValues2) =>
218
+ objIsEqual(paramValues1, paramValues2, arrayOrValueEqual),
219
+ arrayOrValueEqual,
220
+ ];
221
+ const isEqual = (thing1, thing2) => thing1 === thing2;
222
+ const getThing = (thing) => (isFunction(thing) ? thing() : thing);
223
+ const EMPTY_LISTENER_ARG_GETTERS = [];
224
+ const addAndDelListener = (thing, listenable, ...args) => {
225
+ const listenerId = thing?.[ADD + listenable + LISTENER]?.(...args);
226
+ return () => thing?.delListener?.(listenerId);
227
+ };
228
+ const useListenable = (
229
+ listenable,
230
+ thing,
231
+ returnType,
232
+ listenerArgGetters = EMPTY_LISTENER_ARG_GETTERS,
233
+ ) => {
234
+ const [result, setResult] = createSignal(DEFAULTS[returnType]);
235
+ const getListenerArguments = () => arrayMap(listenerArgGetters, getThing);
236
+ const getResult = () =>
237
+ getThing(thing)?.[
238
+ (returnType == 6 /* Boolean */ ? _HAS : GET) + listenable
239
+ ]?.(...getListenerArguments()) ?? DEFAULTS[returnType];
240
+ const updateResult = () => {
241
+ const nextResult = getResult();
242
+ const prevResult = untrack(result);
243
+ setResult(() =>
244
+ !(IS_EQUALS[returnType] ?? isEqual)(nextResult, prevResult)
245
+ ? nextResult
246
+ : prevResult,
247
+ );
248
+ };
249
+ createRenderEffect(() => {
250
+ const resolvedThing = getThing(thing);
251
+ const listenerArguments = getListenerArguments();
252
+ updateResult();
253
+ const cleanup = addAndDelListener(
254
+ resolvedThing,
255
+ (returnType == 6 /* Boolean */ ? HAS : EMPTY_STRING) + listenable,
256
+ ...listenerArguments,
257
+ updateResult,
258
+ );
259
+ onCleanup(cleanup);
260
+ });
261
+ return result;
262
+ };
263
+ const useSetCallback =
264
+ (storeOrQueries, settable, get, then = getUndefined, methodPrefix, ...args) =>
265
+ (parameter) =>
266
+ ifNotUndefined(getThing(storeOrQueries), (obj) =>
267
+ ifNotUndefined(get(parameter, obj), (thing) =>
268
+ then(
269
+ obj[methodPrefix + settable](
270
+ ...argsOrGetArgs(args, obj, parameter),
271
+ thing,
272
+ ),
273
+ thing,
274
+ ),
275
+ ),
276
+ );
277
+ const useStoreSetCallback = (storeOrStoreId, settable, get, then, ...args) =>
278
+ useSetCallback(
279
+ useStoreOrStoreById(storeOrStoreId),
280
+ settable,
281
+ get,
282
+ then,
283
+ SET,
284
+ ...args,
285
+ );
286
+ const argsOrGetArgs = (args, store, parameter) =>
287
+ arrayMap(args, (arg) =>
288
+ isFunction(arg)
289
+ ? arg.length == 0
290
+ ? getThing(arg)
291
+ : arg(parameter, store)
292
+ : arg,
293
+ );
294
+ const useSortedRowIdsImpl = (
295
+ tableId,
296
+ cellId,
297
+ descending,
298
+ offset,
299
+ limit,
300
+ storeOrStoreId,
301
+ ) =>
302
+ useListenable(
303
+ SORTED_ROW_IDS,
304
+ useStoreOrStoreById(storeOrStoreId),
305
+ 1 /* Array */,
306
+ [tableId, cellId, descending, offset, limit],
307
+ );
308
+ const useStoreOrStoreById = (storeOrStoreId) =>
309
+ useThingOrThingById(storeOrStoreId, OFFSET_STORE);
310
+ const useTableCellIds = (tableId, storeOrStoreId) =>
311
+ useListenable(
312
+ TABLE + CELL_IDS,
313
+ useStoreOrStoreById(storeOrStoreId),
314
+ 1 /* Array */,
315
+ [tableId],
316
+ );
317
+ const useRowCount = (tableId, storeOrStoreId) =>
318
+ useListenable(
319
+ ROW_COUNT,
320
+ useStoreOrStoreById(storeOrStoreId),
321
+ 7 /* Number */,
322
+ [tableId],
323
+ );
324
+ const useRowIds = (tableId, storeOrStoreId) =>
325
+ useListenable(ROW_IDS, useStoreOrStoreById(storeOrStoreId), 1 /* Array */, [
326
+ tableId,
327
+ ]);
328
+ const useSortedRowIds = (
329
+ tableIdOrArgs,
330
+ cellIdOrStoreOrStoreId,
331
+ descending,
332
+ offset,
333
+ limit,
334
+ storeOrStoreId,
335
+ ) =>
336
+ isObject(tableIdOrArgs)
337
+ ? useSortedRowIdsImpl(
338
+ tableIdOrArgs.tableId,
339
+ tableIdOrArgs.cellId,
340
+ tableIdOrArgs.descending ?? false,
341
+ tableIdOrArgs.offset ?? 0,
342
+ tableIdOrArgs.limit,
343
+ cellIdOrStoreOrStoreId,
344
+ )
345
+ : useSortedRowIdsImpl(
346
+ tableIdOrArgs,
347
+ cellIdOrStoreOrStoreId,
348
+ descending,
349
+ offset,
350
+ limit,
351
+ storeOrStoreId,
352
+ );
353
+ const useCell = (tableId, rowId, cellId, storeOrStoreId) =>
354
+ useListenable(
355
+ CELL,
356
+ useStoreOrStoreById(storeOrStoreId),
357
+ 5 /* CellOrValue */,
358
+ [tableId, rowId, cellId],
359
+ );
360
+ const useCellState = (tableId, rowId, cellId, storeOrStoreId) => [
361
+ useCell(tableId, rowId, cellId, storeOrStoreId),
362
+ useSetCellCallback(tableId, rowId, cellId, getArg, storeOrStoreId),
363
+ ];
364
+ const useValueIds = (storeOrStoreId) =>
365
+ useListenable(VALUE_IDS, useStoreOrStoreById(storeOrStoreId), 1 /* Array */);
366
+ const useValue = (valueId, storeOrStoreId) =>
367
+ useListenable(
368
+ VALUE,
369
+ useStoreOrStoreById(storeOrStoreId),
370
+ 5 /* CellOrValue */,
371
+ [valueId],
372
+ );
373
+ const useValueState = (valueId, storeOrStoreId) => [
374
+ useValue(valueId, storeOrStoreId),
375
+ useSetValueCallback(valueId, getArg, storeOrStoreId),
376
+ ];
377
+ const useSetCellCallback = (
378
+ tableId,
379
+ rowId,
380
+ cellId,
381
+ getCell,
382
+ storeOrStoreId,
383
+ then,
384
+ ) =>
385
+ useStoreSetCallback(
386
+ storeOrStoreId,
387
+ CELL,
388
+ getCell,
389
+ then,
390
+ tableId,
391
+ rowId,
392
+ cellId,
393
+ );
394
+ const useSetValueCallback = (valueId, getValue, storeOrStoreId, then) =>
395
+ useStoreSetCallback(storeOrStoreId, VALUE, getValue, then, valueId);
396
+ const useIndexesOrIndexesById = (indexesOrIndexesId) =>
397
+ useThingOrThingById(indexesOrIndexesId, OFFSET_INDEXES);
398
+ const useSliceRowIds = (indexId, sliceId, indexesOrIndexesId) =>
399
+ useListenable(
400
+ SLICE + ROW_IDS,
401
+ useIndexesOrIndexesById(indexesOrIndexesId),
402
+ 1 /* Array */,
403
+ [indexId, sliceId],
404
+ );
405
+ const useRelationshipsOrRelationshipsById = (relationshipsOrRelationshipsId) =>
406
+ useThingOrThingById(relationshipsOrRelationshipsId, OFFSET_RELATIONSHIPS);
407
+ const useRemoteRowId = (
408
+ relationshipId,
409
+ localRowId,
410
+ relationshipsOrRelationshipsId,
411
+ ) =>
412
+ useListenable(
413
+ REMOTE_ROW_ID,
414
+ useRelationshipsOrRelationshipsById(relationshipsOrRelationshipsId),
415
+ 5 /* CellOrValue */,
416
+ [relationshipId, localRowId],
417
+ );
418
+ const useQueriesOrQueriesById = (queriesOrQueriesId) =>
419
+ useThingOrThingById(queriesOrQueriesId, OFFSET_QUERIES);
420
+ const useResultTableCellIds = (queryId, queriesOrQueriesId) =>
421
+ useListenable(
422
+ RESULT + TABLE + CELL_IDS,
423
+ useQueriesOrQueriesById(queriesOrQueriesId),
424
+ 1 /* Array */,
425
+ [queryId],
426
+ );
427
+ const useResultRowCount = (queryId, queriesOrQueriesId) =>
428
+ useListenable(
429
+ RESULT + ROW_COUNT,
430
+ useQueriesOrQueriesById(queriesOrQueriesId),
431
+ 7 /* Number */,
432
+ [queryId],
433
+ );
434
+ const useResultRowIds = (queryId, queriesOrQueriesId) =>
435
+ useListenable(
436
+ RESULT + ROW_IDS,
437
+ useQueriesOrQueriesById(queriesOrQueriesId),
438
+ 1 /* Array */,
439
+ [queryId],
440
+ );
441
+ const useResultSortedRowIds = (
442
+ queryId,
443
+ cellId,
444
+ descending,
445
+ offset = 0,
446
+ limit,
447
+ queriesOrQueriesId,
448
+ ) =>
449
+ useListenable(
450
+ RESULT + SORTED_ROW_IDS,
451
+ useQueriesOrQueriesById(queriesOrQueriesId),
452
+ 1 /* Array */,
453
+ [queryId, cellId, descending, offset, limit],
454
+ );
455
+
456
+ const jsonString = JSON.stringify;
457
+ const jsonParse = JSON.parse;
458
+
459
+ const getCellOrValueType = (cellOrValue) => {
460
+ if (isNull(cellOrValue)) {
461
+ return NULL;
462
+ }
463
+ if (isArray(cellOrValue)) {
464
+ return ARRAY;
465
+ }
466
+ if (isObject(cellOrValue)) {
467
+ return OBJECT;
468
+ }
469
+ const type = getTypeOf(cellOrValue);
470
+ return isTypeStringOrBoolean(type) ||
471
+ (type == NUMBER && isFiniteNumber(cellOrValue))
472
+ ? type
473
+ : void 0;
474
+ };
475
+ const getTypeCase = (
476
+ type,
477
+ stringCase,
478
+ numberCase,
479
+ booleanCase,
480
+ objectCase,
481
+ arrayCase,
482
+ ) =>
483
+ type == STRING
484
+ ? stringCase
485
+ : type == NUMBER
486
+ ? numberCase
487
+ : type == BOOLEAN
488
+ ? booleanCase
489
+ : type == OBJECT
490
+ ? objectCase
491
+ : type == ARRAY
492
+ ? arrayCase
493
+ : null;
494
+
495
+ const getStoreCellComponentProps = (store, tableId) => ({
496
+ store,
497
+ tableId,
498
+ });
499
+ const getQueriesCellComponentProps = (queries, queryId) => ({
500
+ queries,
501
+ queryId,
502
+ });
503
+ const getCallbackOrUndefined = (callback, test) => (test ? callback : void 0);
504
+ const getParams = (...args) => args;
505
+ const useCells = (defaultCellIds, customCells, defaultCellComponent) =>
506
+ // eslint-disable-next-line solid/reactivity
507
+ createMemo(() => {
508
+ const customCellIds = getValue(customCells);
509
+ const cellIds = getValue(customCellIds) ?? getValue(defaultCellIds);
510
+ const component = defaultCellComponent();
511
+ return objMap(
512
+ isArray(cellIds)
513
+ ? objNew(arrayMap(cellIds, (cellId) => [cellId, cellId]))
514
+ : cellIds,
515
+ (labelOrCustomCell, cellId) => ({
516
+ ...{
517
+ label: cellId,
518
+ component,
519
+ },
520
+ ...(isString(labelOrCustomCell)
521
+ ? {
522
+ label: labelOrCustomCell,
523
+ }
524
+ : labelOrCustomCell),
525
+ }),
526
+ );
527
+ });
528
+
529
+ var _tmpl$$4 = /*#__PURE__*/ template(`<td>`),
530
+ _tmpl$2$4 = /*#__PURE__*/ template(`<th>`);
531
+ const UP_ARROW = '\u2191';
532
+ const DOWN_ARROW = '\u2193';
533
+ const EDITABLE = 'editable';
534
+ const extraRowCells = (extraRowCells2 = [], extraRowCellProps) =>
535
+ arrayMap(getValue(extraRowCells2) ?? [], (extraRowCell) => {
536
+ const Component = extraRowCell.component;
537
+ return (() => {
538
+ var _el$ = _tmpl$$4();
539
+ className(_el$, EXTRA);
540
+ insert(_el$, createComponent(Component, extraRowCellProps));
541
+ return _el$;
542
+ })();
543
+ });
544
+ const extraHeaders = (extraCells = []) =>
545
+ arrayMap(getValue(extraCells) ?? [], (extraCell) =>
546
+ (() => {
547
+ var _el$2 = _tmpl$2$4();
548
+ className(_el$2, EXTRA);
549
+ insert(_el$2, () => extraCell.label);
550
+ return _el$2;
551
+ })(),
552
+ );
553
+
554
+ var _tmpl$$3 = /*#__PURE__*/ template(`<th>`),
555
+ _tmpl$2$3 = /*#__PURE__*/ template(`<table><tbody>`),
556
+ _tmpl$3$2 = /*#__PURE__*/ template(`<caption>`),
557
+ _tmpl$4$2 = /*#__PURE__*/ template(`<thead><tr>`),
558
+ _tmpl$5$2 = /*#__PURE__*/ template(`<tr>`),
559
+ _tmpl$6$2 = /*#__PURE__*/ template(`<td>`),
560
+ _tmpl$7 = /*#__PURE__*/ template(`<input>`),
561
+ _tmpl$8 = /*#__PURE__*/ template(`<input type=number>`),
562
+ _tmpl$9 = /*#__PURE__*/ template(`<input type=checkbox>`),
563
+ _tmpl$0 = /*#__PURE__*/ template(`<div>`),
564
+ _tmpl$1 = /*#__PURE__*/ template(`<button>`);
565
+ const HtmlHeaderCell = (props) => {
566
+ const sortDescending = props.sort[1];
567
+ const cellId = props.cellId;
568
+ return (() => {
569
+ var _el$ = _tmpl$$3();
570
+ addEventListener(
571
+ _el$,
572
+ 'click',
573
+ getCallbackOrUndefined(() => props.onClick?.(cellId), props.onClick),
574
+ );
575
+ insert(
576
+ _el$,
577
+ () =>
578
+ isUndefined(sortDescending) || props.sort[0] != cellId
579
+ ? null
580
+ : (sortDescending ? DOWN_ARROW : UP_ARROW) + ' ',
581
+ null,
582
+ );
583
+ insert(_el$, () => props.label ?? cellId ?? EMPTY_STRING, null);
584
+ effect(() =>
585
+ className(
586
+ _el$,
587
+ isUndefined(sortDescending) || props.sort[0] != cellId
588
+ ? void 0
589
+ : `sorted ${sortDescending ? 'de' : 'a'}scending`,
590
+ ),
591
+ );
592
+ return _el$;
593
+ })();
594
+ };
595
+ const HtmlTable = (props) => {
596
+ const content = () => {
597
+ const [
598
+ cells,
599
+ cellComponentProps,
600
+ rowIds,
601
+ extraCellsBefore,
602
+ extraCellsAfter,
603
+ sortAndOffset,
604
+ handleSort,
605
+ paginatorComponent,
606
+ ] = props.params;
607
+ const sort = sortAndOffset == null ? [] : getValue(sortAndOffset);
608
+ const paginator = getValue(paginatorComponent);
609
+ return (() => {
610
+ var _el$2 = _tmpl$2$3(),
611
+ _el$3 = _el$2.firstChild;
612
+ insert(
613
+ _el$2,
614
+ paginator
615
+ ? (() => {
616
+ var _el$4 = _tmpl$3$2();
617
+ insert(_el$4, paginator);
618
+ return _el$4;
619
+ })()
620
+ : null,
621
+ _el$3,
622
+ );
623
+ insert(
624
+ _el$2,
625
+ (() => {
626
+ var _c$ = memo(() => props.headerRow === false);
627
+ return () =>
628
+ _c$()
629
+ ? null
630
+ : (() => {
631
+ var _el$5 = _tmpl$4$2(),
632
+ _el$6 = _el$5.firstChild;
633
+ insert(_el$6, () => extraHeaders(extraCellsBefore), null);
634
+ insert(
635
+ _el$6,
636
+ (() => {
637
+ var _c$2 = memo(() => props.idColumn === false);
638
+ return () =>
639
+ _c$2()
640
+ ? null
641
+ : HtmlHeaderCell({
642
+ sort,
643
+ label: 'Id',
644
+ onClick: handleSort,
645
+ });
646
+ })(),
647
+ null,
648
+ );
649
+ insert(
650
+ _el$6,
651
+ () =>
652
+ objToArray(getValue(cells), ({label}, cellId) =>
653
+ HtmlHeaderCell({
654
+ cellId,
655
+ label,
656
+ sort,
657
+ onClick: handleSort,
658
+ }),
659
+ ),
660
+ null,
661
+ );
662
+ insert(_el$6, () => extraHeaders(extraCellsAfter), null);
663
+ return _el$5;
664
+ })();
665
+ })(),
666
+ _el$3,
667
+ );
668
+ insert(_el$3, () =>
669
+ arrayMap(getValue(rowIds), (rowId) => {
670
+ const rowProps = {
671
+ ...cellComponentProps,
672
+ rowId,
673
+ };
674
+ return (() => {
675
+ var _el$7 = _tmpl$5$2();
676
+ insert(
677
+ _el$7,
678
+ () => extraRowCells(extraCellsBefore, rowProps),
679
+ null,
680
+ );
681
+ insert(
682
+ _el$7,
683
+ (() => {
684
+ var _c$3 = memo(() => !!isFalse(props.idColumn));
685
+ return () =>
686
+ _c$3()
687
+ ? null
688
+ : (() => {
689
+ var _el$8 = _tmpl$$3();
690
+ setAttribute(_el$8, 'title', rowId);
691
+ insert(_el$8, rowId);
692
+ return _el$8;
693
+ })();
694
+ })(),
695
+ null,
696
+ );
697
+ insert(
698
+ _el$7,
699
+ () =>
700
+ objToArray(
701
+ getValue(cells),
702
+ ({component: CellView, getComponentProps}, cellId) =>
703
+ (() => {
704
+ var _el$9 = _tmpl$6$2();
705
+ insert(
706
+ _el$9,
707
+ createComponent(
708
+ CellView,
709
+ mergeProps(
710
+ () => getProps(getComponentProps, rowId, cellId),
711
+ rowProps,
712
+ {
713
+ cellId: cellId,
714
+ },
715
+ ),
716
+ ),
717
+ );
718
+ return _el$9;
719
+ })(),
720
+ ),
721
+ null,
722
+ );
723
+ insert(_el$7, () => extraRowCells(extraCellsAfter, rowProps), null);
724
+ return _el$7;
725
+ })();
726
+ }),
727
+ );
728
+ effect(() => className(_el$2, props.className));
729
+ return _el$2;
730
+ })();
731
+ };
732
+ return memo(content);
733
+ };
734
+ const EditableThing = (props) => {
735
+ const [thingType, setThingType] = createSignal();
736
+ const [currentThing, setCurrentThing] = createSignal();
737
+ const [stringThing, setStringThing] = createSignal();
738
+ const [numberThing, setNumberThing] = createSignal();
739
+ const [booleanThing, setBooleanThing] = createSignal();
740
+ const [objectThing, setObjectThing] = createSignal('{}');
741
+ const [arrayThing, setArrayThing] = createSignal('[]');
742
+ const [objectClassName, setObjectClassName] = createSignal('');
743
+ const [arrayClassName, setArrayClassName] = createSignal('');
744
+ createRenderEffect(() => {
745
+ const thing = props.thing;
746
+ if (untrack(currentThing) !== thing) {
747
+ setThingType(getCellOrValueType(thing));
748
+ setCurrentThing(() => thing);
749
+ if (isObject(thing)) {
750
+ setObjectThing(jsonString(thing));
751
+ } else if (isArray(thing)) {
752
+ setArrayThing(jsonString(thing));
753
+ } else {
754
+ setStringThing(String(thing));
755
+ setNumberThing(Number(thing) || 0);
756
+ setBooleanThing(Boolean(thing));
757
+ }
758
+ }
759
+ });
760
+ const handleThingChange = (thing, setTypedThing) => {
761
+ setTypedThing(thing);
762
+ setCurrentThing(() => thing);
763
+ props.onThingChange(thing);
764
+ };
765
+ const handleJsonThingChange = (
766
+ value,
767
+ setTypedThing,
768
+ isThing,
769
+ setTypedClassName,
770
+ ) => {
771
+ setTypedThing(value);
772
+ try {
773
+ const object = jsonParse(value);
774
+ if (isThing(object)) {
775
+ setCurrentThing(() => object);
776
+ props.onThingChange(object);
777
+ setTypedClassName('');
778
+ }
779
+ } catch {
780
+ setTypedClassName('invalid');
781
+ }
782
+ };
783
+ const handleTypeChange = () => {
784
+ if (!props.hasSchema?.()) {
785
+ const nextType = getTypeCase(
786
+ thingType(),
787
+ NUMBER,
788
+ BOOLEAN,
789
+ OBJECT,
790
+ ARRAY,
791
+ STRING,
792
+ );
793
+ const thing = getTypeCase(
794
+ nextType,
795
+ stringThing(),
796
+ numberThing(),
797
+ booleanThing(),
798
+ tryReturn(() => jsonParse(objectThing()), {}),
799
+ tryReturn(() => jsonParse(arrayThing()), []),
800
+ );
801
+ setThingType(nextType);
802
+ setCurrentThing(() => thing);
803
+ props.onThingChange(thing);
804
+ }
805
+ };
806
+ const widget = () =>
807
+ getTypeCase(
808
+ thingType(),
809
+ (() => {
810
+ var _el$0 = _tmpl$7();
811
+ _el$0.addEventListener('input', (event) =>
812
+ handleThingChange(
813
+ String(event[CURRENT_TARGET][_VALUE]),
814
+ setStringThing,
815
+ ),
816
+ );
817
+ effect(() => (_el$0.value = stringThing()));
818
+ return _el$0;
819
+ })(),
820
+ (() => {
821
+ var _el$1 = _tmpl$8();
822
+ _el$1.addEventListener('input', (event) =>
823
+ handleThingChange(
824
+ Number(event[CURRENT_TARGET][_VALUE] || 0),
825
+ setNumberThing,
826
+ ),
827
+ );
828
+ effect(() => (_el$1.value = numberThing()));
829
+ return _el$1;
830
+ })(),
831
+ (() => {
832
+ var _el$10 = _tmpl$9();
833
+ _el$10.addEventListener('input', (event) =>
834
+ handleThingChange(
835
+ Boolean(event[CURRENT_TARGET].checked),
836
+ setBooleanThing,
837
+ ),
838
+ );
839
+ effect(() => (_el$10.checked = booleanThing()));
840
+ return _el$10;
841
+ })(),
842
+ (() => {
843
+ var _el$11 = _tmpl$7();
844
+ _el$11.addEventListener('input', (event) =>
845
+ handleJsonThingChange(
846
+ event[CURRENT_TARGET][_VALUE],
847
+ setObjectThing,
848
+ isObject,
849
+ setObjectClassName,
850
+ ),
851
+ );
852
+ effect(() => className(_el$11, objectClassName()));
853
+ effect(() => (_el$11.value = objectThing()));
854
+ return _el$11;
855
+ })(),
856
+ (() => {
857
+ var _el$12 = _tmpl$7();
858
+ _el$12.addEventListener('input', (event) =>
859
+ handleJsonThingChange(
860
+ event[CURRENT_TARGET][_VALUE],
861
+ setArrayThing,
862
+ isArray,
863
+ setArrayClassName,
864
+ ),
865
+ );
866
+ effect(() => className(_el$12, arrayClassName()));
867
+ effect(() => (_el$12.value = arrayThing()));
868
+ return _el$12;
869
+ })(),
870
+ );
871
+ const content = () => {
872
+ const currentWidget = widget();
873
+ return (() => {
874
+ var _el$13 = _tmpl$0();
875
+ insert(
876
+ _el$13,
877
+ (() => {
878
+ var _c$4 = memo(() => !!(props.showType !== false && currentWidget));
879
+ return () =>
880
+ _c$4()
881
+ ? (() => {
882
+ var _el$14 = _tmpl$1();
883
+ _el$14.addEventListener('click', handleTypeChange);
884
+ insert(_el$14, thingType);
885
+ effect(
886
+ (_p$) => {
887
+ var _v$ = thingType(),
888
+ _v$2 = thingType();
889
+ _v$ !== _p$.e &&
890
+ setAttribute(_el$14, 'title', (_p$.e = _v$));
891
+ _v$2 !== _p$.t && className(_el$14, (_p$.t = _v$2));
892
+ return _p$;
893
+ },
894
+ {
895
+ e: undefined,
896
+ t: undefined,
897
+ },
898
+ );
899
+ return _el$14;
900
+ })()
901
+ : null;
902
+ })(),
903
+ null,
904
+ );
905
+ insert(_el$13, currentWidget, null);
906
+ effect(() => className(_el$13, props.class));
907
+ return _el$13;
908
+ })();
909
+ };
910
+ return memo(content);
911
+ };
912
+
913
+ const EditableCellView = (props) => {
914
+ const [cell, setCell] = useCellState(
915
+ () => props.tableId,
916
+ () => props.rowId,
917
+ () => props.cellId,
918
+ () => props.store,
919
+ );
920
+ const store = useStoreOrStoreById(() => props.store);
921
+ return EditableThing({
922
+ get thing() {
923
+ return cell();
924
+ },
925
+ onThingChange: setCell,
926
+ class: props.className ?? EDITABLE + CELL,
927
+ showType: props.showType,
928
+ hasSchema: () => !!store()?.hasTablesSchema(),
929
+ });
930
+ };
931
+
932
+ const EditableValueView = (props) => {
933
+ const [value, setValue] = useValueState(
934
+ () => props.valueId,
935
+ () => props.store,
936
+ );
937
+ const store = useStoreOrStoreById(() => props.store);
938
+ return EditableThing({
939
+ get thing() {
940
+ return value();
941
+ },
942
+ onThingChange: setValue,
943
+ class: props.className ?? EDITABLE + VALUE,
944
+ showType: props.showType,
945
+ hasSchema: () => !!store()?.hasValuesSchema(),
946
+ });
947
+ };
948
+
949
+ var _tmpl$$2 = /*#__PURE__*/ template(`<tr>`),
950
+ _tmpl$2$2 = /*#__PURE__*/ template(`<th>`),
951
+ _tmpl$3$1 = /*#__PURE__*/ template(`<td>`),
952
+ _tmpl$4$1 = /*#__PURE__*/ template(`<table><tbody>`),
953
+ _tmpl$5$1 = /*#__PURE__*/ template(`<thead><tr>`),
954
+ _tmpl$6$1 = /*#__PURE__*/ template(`<th>.Id`);
955
+ const useDottedCellIds = (tableId, store) => {
956
+ const cellIds = useTableCellIds(
957
+ () => getValue(tableId),
958
+ () => getValue(store),
959
+ );
960
+ const dottedCellIds = createMemo(() =>
961
+ arrayMap(cellIds(), (cellId) => getValue(tableId) + DOT + cellId),
962
+ );
963
+ return dottedCellIds;
964
+ };
965
+ const RelationshipInHtmlRow = (props) => {
966
+ const [
967
+ idColumn,
968
+ cells,
969
+ localTableId,
970
+ remoteTableId,
971
+ relationshipId,
972
+ relationships,
973
+ store,
974
+ extraCellsBefore,
975
+ extraCellsAfter,
976
+ ] = props.params;
977
+ const remoteRowId = useRemoteRowId(
978
+ () => relationshipId,
979
+ () => props.localRowId,
980
+ () => relationships,
981
+ );
982
+ const rowProps = {
983
+ tableId: localTableId ?? '',
984
+ rowId: props.localRowId,
985
+ store,
986
+ };
987
+ return (() => {
988
+ var _el$ = _tmpl$$2();
989
+ insert(_el$, () => extraRowCells(extraCellsBefore, rowProps), null);
990
+ insert(
991
+ _el$,
992
+ (() => {
993
+ var _c$ = memo(() => !!isFalse(idColumn));
994
+ return () =>
995
+ _c$()
996
+ ? null
997
+ : [
998
+ (() => {
999
+ var _el$2 = _tmpl$2$2();
1000
+ insert(_el$2, () => props.localRowId);
1001
+ effect(() => setAttribute(_el$2, 'title', props.localRowId));
1002
+ return _el$2;
1003
+ })(),
1004
+ (() => {
1005
+ var _el$3 = _tmpl$2$2();
1006
+ insert(_el$3, remoteRowId);
1007
+ effect(() => setAttribute(_el$3, 'title', remoteRowId()));
1008
+ return _el$3;
1009
+ })(),
1010
+ ];
1011
+ })(),
1012
+ null,
1013
+ );
1014
+ insert(
1015
+ _el$,
1016
+ () =>
1017
+ objToArray(
1018
+ getValue(cells),
1019
+ ({component: CellView2, getComponentProps}, compoundCellId) => {
1020
+ const [tableId, cellId] = strSplit(compoundCellId, DOT, 2);
1021
+ const rowId =
1022
+ tableId === localTableId
1023
+ ? props.localRowId
1024
+ : tableId === remoteTableId
1025
+ ? remoteRowId()
1026
+ : void 0;
1027
+ return isUndefined(rowId)
1028
+ ? null
1029
+ : (() => {
1030
+ var _el$4 = _tmpl$3$1();
1031
+ insert(
1032
+ _el$4,
1033
+ createComponent(
1034
+ CellView2,
1035
+ mergeProps(
1036
+ () => getProps(getComponentProps, rowId, cellId),
1037
+ {
1038
+ store: store,
1039
+ tableId: tableId,
1040
+ rowId: rowId,
1041
+ cellId: cellId,
1042
+ },
1043
+ ),
1044
+ ),
1045
+ );
1046
+ return _el$4;
1047
+ })();
1048
+ },
1049
+ ),
1050
+ null,
1051
+ );
1052
+ insert(_el$, () => extraRowCells(extraCellsAfter, rowProps), null);
1053
+ return _el$;
1054
+ })();
1055
+ };
1056
+ const RelationshipInHtmlTable = (props) => {
1057
+ const resolvedRelationships = useRelationshipsOrRelationshipsById(
1058
+ () => props.relationships,
1059
+ );
1060
+ const details = createMemo(() =>
1061
+ getRelationshipsStoreTableIds(
1062
+ resolvedRelationships(),
1063
+ props.relationshipId,
1064
+ ),
1065
+ );
1066
+ const localCellIds = useDottedCellIds(
1067
+ () => details()[2],
1068
+ () => details()[1],
1069
+ );
1070
+ const remoteCellIds = useDottedCellIds(
1071
+ () => details()[3],
1072
+ () => details()[1],
1073
+ );
1074
+ const cellIds = createMemo(() => [...localCellIds(), ...remoteCellIds()]);
1075
+ const cells = useCells(
1076
+ cellIds,
1077
+ () => props.customCells,
1078
+ () => (props.editable ? EditableCellView : CellView),
1079
+ );
1080
+ const rowIds = useRowIds(
1081
+ () => details()[2],
1082
+ () => details()[1],
1083
+ );
1084
+ const content = () => {
1085
+ const [relationships, store, localTableId, remoteTableId] = details();
1086
+ const params = getParams(
1087
+ props.idColumn ?? true,
1088
+ cells,
1089
+ localTableId,
1090
+ remoteTableId,
1091
+ props.relationshipId,
1092
+ relationships,
1093
+ store,
1094
+ props.extraCellsBefore,
1095
+ props.extraCellsAfter,
1096
+ );
1097
+ return (() => {
1098
+ var _el$5 = _tmpl$4$1(),
1099
+ _el$6 = _el$5.firstChild;
1100
+ insert(
1101
+ _el$5,
1102
+ (() => {
1103
+ var _c$2 = memo(() => !!isFalse(props.headerRow));
1104
+ return () =>
1105
+ _c$2()
1106
+ ? null
1107
+ : (() => {
1108
+ var _el$7 = _tmpl$5$1(),
1109
+ _el$8 = _el$7.firstChild;
1110
+ insert(
1111
+ _el$8,
1112
+ () => extraHeaders(props.extraCellsBefore),
1113
+ null,
1114
+ );
1115
+ insert(
1116
+ _el$8,
1117
+ (() => {
1118
+ var _c$3 = memo(() => !!isFalse(props.idColumn));
1119
+ return () =>
1120
+ _c$3()
1121
+ ? null
1122
+ : [
1123
+ (() => {
1124
+ var _el$9 = _tmpl$6$1(),
1125
+ _el$0 = _el$9.firstChild;
1126
+ insert(_el$9, localTableId, _el$0);
1127
+ return _el$9;
1128
+ })(),
1129
+ (() => {
1130
+ var _el$1 = _tmpl$6$1(),
1131
+ _el$10 = _el$1.firstChild;
1132
+ insert(_el$1, remoteTableId, _el$10);
1133
+ return _el$1;
1134
+ })(),
1135
+ ];
1136
+ })(),
1137
+ null,
1138
+ );
1139
+ insert(
1140
+ _el$8,
1141
+ () =>
1142
+ objToArray(cells(), (cell) =>
1143
+ (() => {
1144
+ var _el$11 = _tmpl$2$2();
1145
+ insert(_el$11, () => cell.label);
1146
+ return _el$11;
1147
+ })(),
1148
+ ),
1149
+ null,
1150
+ );
1151
+ insert(
1152
+ _el$8,
1153
+ () => extraHeaders(props.extraCellsAfter),
1154
+ null,
1155
+ );
1156
+ return _el$7;
1157
+ })();
1158
+ })(),
1159
+ _el$6,
1160
+ );
1161
+ insert(_el$6, () =>
1162
+ arrayMap(rowIds(), (localRowId) =>
1163
+ RelationshipInHtmlRow({
1164
+ localRowId,
1165
+ params,
1166
+ }),
1167
+ ),
1168
+ );
1169
+ effect(() => className(_el$5, props.className));
1170
+ return _el$5;
1171
+ })();
1172
+ };
1173
+ return memo(content);
1174
+ };
1175
+
1176
+ var _tmpl$$1 = /*#__PURE__*/ template(`<button class=previous>←`),
1177
+ _tmpl$2$1 = /*#__PURE__*/ template(`<button class=next>→`);
1178
+ const useSortingAndPagination = (
1179
+ cellId,
1180
+ descending,
1181
+ sortOnClick,
1182
+ offset,
1183
+ limit,
1184
+ total,
1185
+ paginator,
1186
+ onChange,
1187
+ ) => {
1188
+ const [sortAndOffset, setSortAndOffset] = createSignal([
1189
+ getValue(cellId),
1190
+ !!getValue(descending),
1191
+ getValue(offset) ?? 0,
1192
+ ]);
1193
+ createEffect(() =>
1194
+ setSortAndOffset([
1195
+ getValue(cellId),
1196
+ !!getValue(descending),
1197
+ getValue(offset) ?? 0,
1198
+ ]),
1199
+ );
1200
+ const setStateAndChange = (sortAndOffset2) => {
1201
+ setSortAndOffset(sortAndOffset2);
1202
+ getValue(onChange)?.(sortAndOffset2);
1203
+ };
1204
+ const handleSort = (cellId2) => {
1205
+ if (getValue(sortOnClick)) {
1206
+ const [currentCellId, currentDescending, currentOffset] = sortAndOffset();
1207
+ setStateAndChange([
1208
+ cellId2,
1209
+ cellId2 == currentCellId ? !currentDescending : false,
1210
+ currentOffset,
1211
+ ]);
1212
+ }
1213
+ };
1214
+ const handleChangeOffset = (offset2) => {
1215
+ const [currentCellId, currentDescending] = sortAndOffset();
1216
+ setStateAndChange([currentCellId, currentDescending, offset2]);
1217
+ };
1218
+ const paginatorComponent = createMemo(() => {
1219
+ const resolvedPaginator = getValue(paginator);
1220
+ const [_, __, currentOffset] = sortAndOffset();
1221
+ const PaginatorComponent = isTrue(resolvedPaginator)
1222
+ ? SortedTablePaginator
1223
+ : resolvedPaginator;
1224
+ return isFalse(resolvedPaginator)
1225
+ ? null
1226
+ : createComponent(PaginatorComponent, {
1227
+ offset: currentOffset,
1228
+ get limit() {
1229
+ return getValue(limit);
1230
+ },
1231
+ get total() {
1232
+ return getValue(total);
1233
+ },
1234
+ onChange: handleChangeOffset,
1235
+ });
1236
+ });
1237
+ return [sortAndOffset, handleSort, paginatorComponent];
1238
+ };
1239
+ const SortedTablePaginator = (props) => {
1240
+ const content = () => {
1241
+ let offset = props.offset ?? 0;
1242
+ const limit = props.limit ?? props.total;
1243
+ if (offset > props.total || offset < 0) {
1244
+ offset = 0;
1245
+ props.onChange(0);
1246
+ }
1247
+ const singular = props.singular ?? 'row';
1248
+ const plural = props.plural ?? singular + 's';
1249
+ return [
1250
+ memo(
1251
+ () =>
1252
+ memo(() => props.total > limit)() && [
1253
+ (() => {
1254
+ var _el$ = _tmpl$$1();
1255
+ addEventListener(
1256
+ _el$,
1257
+ 'click',
1258
+ getCallbackOrUndefined(
1259
+ () => props.onChange(offset - limit),
1260
+ offset > 0,
1261
+ ),
1262
+ );
1263
+ _el$.disabled = offset == 0;
1264
+ return _el$;
1265
+ })(),
1266
+ (() => {
1267
+ var _el$2 = _tmpl$2$1();
1268
+ addEventListener(
1269
+ _el$2,
1270
+ 'click',
1271
+ getCallbackOrUndefined(
1272
+ () => props.onChange(offset + limit),
1273
+ offset + limit < props.total,
1274
+ ),
1275
+ );
1276
+ effect(() => (_el$2.disabled = offset + limit >= props.total));
1277
+ return _el$2;
1278
+ })(),
1279
+ offset + 1,
1280
+ ' to ',
1281
+ memo(() => mathMin(props.total, offset + limit)),
1282
+ ' of ',
1283
+ ],
1284
+ ),
1285
+ memo(() => props.total),
1286
+ ' ',
1287
+ memo(() => (props.total != 1 ? plural : singular)),
1288
+ ];
1289
+ };
1290
+ return memo(content);
1291
+ };
1292
+
1293
+ const ResultSortedTableInHtmlTable = (props) => {
1294
+ const [sortAndOffset, handleSort, paginatorComponent] =
1295
+ useSortingAndPagination(
1296
+ () => props.cellId,
1297
+ () => props.descending,
1298
+ () => props.sortOnClick,
1299
+ () => props.offset,
1300
+ () => props.limit,
1301
+ useResultRowCount(
1302
+ () => props.queryId,
1303
+ () => props.queries,
1304
+ ),
1305
+ () => props.paginator ?? false,
1306
+ () => props.onChange,
1307
+ );
1308
+ return HtmlTable({
1309
+ ...props,
1310
+ params: getParams(
1311
+ useCells(
1312
+ useResultTableCellIds(
1313
+ () => props.queryId,
1314
+ () => props.queries,
1315
+ ),
1316
+ () => props.customCells,
1317
+ () => ResultCellView,
1318
+ ),
1319
+ getQueriesCellComponentProps(props.queries, props.queryId),
1320
+ useResultSortedRowIds(
1321
+ () => props.queryId,
1322
+ () => sortAndOffset()[0],
1323
+ () => sortAndOffset()[1],
1324
+ () => sortAndOffset()[2],
1325
+ () => props.limit,
1326
+ () => props.queries,
1327
+ ),
1328
+ props.extraCellsBefore,
1329
+ props.extraCellsAfter,
1330
+ sortAndOffset,
1331
+ handleSort,
1332
+ paginatorComponent,
1333
+ ),
1334
+ });
1335
+ };
1336
+
1337
+ const ResultTableInHtmlTable = (props) =>
1338
+ HtmlTable({
1339
+ ...props,
1340
+ params: getParams(
1341
+ useCells(
1342
+ useResultTableCellIds(
1343
+ () => props.queryId,
1344
+ () => props.queries,
1345
+ ),
1346
+ () => props.customCells,
1347
+ () => ResultCellView,
1348
+ ),
1349
+ getQueriesCellComponentProps(props.queries, props.queryId),
1350
+ useResultRowIds(
1351
+ () => props.queryId,
1352
+ () => props.queries,
1353
+ ),
1354
+ props.extraCellsBefore,
1355
+ props.extraCellsAfter,
1356
+ ),
1357
+ });
1358
+
1359
+ const SliceInHtmlTable = (props) => {
1360
+ const resolvedIndexes = useIndexesOrIndexesById(() => props.indexes);
1361
+ const details = createMemo(() =>
1362
+ getIndexStoreTableId(resolvedIndexes(), props.indexId),
1363
+ );
1364
+ return HtmlTable({
1365
+ ...props,
1366
+ params: getParams(
1367
+ useCells(
1368
+ useTableCellIds(
1369
+ () => details()[2],
1370
+ () => details()[1],
1371
+ ),
1372
+ props.customCells,
1373
+ () => (props.editable ? EditableCellView : CellView),
1374
+ ),
1375
+ getStoreCellComponentProps(details()[1], details()[2]),
1376
+ useSliceRowIds(
1377
+ () => props.indexId,
1378
+ () => props.sliceId,
1379
+ resolvedIndexes,
1380
+ ),
1381
+ props.extraCellsBefore,
1382
+ props.extraCellsAfter,
1383
+ ),
1384
+ });
1385
+ };
1386
+
1387
+ const SortedTableInHtmlTable = (props) => {
1388
+ const [sortAndOffset, handleSort, paginatorComponent] =
1389
+ useSortingAndPagination(
1390
+ () => props.cellId,
1391
+ () => props.descending,
1392
+ () => props.sortOnClick,
1393
+ () => props.offset,
1394
+ () => props.limit,
1395
+ useRowCount(
1396
+ () => props.tableId,
1397
+ () => props.store,
1398
+ ),
1399
+ () => props.paginator ?? false,
1400
+ () => props.onChange,
1401
+ );
1402
+ return HtmlTable({
1403
+ ...props,
1404
+ params: getParams(
1405
+ useCells(
1406
+ useTableCellIds(
1407
+ () => props.tableId,
1408
+ () => props.store,
1409
+ ),
1410
+ () => props.customCells,
1411
+ () => (props.editable === true ? EditableCellView : CellView),
1412
+ ),
1413
+ getStoreCellComponentProps(props.store, props.tableId),
1414
+ useSortedRowIds(
1415
+ () => props.tableId,
1416
+ () => sortAndOffset()[0],
1417
+ () => sortAndOffset()[1],
1418
+ () => sortAndOffset()[2],
1419
+ () => props.limit,
1420
+ () => props.store,
1421
+ ),
1422
+ props.extraCellsBefore,
1423
+ props.extraCellsAfter,
1424
+ sortAndOffset,
1425
+ handleSort,
1426
+ paginatorComponent,
1427
+ ),
1428
+ });
1429
+ };
1430
+
1431
+ const TableInHtmlTable = (props) =>
1432
+ HtmlTable({
1433
+ ...props,
1434
+ params: getParams(
1435
+ useCells(
1436
+ useTableCellIds(
1437
+ () => props.tableId,
1438
+ () => props.store,
1439
+ ),
1440
+ () => props.customCells,
1441
+ () => (props.editable ? EditableCellView : CellView),
1442
+ ),
1443
+ getStoreCellComponentProps(props.store, props.tableId),
1444
+ useRowIds(
1445
+ () => props.tableId,
1446
+ () => props.store,
1447
+ ),
1448
+ props.extraCellsBefore,
1449
+ props.extraCellsAfter,
1450
+ ),
1451
+ });
1452
+
1453
+ var _tmpl$ = /*#__PURE__*/ template(`<td>`),
1454
+ _tmpl$2 = /*#__PURE__*/ template(`<table><tbody>`),
1455
+ _tmpl$3 = /*#__PURE__*/ template(`<thead><tr><th>`),
1456
+ _tmpl$4 = /*#__PURE__*/ template(`<th>Id`),
1457
+ _tmpl$5 = /*#__PURE__*/ template(`<tr><td>`),
1458
+ _tmpl$6 = /*#__PURE__*/ template(`<th>`);
1459
+ const extraValueCells = (extraValueCells2 = [], extraValueCellProps) =>
1460
+ arrayMap(getValue(extraValueCells2) ?? [], (extraValueCell) => {
1461
+ const Component = extraValueCell.component;
1462
+ return (() => {
1463
+ var _el$ = _tmpl$();
1464
+ className(_el$, EXTRA);
1465
+ insert(_el$, createComponent(Component, extraValueCellProps));
1466
+ return _el$;
1467
+ })();
1468
+ });
1469
+ const ValuesInHtmlTable = (props) => {
1470
+ const valueIds = useValueIds(() => props.store);
1471
+ return (() => {
1472
+ var _el$2 = _tmpl$2(),
1473
+ _el$3 = _el$2.firstChild;
1474
+ insert(
1475
+ _el$2,
1476
+ (() => {
1477
+ var _c$ = memo(() => props.headerRow === false);
1478
+ return () =>
1479
+ _c$()
1480
+ ? null
1481
+ : (() => {
1482
+ var _el$4 = _tmpl$3(),
1483
+ _el$5 = _el$4.firstChild,
1484
+ _el$6 = _el$5.firstChild;
1485
+ insert(
1486
+ _el$5,
1487
+ () => extraHeaders(props.extraCellsBefore),
1488
+ _el$6,
1489
+ );
1490
+ insert(
1491
+ _el$5,
1492
+ (() => {
1493
+ var _c$2 = memo(() => props.idColumn === false);
1494
+ return () => (_c$2() ? null : _tmpl$4());
1495
+ })(),
1496
+ _el$6,
1497
+ );
1498
+ insert(_el$6, VALUE);
1499
+ insert(_el$5, () => extraHeaders(props.extraCellsAfter), null);
1500
+ return _el$4;
1501
+ })();
1502
+ })(),
1503
+ _el$3,
1504
+ );
1505
+ insert(_el$3, () =>
1506
+ arrayMap(valueIds(), (valueId) => {
1507
+ const valueProps = {
1508
+ valueId,
1509
+ store: props.store,
1510
+ };
1511
+ const Value =
1512
+ props.valueComponent ??
1513
+ (getValue(props.editable) === true ? EditableValueView : ValueView);
1514
+ return (() => {
1515
+ var _el$8 = _tmpl$5(),
1516
+ _el$9 = _el$8.firstChild;
1517
+ insert(
1518
+ _el$8,
1519
+ () => extraValueCells(props.extraCellsBefore, valueProps),
1520
+ _el$9,
1521
+ );
1522
+ insert(
1523
+ _el$8,
1524
+ (() => {
1525
+ var _c$3 = memo(() => !!isFalse(props.idColumn));
1526
+ return () =>
1527
+ _c$3()
1528
+ ? null
1529
+ : (() => {
1530
+ var _el$0 = _tmpl$6();
1531
+ setAttribute(_el$0, 'title', valueId);
1532
+ insert(_el$0, valueId);
1533
+ return _el$0;
1534
+ })();
1535
+ })(),
1536
+ _el$9,
1537
+ );
1538
+ insert(
1539
+ _el$9,
1540
+ createComponent(
1541
+ Value,
1542
+ mergeProps(
1543
+ () => getProps(props.getValueComponentProps, valueId),
1544
+ valueProps,
1545
+ ),
1546
+ ),
1547
+ );
1548
+ insert(
1549
+ _el$8,
1550
+ () => extraValueCells(props.extraCellsAfter, valueProps),
1551
+ null,
1552
+ );
1553
+ return _el$8;
1554
+ })();
1555
+ }),
1556
+ );
1557
+ effect(() => className(_el$2, props.className));
1558
+ return _el$2;
1559
+ })();
1560
+ };
1561
+
1562
+ export {
1563
+ EditableCellView,
1564
+ EditableValueView,
1565
+ RelationshipInHtmlRow,
1566
+ RelationshipInHtmlTable,
1567
+ ResultSortedTableInHtmlTable,
1568
+ ResultTableInHtmlTable,
1569
+ SliceInHtmlTable,
1570
+ SortedTableInHtmlTable,
1571
+ SortedTablePaginator,
1572
+ TableInHtmlTable,
1573
+ useSortingAndPagination,
1574
+ ValuesInHtmlTable,
1575
+ };