tinybase 7.0.0-beta.1 → 7.0.0-beta.2

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 (143) hide show
  1. package/@types/mergeable-store/index.d.ts +1 -0
  2. package/@types/mergeable-store/with-schemas/index.d.ts +4 -2
  3. package/@types/omni/index.d.ts +2 -0
  4. package/@types/omni/with-schemas/index.d.ts +2 -0
  5. package/@types/persisters/index.d.ts +4 -0
  6. package/@types/persisters/persister-automerge/index.d.ts +4 -6
  7. package/@types/persisters/persister-automerge/with-schemas/index.d.ts +7 -8
  8. package/@types/persisters/persister-browser/index.d.ts +97 -6
  9. package/@types/persisters/persister-browser/with-schemas/index.d.ts +113 -6
  10. package/@types/persisters/persister-cr-sqlite-wasm/with-schemas/index.d.ts +3 -2
  11. package/@types/persisters/persister-durable-object-sql-storage/index.d.ts +2 -2
  12. package/@types/persisters/persister-durable-object-sql-storage/with-schemas/index.d.ts +1 -0
  13. package/@types/persisters/persister-durable-object-storage/index.d.ts +1 -2
  14. package/@types/persisters/persister-durable-object-storage/with-schemas/index.d.ts +3 -2
  15. package/@types/persisters/persister-electric-sql/with-schemas/index.d.ts +3 -2
  16. package/@types/persisters/persister-expo-sqlite/index.d.ts +1 -2
  17. package/@types/persisters/persister-expo-sqlite/with-schemas/index.d.ts +3 -2
  18. package/@types/persisters/persister-file/index.d.ts +1 -2
  19. package/@types/persisters/persister-file/with-schemas/index.d.ts +3 -2
  20. package/@types/persisters/persister-indexed-db/with-schemas/index.d.ts +3 -2
  21. package/@types/persisters/persister-libsql/with-schemas/index.d.ts +3 -2
  22. package/@types/persisters/persister-partykit-client/with-schemas/index.d.ts +3 -2
  23. package/@types/persisters/persister-pglite/index.d.ts +2 -2
  24. package/@types/persisters/persister-pglite/with-schemas/index.d.ts +4 -2
  25. package/@types/persisters/persister-postgres/index.d.ts +1 -2
  26. package/@types/persisters/persister-postgres/with-schemas/index.d.ts +3 -2
  27. package/@types/persisters/persister-powersync/with-schemas/index.d.ts +3 -2
  28. package/@types/persisters/persister-react-native-mmkv/index.d.ts +117 -0
  29. package/@types/persisters/persister-react-native-mmkv/with-schemas/index.d.ts +133 -0
  30. package/@types/persisters/persister-react-native-sqlite/index.d.ts +180 -0
  31. package/@types/persisters/persister-react-native-sqlite/with-schemas/index.d.ts +203 -0
  32. package/@types/persisters/persister-remote/with-schemas/index.d.ts +3 -2
  33. package/@types/persisters/persister-sqlite-bun/index.d.ts +1 -2
  34. package/@types/persisters/persister-sqlite-bun/with-schemas/index.d.ts +3 -2
  35. package/@types/persisters/persister-sqlite-wasm/index.d.ts +2 -2
  36. package/@types/persisters/persister-sqlite-wasm/with-schemas/index.d.ts +4 -2
  37. package/@types/persisters/persister-sqlite3/index.d.ts +1 -2
  38. package/@types/persisters/persister-sqlite3/with-schemas/index.d.ts +3 -2
  39. package/@types/persisters/persister-yjs/with-schemas/index.d.ts +3 -2
  40. package/@types/persisters/with-schemas/index.d.ts +4 -0
  41. package/@types/queries/with-schemas/index.d.ts +4 -8
  42. package/@types/store/index.d.ts +13 -0
  43. package/@types/store/with-schemas/index.d.ts +13 -0
  44. package/@types/synchronizers/index.d.ts +1 -0
  45. package/@types/synchronizers/synchronizer-broadcast-channel/with-schemas/index.d.ts +3 -2
  46. package/@types/synchronizers/synchronizer-local/with-schemas/index.d.ts +3 -2
  47. package/@types/synchronizers/synchronizer-ws-client/index.d.ts +4 -2
  48. package/@types/synchronizers/synchronizer-ws-client/with-schemas/index.d.ts +1 -0
  49. package/@types/synchronizers/synchronizer-ws-server/index.d.ts +7 -7
  50. package/@types/synchronizers/synchronizer-ws-server/with-schemas/index.d.ts +7 -7
  51. package/@types/synchronizers/synchronizer-ws-server-durable-object/index.d.ts +1 -0
  52. package/@types/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.d.ts +1 -0
  53. package/@types/synchronizers/synchronizer-ws-server-simple/index.d.ts +1 -1
  54. package/@types/synchronizers/synchronizer-ws-server-simple/with-schemas/index.d.ts +1 -1
  55. package/@types/synchronizers/with-schemas/index.d.ts +4 -2
  56. package/@types/ui-react/index.d.ts +6 -1
  57. package/@types/ui-react/with-schemas/index.d.ts +6 -1
  58. package/@types/ui-react-dom/index.d.ts +153 -20
  59. package/@types/ui-react-dom/with-schemas/index.d.ts +72 -20
  60. package/@types/ui-react-inspector/index.d.ts +8 -0
  61. package/@types/ui-react-inspector/with-schemas/index.d.ts +27 -1925
  62. package/agents.md +281 -0
  63. package/common/index.js +1 -1
  64. package/common/with-schemas/index.js +1 -1
  65. package/index.js +1 -1
  66. package/mergeable-store/index.js +1 -1
  67. package/mergeable-store/with-schemas/index.js +1 -1
  68. package/min/index.js +1 -1
  69. package/min/index.js.gz +0 -0
  70. package/min/mergeable-store/index.js +1 -1
  71. package/min/mergeable-store/index.js.gz +0 -0
  72. package/min/mergeable-store/with-schemas/index.js +1 -1
  73. package/min/mergeable-store/with-schemas/index.js.gz +0 -0
  74. package/min/omni/index.js +1 -1
  75. package/min/omni/index.js.gz +0 -0
  76. package/min/omni/with-schemas/index.js +1 -1
  77. package/min/omni/with-schemas/index.js.gz +0 -0
  78. package/min/persisters/persister-automerge/index.js +1 -1
  79. package/min/persisters/persister-automerge/index.js.gz +0 -0
  80. package/min/persisters/persister-automerge/with-schemas/index.js +1 -1
  81. package/min/persisters/persister-automerge/with-schemas/index.js.gz +0 -0
  82. package/min/persisters/persister-browser/index.js +1 -1
  83. package/min/persisters/persister-browser/index.js.gz +0 -0
  84. package/min/persisters/persister-browser/with-schemas/index.js +1 -1
  85. package/min/persisters/persister-browser/with-schemas/index.js.gz +0 -0
  86. package/min/persisters/persister-react-native-mmkv/index.js +1 -0
  87. package/min/persisters/persister-react-native-mmkv/index.js.gz +0 -0
  88. package/min/persisters/persister-react-native-mmkv/with-schemas/index.js +1 -0
  89. package/min/persisters/persister-react-native-mmkv/with-schemas/index.js.gz +0 -0
  90. package/min/persisters/persister-react-native-sqlite/index.js +1 -0
  91. package/min/persisters/persister-react-native-sqlite/index.js.gz +0 -0
  92. package/min/persisters/persister-react-native-sqlite/with-schemas/index.js +1 -0
  93. package/min/persisters/persister-react-native-sqlite/with-schemas/index.js.gz +0 -0
  94. package/min/synchronizers/synchronizer-ws-server/index.js +1 -1
  95. package/min/synchronizers/synchronizer-ws-server/index.js.gz +0 -0
  96. package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js +1 -1
  97. package/min/synchronizers/synchronizer-ws-server/with-schemas/index.js.gz +0 -0
  98. package/min/ui-react/index.js +1 -1
  99. package/min/ui-react/index.js.gz +0 -0
  100. package/min/ui-react/with-schemas/index.js +1 -1
  101. package/min/ui-react/with-schemas/index.js.gz +0 -0
  102. package/min/ui-react-dom/index.js +1 -1
  103. package/min/ui-react-dom/index.js.gz +0 -0
  104. package/min/ui-react-dom/with-schemas/index.js +1 -1
  105. package/min/ui-react-dom/with-schemas/index.js.gz +0 -0
  106. package/min/ui-react-inspector/index.js +1 -1
  107. package/min/ui-react-inspector/index.js.gz +0 -0
  108. package/min/ui-react-inspector/with-schemas/index.js +1 -1
  109. package/min/ui-react-inspector/with-schemas/index.js.gz +0 -0
  110. package/min/with-schemas/index.js +1 -1
  111. package/min/with-schemas/index.js.gz +0 -0
  112. package/omni/index.js +2103 -1162
  113. package/omni/with-schemas/index.js +2103 -1162
  114. package/package.json +91 -11
  115. package/persisters/persister-automerge/index.js +1 -1
  116. package/persisters/persister-automerge/with-schemas/index.js +1 -1
  117. package/persisters/persister-browser/index.js +27 -1
  118. package/persisters/persister-browser/with-schemas/index.js +27 -1
  119. package/persisters/persister-react-native-mmkv/index.js +459 -0
  120. package/persisters/persister-react-native-mmkv/with-schemas/index.js +459 -0
  121. package/persisters/persister-react-native-sqlite/index.js +1189 -0
  122. package/persisters/persister-react-native-sqlite/with-schemas/index.js +1189 -0
  123. package/readme.md +8 -8
  124. package/releases.md +80 -30
  125. package/synchronizers/index.js +1 -1
  126. package/synchronizers/synchronizer-broadcast-channel/index.js +1 -1
  127. package/synchronizers/synchronizer-broadcast-channel/with-schemas/index.js +1 -1
  128. package/synchronizers/synchronizer-local/index.js +1 -1
  129. package/synchronizers/synchronizer-local/with-schemas/index.js +1 -1
  130. package/synchronizers/synchronizer-ws-client/index.js +1 -1
  131. package/synchronizers/synchronizer-ws-client/with-schemas/index.js +1 -1
  132. package/synchronizers/synchronizer-ws-server/index.js +1 -1
  133. package/synchronizers/synchronizer-ws-server/with-schemas/index.js +1 -1
  134. package/synchronizers/synchronizer-ws-server-durable-object/index.js +1 -1
  135. package/synchronizers/synchronizer-ws-server-durable-object/with-schemas/index.js +1 -1
  136. package/synchronizers/with-schemas/index.js +1 -1
  137. package/ui-react/index.js +397 -368
  138. package/ui-react/with-schemas/index.js +397 -368
  139. package/ui-react-dom/index.js +873 -436
  140. package/ui-react-dom/with-schemas/index.js +873 -436
  141. package/ui-react-inspector/index.js +1717 -544
  142. package/ui-react-inspector/with-schemas/index.js +1717 -544
  143. package/with-schemas/index.js +1 -1
package/omni/index.js CHANGED
@@ -62,6 +62,7 @@ const _VALUE = 'value';
62
62
  const OPEN = 'open';
63
63
  const MESSAGE = 'message';
64
64
  const ERROR = 'error';
65
+ const EXTRA = 'extra';
65
66
  const T = 't';
66
67
  const V = 'v';
67
68
  const UNDEFINED = '\uFFFC';
@@ -159,7 +160,13 @@ const setOrDelCell = (store, tableId, rowId, cellId, cell) =>
159
160
  const setOrDelValue = (store, valueId, value) =>
160
161
  isUndefined(value) ? store.delValue(valueId) : store.setValue(valueId, value);
161
162
  const getTypeCase = (type, stringCase, numberCase, booleanCase) =>
162
- type == STRING ? stringCase : type == NUMBER ? numberCase : booleanCase;
163
+ type == STRING
164
+ ? stringCase
165
+ : type == NUMBER
166
+ ? numberCase
167
+ : type == BOOLEAN
168
+ ? booleanCase
169
+ : null;
163
170
 
164
171
  const collSizeN = (collSizer) => (coll) =>
165
172
  arrayReduce(collValues(coll), (total, coll2) => total + collSizer(coll2), 0);
@@ -856,7 +863,7 @@ const getUniqueId$1 = (length = 16) =>
856
863
  arrayReduce(
857
864
  getRandomValues(new Uint8Array(length)),
858
865
  (uniqueId, number) => uniqueId + encode(number),
859
- '',
866
+ EMPTY_STRING,
860
867
  );
861
868
 
862
869
  const jsonString = JSON.stringify;
@@ -4484,7 +4491,7 @@ const createAutomergePersister = (
4484
4491
  ) => {
4485
4492
  docHandle.change((doc) => objEnsure(doc, docObjName, objNew));
4486
4493
  const getPersisted = async () => {
4487
- const doc = await docHandle.doc();
4494
+ const doc = docHandle.doc();
4488
4495
  return objSize(doc?.[docObjName]) == 2
4489
4496
  ? getDocContent(doc, docObjName)
4490
4497
  : void 0;
@@ -4514,7 +4521,7 @@ const createAutomergePersister = (
4514
4521
  );
4515
4522
  };
4516
4523
 
4517
- const STORAGE = 'storage';
4524
+ const STORAGE$1 = 'storage';
4518
4525
  const createStoragePersister = (
4519
4526
  store,
4520
4527
  storageName,
@@ -4534,11 +4541,11 @@ const createStoragePersister = (
4534
4541
  );
4535
4542
  }
4536
4543
  };
4537
- WINDOW.addEventListener(STORAGE, storageListener);
4544
+ WINDOW.addEventListener(STORAGE$1, storageListener);
4538
4545
  return storageListener;
4539
4546
  };
4540
4547
  const delPersisterListener = (storageListener) =>
4541
- WINDOW.removeEventListener(STORAGE, storageListener);
4548
+ WINDOW.removeEventListener(STORAGE$1, storageListener);
4542
4549
  return createCustomPersister(
4543
4550
  store,
4544
4551
  getPersisted,
@@ -4555,6 +4562,32 @@ const createLocalPersister = (store, storageName, onIgnoredError) =>
4555
4562
  createStoragePersister(store, storageName, localStorage, onIgnoredError);
4556
4563
  const createSessionPersister = (store, storageName, onIgnoredError) =>
4557
4564
  createStoragePersister(store, storageName, sessionStorage, onIgnoredError);
4565
+ const createOpfsPersister = (store, handle, onIgnoredError) => {
4566
+ const getPersisted = async () =>
4567
+ jsonParseWithUndefined(await (await handle.getFile()).text());
4568
+ const setPersisted = async (getContent) => {
4569
+ const writable = await handle.createWritable();
4570
+ await writable.write(jsonStringWithUndefined(getContent()));
4571
+ await writable.close();
4572
+ };
4573
+ const addPersisterListener = async (listener) => {
4574
+ const observer = new FileSystemObserver(() => listener());
4575
+ await observer.observe(handle);
4576
+ return observer;
4577
+ };
4578
+ const delPersisterListener = (observer) => observer?.disconnect();
4579
+ return createCustomPersister(
4580
+ store,
4581
+ getPersisted,
4582
+ setPersisted,
4583
+ addPersisterListener,
4584
+ delPersisterListener,
4585
+ onIgnoredError,
4586
+ 3,
4587
+ // StoreOrMergeableStore,
4588
+ {getHandle: () => handle},
4589
+ );
4590
+ };
4558
4591
 
4559
4592
  const createCrSqliteWasmPersister = (
4560
4593
  store,
@@ -5360,6 +5393,71 @@ const viewUpsert = async (
5360
5393
  );
5361
5394
  };
5362
5395
 
5396
+ const STORAGE = 'storage';
5397
+ const createReactNativeMmkvPersister = (
5398
+ store,
5399
+ storage,
5400
+ storageName = STORAGE,
5401
+ onIgnoredError,
5402
+ ) => {
5403
+ const getPersisted = async () => {
5404
+ const data = storage.getString(storageName);
5405
+ const value = data === void 0 ? void 0 : JSON.parse(data);
5406
+ return Promise.resolve(value);
5407
+ };
5408
+ const setPersisted = async (getContent) => {
5409
+ const content = getContent();
5410
+ if (content !== void 0) {
5411
+ storage.set(storageName, JSON.stringify(content));
5412
+ }
5413
+ };
5414
+ const addPersisterListener = (listener) =>
5415
+ storage.addOnValueChangedListener((key) => {
5416
+ if (key === storageName) {
5417
+ const value = storage.getString(storageName);
5418
+ if (value) {
5419
+ listener(JSON.parse(value));
5420
+ }
5421
+ }
5422
+ });
5423
+ const delPersisterListener = (storageListener) => {
5424
+ storageListener.remove();
5425
+ };
5426
+ return createCustomPersister(
5427
+ store,
5428
+ getPersisted,
5429
+ setPersisted,
5430
+ addPersisterListener,
5431
+ delPersisterListener,
5432
+ onIgnoredError,
5433
+ 3,
5434
+ // StoreOrMergeableStore
5435
+ {getStorageName: () => storageName},
5436
+ );
5437
+ };
5438
+
5439
+ const createReactNativeSqlitePersister = (
5440
+ store,
5441
+ db,
5442
+ configOrStoreTableName,
5443
+ onSqlCommand,
5444
+ onIgnoredError,
5445
+ ) =>
5446
+ createCustomSqlitePersister(
5447
+ store,
5448
+ configOrStoreTableName,
5449
+ async (sql, params = []) =>
5450
+ (await db.executeSql(sql, params))[0].rows.raw(),
5451
+ noop,
5452
+ noop,
5453
+ onSqlCommand,
5454
+ onIgnoredError,
5455
+ noop,
5456
+ 3,
5457
+ // StoreOrMergeableStore,
5458
+ db,
5459
+ );
5460
+
5363
5461
  const getETag = (response) => response.headers.get('ETag');
5364
5462
  const createRemotePersister = (
5365
5463
  store,
@@ -7021,17 +7119,6 @@ const getIndexStoreTableId = (indexes, indexId) => [
7021
7119
  indexes?.getTableId(indexId),
7022
7120
  ];
7023
7121
 
7024
- var Offsets = /* @__PURE__ */ ((Offsets2) => {
7025
- Offsets2[(Offsets2['Store'] = 0)] = 'Store';
7026
- Offsets2[(Offsets2['Metrics'] = 1)] = 'Metrics';
7027
- Offsets2[(Offsets2['Indexes'] = 2)] = 'Indexes';
7028
- Offsets2[(Offsets2['Relationships'] = 3)] = 'Relationships';
7029
- Offsets2[(Offsets2['Queries'] = 4)] = 'Queries';
7030
- Offsets2[(Offsets2['Checkpoints'] = 5)] = 'Checkpoints';
7031
- Offsets2[(Offsets2['Persister'] = 6)] = 'Persister';
7032
- Offsets2[(Offsets2['Synchronizer'] = 7)] = 'Synchronizer';
7033
- return Offsets2;
7034
- })(Offsets || {});
7035
7122
  const TINYBASE_CONTEXT = TINYBASE + '_uirc';
7036
7123
  const Context = GLOBAL[TINYBASE_CONTEXT]
7037
7124
  ? /* istanbul ignore next */
@@ -7062,6 +7149,165 @@ const useProvideThing = (thingId, thing, offset) => {
7062
7149
  const useThingIds = (offset) =>
7063
7150
  objIds(useContext(Context)[offset * 2 + 1] ?? {});
7064
7151
 
7152
+ const OFFSET_STORE = 0;
7153
+ const OFFSET_METRICS = 1;
7154
+ const OFFSET_INDEXES = 2;
7155
+ const OFFSET_RELATIONSHIPS = 3;
7156
+ const OFFSET_QUERIES = 4;
7157
+ const OFFSET_CHECKPOINTS = 5;
7158
+ const OFFSET_PERSISTER = 6;
7159
+ const OFFSET_SYNCHRONIZER = 7;
7160
+ const mergeParentThings = (
7161
+ offset,
7162
+ parentValue,
7163
+ defaultThing,
7164
+ thingsById,
7165
+ extraThingsById,
7166
+ ) => [
7167
+ defaultThing ?? parentValue[offset * 2],
7168
+ {
7169
+ ...parentValue[offset * 2 + 1],
7170
+ ...thingsById,
7171
+ ...extraThingsById[offset],
7172
+ },
7173
+ ];
7174
+ const Provider = ({
7175
+ store,
7176
+ storesById,
7177
+ metrics,
7178
+ metricsById,
7179
+ indexes,
7180
+ indexesById,
7181
+ relationships,
7182
+ relationshipsById,
7183
+ queries,
7184
+ queriesById,
7185
+ checkpoints,
7186
+ checkpointsById,
7187
+ persister,
7188
+ persistersById,
7189
+ synchronizer,
7190
+ synchronizersById,
7191
+ children,
7192
+ }) => {
7193
+ const parentValue = useContext(Context);
7194
+ const [extraThingsById, setExtraThingsById] = useState(() =>
7195
+ arrayNew(8, () => ({})),
7196
+ );
7197
+ const addExtraThingById = useCallback(
7198
+ (thingOffset, id, thing) =>
7199
+ setExtraThingsById((extraThingsById2) =>
7200
+ objGet(extraThingsById2[thingOffset], id) == thing
7201
+ ? extraThingsById2
7202
+ : arrayWith(extraThingsById2, thingOffset, {
7203
+ ...extraThingsById2[thingOffset],
7204
+ [id]: thing,
7205
+ }),
7206
+ ),
7207
+ [],
7208
+ );
7209
+ const delExtraThingById = useCallback(
7210
+ (thingOffset, id) =>
7211
+ setExtraThingsById((extraThingsById2) =>
7212
+ !objHas(extraThingsById2[thingOffset], id)
7213
+ ? extraThingsById2
7214
+ : arrayWith(
7215
+ extraThingsById2,
7216
+ thingOffset,
7217
+ objDel(extraThingsById2[thingOffset], id),
7218
+ ),
7219
+ ),
7220
+ [],
7221
+ );
7222
+ return /* @__PURE__ */ jsx(Context.Provider, {
7223
+ value: useMemo(
7224
+ () => [
7225
+ ...mergeParentThings(
7226
+ OFFSET_STORE,
7227
+ parentValue,
7228
+ store,
7229
+ storesById,
7230
+ extraThingsById,
7231
+ ),
7232
+ ...mergeParentThings(
7233
+ OFFSET_METRICS,
7234
+ parentValue,
7235
+ metrics,
7236
+ metricsById,
7237
+ extraThingsById,
7238
+ ),
7239
+ ...mergeParentThings(
7240
+ OFFSET_INDEXES,
7241
+ parentValue,
7242
+ indexes,
7243
+ indexesById,
7244
+ extraThingsById,
7245
+ ),
7246
+ ...mergeParentThings(
7247
+ OFFSET_RELATIONSHIPS,
7248
+ parentValue,
7249
+ relationships,
7250
+ relationshipsById,
7251
+ extraThingsById,
7252
+ ),
7253
+ ...mergeParentThings(
7254
+ OFFSET_QUERIES,
7255
+ parentValue,
7256
+ queries,
7257
+ queriesById,
7258
+ extraThingsById,
7259
+ ),
7260
+ ...mergeParentThings(
7261
+ OFFSET_CHECKPOINTS,
7262
+ parentValue,
7263
+ checkpoints,
7264
+ checkpointsById,
7265
+ extraThingsById,
7266
+ ),
7267
+ ...mergeParentThings(
7268
+ OFFSET_PERSISTER,
7269
+ parentValue,
7270
+ persister,
7271
+ persistersById,
7272
+ extraThingsById,
7273
+ ),
7274
+ ...mergeParentThings(
7275
+ OFFSET_SYNCHRONIZER,
7276
+ parentValue,
7277
+ synchronizer,
7278
+ synchronizersById,
7279
+ extraThingsById,
7280
+ ),
7281
+ addExtraThingById,
7282
+ delExtraThingById,
7283
+ ],
7284
+ [
7285
+ extraThingsById,
7286
+ store,
7287
+ storesById,
7288
+ metrics,
7289
+ metricsById,
7290
+ indexes,
7291
+ indexesById,
7292
+ relationships,
7293
+ relationshipsById,
7294
+ queries,
7295
+ queriesById,
7296
+ checkpoints,
7297
+ checkpointsById,
7298
+ persister,
7299
+ persistersById,
7300
+ synchronizer,
7301
+ synchronizersById,
7302
+ parentValue,
7303
+ addExtraThingById,
7304
+ delExtraThingById,
7305
+ ],
7306
+ ),
7307
+ children,
7308
+ });
7309
+ };
7310
+
7065
7311
  const EMPTY_ARRAY = [];
7066
7312
  const DEFAULTS = [{}, [], [EMPTY_ARRAY, void 0, EMPTY_ARRAY], void 0, false, 0];
7067
7313
  const IS_EQUALS = [
@@ -7226,13 +7472,13 @@ const useSortedRowIdsListenerImpl = (
7226
7472
  );
7227
7473
  const useCreateStore = (create, createDeps = EMPTY_ARRAY) =>
7228
7474
  useMemo(create, createDeps);
7229
- const useStoreIds = () => useThingIds(Offsets.Store);
7230
- const useStore = (id) => useThing(id, Offsets.Store);
7231
- const useStores = () => useThings(Offsets.Store);
7475
+ const useStoreIds = () => useThingIds(OFFSET_STORE);
7476
+ const useStore = (id) => useThing(id, OFFSET_STORE);
7477
+ const useStores = () => useThings(OFFSET_STORE);
7232
7478
  const useStoreOrStoreById = (storeOrStoreId) =>
7233
- useThingOrThingById(storeOrStoreId, Offsets.Store);
7479
+ useThingOrThingById(storeOrStoreId, OFFSET_STORE);
7234
7480
  const useProvideStore = (storeId, store) =>
7235
- useProvideThing(storeId, store, Offsets.Store);
7481
+ useProvideThing(storeId, store, OFFSET_STORE);
7236
7482
  const useCreateMergeableStore = (create, createDeps = EMPTY_ARRAY) =>
7237
7483
  useMemo(create, createDeps);
7238
7484
  const useHasTables = (storeOrStoreId) =>
@@ -7886,12 +8132,12 @@ const useDidFinishTransactionListener = (
7886
8132
  );
7887
8133
  const useCreateMetrics = (store, create, createDeps) =>
7888
8134
  useCreate(store, create, createDeps);
7889
- const useMetricsIds = () => useThingIds(Offsets.Metrics);
7890
- const useMetrics = (id) => useThing(id, Offsets.Metrics);
8135
+ const useMetricsIds = () => useThingIds(OFFSET_METRICS);
8136
+ const useMetrics = (id) => useThing(id, OFFSET_METRICS);
7891
8137
  const useMetricsOrMetricsById = (metricsOrMetricsId) =>
7892
- useThingOrThingById(metricsOrMetricsId, Offsets.Metrics);
8138
+ useThingOrThingById(metricsOrMetricsId, OFFSET_METRICS);
7893
8139
  const useProvideMetrics = (metricsId, metrics) =>
7894
- useProvideThing(metricsId, metrics, Offsets.Metrics);
8140
+ useProvideThing(metricsId, metrics, OFFSET_METRICS);
7895
8141
  const useMetricIds = (metricsOrMetricsId) =>
7896
8142
  useListenable(
7897
8143
  METRIC + IDS,
@@ -7920,12 +8166,12 @@ const useMetricListener = (
7920
8166
  );
7921
8167
  const useCreateIndexes = (store, create, createDeps) =>
7922
8168
  useCreate(store, create, createDeps);
7923
- const useIndexesIds = () => useThingIds(Offsets.Indexes);
7924
- const useIndexes = (id) => useThing(id, Offsets.Indexes);
8169
+ const useIndexesIds = () => useThingIds(OFFSET_INDEXES);
8170
+ const useIndexes = (id) => useThing(id, OFFSET_INDEXES);
7925
8171
  const useIndexesOrIndexesById = (indexesOrIndexesId) =>
7926
- useThingOrThingById(indexesOrIndexesId, Offsets.Indexes);
8172
+ useThingOrThingById(indexesOrIndexesId, OFFSET_INDEXES);
7927
8173
  const useProvideIndexes = (indexesId, indexes) =>
7928
- useProvideThing(indexesId, indexes, Offsets.Indexes);
8174
+ useProvideThing(indexesId, indexes, OFFSET_INDEXES);
7929
8175
  const useSliceIds = (indexId, indexesOrIndexesId) =>
7930
8176
  useListenable(
7931
8177
  SLICE + IDS,
@@ -7975,12 +8221,12 @@ const useSliceRowIdsListener = (
7975
8221
  );
7976
8222
  const useCreateRelationships = (store, create, createDeps) =>
7977
8223
  useCreate(store, create, createDeps);
7978
- const useRelationshipsIds = () => useThingIds(Offsets.Relationships);
7979
- const useRelationships = (id) => useThing(id, Offsets.Relationships);
8224
+ const useRelationshipsIds = () => useThingIds(OFFSET_RELATIONSHIPS);
8225
+ const useRelationships = (id) => useThing(id, OFFSET_RELATIONSHIPS);
7980
8226
  const useRelationshipsOrRelationshipsById = (relationshipsOrRelationshipsId) =>
7981
- useThingOrThingById(relationshipsOrRelationshipsId, Offsets.Relationships);
8227
+ useThingOrThingById(relationshipsOrRelationshipsId, OFFSET_RELATIONSHIPS);
7982
8228
  const useProvideRelationships = (relationshipsId, relationships) =>
7983
- useProvideThing(relationshipsId, relationships, Offsets.Relationships);
8229
+ useProvideThing(relationshipsId, relationships, OFFSET_RELATIONSHIPS);
7984
8230
  const useRelationshipIds = (relationshipsOrRelationshipsId) =>
7985
8231
  useListenable(
7986
8232
  RELATIONSHIP + IDS,
@@ -8064,12 +8310,12 @@ const useLinkedRowIdsListener = (
8064
8310
  );
8065
8311
  const useCreateQueries = (store, create, createDeps) =>
8066
8312
  useCreate(store, create, createDeps);
8067
- const useQueriesIds = () => useThingIds(Offsets.Queries);
8068
- const useQueries = (id) => useThing(id, Offsets.Queries);
8313
+ const useQueriesIds = () => useThingIds(OFFSET_QUERIES);
8314
+ const useQueries = (id) => useThing(id, OFFSET_QUERIES);
8069
8315
  const useQueriesOrQueriesById = (queriesOrQueriesId) =>
8070
- useThingOrThingById(queriesOrQueriesId, Offsets.Queries);
8316
+ useThingOrThingById(queriesOrQueriesId, OFFSET_QUERIES);
8071
8317
  const useProvideQueries = (queriesId, queries) =>
8072
- useProvideThing(queriesId, queries, Offsets.Queries);
8318
+ useProvideThing(queriesId, queries, OFFSET_QUERIES);
8073
8319
  const useQueryIds = (queriesOrQueriesId) =>
8074
8320
  useListenable(
8075
8321
  QUERY + IDS,
@@ -8253,12 +8499,12 @@ const useResultCellListener = (
8253
8499
  );
8254
8500
  const useCreateCheckpoints = (store, create, createDeps) =>
8255
8501
  useCreate(store, create, createDeps);
8256
- const useCheckpointsIds = () => useThingIds(Offsets.Checkpoints);
8257
- const useCheckpoints = (id) => useThing(id, Offsets.Checkpoints);
8502
+ const useCheckpointsIds = () => useThingIds(OFFSET_CHECKPOINTS);
8503
+ const useCheckpoints = (id) => useThing(id, OFFSET_CHECKPOINTS);
8258
8504
  const useCheckpointsOrCheckpointsById = (checkpointsOrCheckpointsId) =>
8259
- useThingOrThingById(checkpointsOrCheckpointsId, Offsets.Checkpoints);
8505
+ useThingOrThingById(checkpointsOrCheckpointsId, OFFSET_CHECKPOINTS);
8260
8506
  const useProvideCheckpoints = (checkpointsId, checkpoints) =>
8261
- useProvideThing(checkpointsId, checkpoints, Offsets.Checkpoints);
8507
+ useProvideThing(checkpointsId, checkpoints, OFFSET_CHECKPOINTS);
8262
8508
  const useCheckpointIds = (checkpointsOrCheckpointsId) =>
8263
8509
  useListenable(
8264
8510
  CHECKPOINT + IDS,
@@ -8406,12 +8652,12 @@ const useCreatePersister = (
8406
8652
  );
8407
8653
  return persister;
8408
8654
  };
8409
- const usePersisterIds = () => useThingIds(Offsets.Persister);
8410
- const usePersister = (id) => useThing(id, Offsets.Persister);
8655
+ const usePersisterIds = () => useThingIds(OFFSET_PERSISTER);
8656
+ const usePersister = (id) => useThing(id, OFFSET_PERSISTER);
8411
8657
  const usePersisterOrPersisterById = (persisterOrPersisterId) =>
8412
- useThingOrThingById(persisterOrPersisterId, Offsets.Persister);
8658
+ useThingOrThingById(persisterOrPersisterId, OFFSET_PERSISTER);
8413
8659
  const useProvidePersister = (persisterId, persister) =>
8414
- useProvideThing(persisterId, persister, Offsets.Persister);
8660
+ useProvideThing(persisterId, persister, OFFSET_PERSISTER);
8415
8661
  const usePersisterStatus = (persisterOrPersisterId) =>
8416
8662
  useListenable(
8417
8663
  STATUS,
@@ -8461,12 +8707,12 @@ const useCreateSynchronizer = (
8461
8707
  );
8462
8708
  return synchronizer;
8463
8709
  };
8464
- const useSynchronizerIds = () => useThingIds(Offsets.Synchronizer);
8465
- const useSynchronizer = (id) => useThing(id, Offsets.Synchronizer);
8710
+ const useSynchronizerIds = () => useThingIds(OFFSET_SYNCHRONIZER);
8711
+ const useSynchronizer = (id) => useThing(id, OFFSET_SYNCHRONIZER);
8466
8712
  const useSynchronizerOrSynchronizerById = (synchronizerOrSynchronizerId) =>
8467
- useThingOrThingById(synchronizerOrSynchronizerId, Offsets.Synchronizer);
8713
+ useThingOrThingById(synchronizerOrSynchronizerId, OFFSET_SYNCHRONIZER);
8468
8714
  const useProvideSynchronizer = (persisterId, persister) =>
8469
- useProvideThing(persisterId, persister, Offsets.Synchronizer);
8715
+ useProvideThing(persisterId, persister, OFFSET_SYNCHRONIZER);
8470
8716
  const useSynchronizerStatus = (synchronizerOrSynchronizerId) =>
8471
8717
  useListenable(
8472
8718
  STATUS,
@@ -8487,281 +8733,314 @@ const useSynchronizerStatusListener = (
8487
8733
  [],
8488
8734
  );
8489
8735
 
8490
- const mergeParentThings = (
8491
- offset,
8492
- parentValue,
8493
- defaultThing,
8494
- thingsById,
8495
- extraThingsById,
8496
- ) => [
8497
- defaultThing ?? parentValue[offset * 2],
8498
- {
8499
- ...parentValue[offset * 2 + 1],
8500
- ...thingsById,
8501
- ...extraThingsById[offset],
8502
- },
8503
- ];
8504
- const tableView = (
8505
- {
8506
- tableId,
8507
- store,
8508
- rowComponent: Row = RowView,
8509
- getRowComponentProps,
8510
- customCellIds,
8511
- separator,
8512
- debugIds,
8513
- },
8514
- rowIds,
8515
- ) =>
8516
- wrap(
8517
- arrayMap(rowIds, (rowId) =>
8518
- /* @__PURE__ */ jsx(
8519
- Row,
8520
- {
8521
- ...getProps(getRowComponentProps, rowId),
8522
- tableId,
8523
- rowId,
8524
- customCellIds,
8525
- store,
8526
- debugIds,
8527
- },
8528
- rowId,
8529
- ),
8530
- ),
8531
- separator,
8532
- debugIds,
8533
- tableId,
8534
- );
8535
- const resultTableView = (
8536
- {
8537
- queryId,
8538
- queries,
8539
- resultRowComponent: ResultRow = ResultRowView,
8540
- getResultRowComponentProps,
8541
- separator,
8542
- debugIds,
8543
- },
8544
- rowIds,
8545
- ) =>
8546
- wrap(
8547
- arrayMap(rowIds, (rowId) =>
8548
- /* @__PURE__ */ jsx(
8549
- ResultRow,
8550
- {
8551
- ...getProps(getResultRowComponentProps, rowId),
8552
- queryId,
8553
- rowId,
8554
- queries,
8555
- debugIds,
8556
- },
8557
- rowId,
8558
- ),
8559
- ),
8560
- separator,
8561
- debugIds,
8562
- queryId,
8736
+ const useStoreCellComponentProps = (store, tableId) =>
8737
+ useMemo(() => ({store, tableId}), [store, tableId]);
8738
+ const useQueriesCellComponentProps = (queries, queryId) =>
8739
+ useMemo(() => ({queries, queryId}), [queries, queryId]);
8740
+ const useCallbackOrUndefined = (callback, deps, test) => {
8741
+ const returnCallback = useCallback(callback, deps);
8742
+ return test ? returnCallback : void 0;
8743
+ };
8744
+ const useParams = (...args) =>
8745
+ useMemo(
8746
+ () => args,
8747
+ // eslint-disable-next-line react-hooks/exhaustive-deps
8748
+ args,
8563
8749
  );
8564
- const useComponentPerRow = (
8565
- {
8566
- relationshipId,
8567
- relationships,
8568
- rowComponent: Row = RowView,
8569
- getRowComponentProps,
8570
- separator,
8571
- debugIds,
8572
- },
8573
- getRowIdsHook,
8574
- rowId,
8575
- ) => {
8576
- const [resolvedRelationships, store, localTableId] =
8577
- getRelationshipsStoreTableIds(
8578
- useRelationshipsOrRelationshipsById(relationships),
8579
- relationshipId,
8750
+ const useCells = (defaultCellIds, customCells, defaultCellComponent) =>
8751
+ useMemo(() => {
8752
+ const cellIds = customCells ?? defaultCellIds;
8753
+ return objMap(
8754
+ isArray(cellIds)
8755
+ ? objNew(arrayMap(cellIds, (cellId) => [cellId, cellId]))
8756
+ : cellIds,
8757
+ (labelOrCustomCell, cellId) => ({
8758
+ ...{label: cellId, component: defaultCellComponent},
8759
+ ...(isString(labelOrCustomCell)
8760
+ ? {label: labelOrCustomCell}
8761
+ : labelOrCustomCell),
8762
+ }),
8580
8763
  );
8581
- const rowIds = getRowIdsHook(relationshipId, rowId, resolvedRelationships);
8582
- return wrap(
8583
- arrayMap(rowIds, (rowId2) =>
8584
- /* @__PURE__ */ jsx(
8585
- Row,
8586
- {
8587
- ...getProps(getRowComponentProps, rowId2),
8588
- tableId: localTableId,
8589
- rowId: rowId2,
8590
- store,
8591
- debugIds,
8592
- },
8593
- rowId2,
8594
- ),
8764
+ }, [customCells, defaultCellComponent, defaultCellIds]);
8765
+
8766
+ const UP_ARROW = '\u2191';
8767
+ const DOWN_ARROW = '\u2193';
8768
+ const EDITABLE = 'editable';
8769
+ const extraRowCells = (extraRowCells2 = [], extraRowCellProps, after = 0) =>
8770
+ arrayMap(extraRowCells2, ({component: Component}, index) =>
8771
+ /* @__PURE__ */ jsx(
8772
+ 'td',
8773
+ {
8774
+ className: EXTRA,
8775
+ children: /* @__PURE__ */ jsx(Component, {...extraRowCellProps}),
8776
+ },
8777
+ extraKey(index, after),
8595
8778
  ),
8596
- separator,
8597
- debugIds,
8598
- rowId,
8599
8779
  );
8600
- };
8601
- const getUseCheckpointView =
8602
- (getCheckpoints) =>
8603
- ({
8604
- checkpoints,
8605
- checkpointComponent: Checkpoint = CheckpointView,
8606
- getCheckpointComponentProps,
8607
- separator,
8608
- debugIds,
8609
- }) => {
8610
- const resolvedCheckpoints = useCheckpointsOrCheckpointsById(checkpoints);
8611
- return wrap(
8612
- arrayMap(
8613
- getCheckpoints(useCheckpointIds(resolvedCheckpoints)),
8614
- (checkpointId) =>
8615
- /* @__PURE__ */ jsx(
8616
- Checkpoint,
8780
+ const extraKey = (index, after) => (after ? '>' : '<') + index;
8781
+ const extraHeaders = (extraCells = [], after = 0) =>
8782
+ arrayMap(extraCells, ({label}, index) =>
8783
+ /* @__PURE__ */ jsx(
8784
+ 'th',
8785
+ {className: EXTRA, children: label},
8786
+ extraKey(index, after),
8787
+ ),
8788
+ );
8789
+
8790
+ const HtmlHeaderCell = ({
8791
+ cellId,
8792
+ sort: [sortCellId, sortDescending],
8793
+ label = cellId ?? EMPTY_STRING,
8794
+ onClick,
8795
+ }) =>
8796
+ /* @__PURE__ */ jsxs('th', {
8797
+ onClick: useCallbackOrUndefined(
8798
+ () => onClick?.(cellId),
8799
+ [onClick, cellId],
8800
+ onClick,
8801
+ ),
8802
+ className:
8803
+ isUndefined(sortDescending) || sortCellId != cellId
8804
+ ? void 0
8805
+ : `sorted ${sortDescending ? 'de' : 'a'}scending`,
8806
+ children: [
8807
+ isUndefined(sortDescending) || sortCellId != cellId
8808
+ ? null
8809
+ : (sortDescending ? DOWN_ARROW : UP_ARROW) + ' ',
8810
+ label,
8811
+ ],
8812
+ });
8813
+ const HtmlTable = ({
8814
+ className,
8815
+ headerRow,
8816
+ idColumn,
8817
+ params: [
8818
+ cells,
8819
+ cellComponentProps,
8820
+ rowIds,
8821
+ extraCellsBefore,
8822
+ extraCellsAfter,
8823
+ sortAndOffset,
8824
+ handleSort,
8825
+ paginatorComponent,
8826
+ ],
8827
+ }) =>
8828
+ /* @__PURE__ */ jsxs('table', {
8829
+ className,
8830
+ children: [
8831
+ paginatorComponent
8832
+ ? /* @__PURE__ */ jsx('caption', {children: paginatorComponent})
8833
+ : null,
8834
+ headerRow === false
8835
+ ? null
8836
+ : /* @__PURE__ */ jsx('thead', {
8837
+ children: /* @__PURE__ */ jsxs('tr', {
8838
+ children: [
8839
+ extraHeaders(extraCellsBefore),
8840
+ idColumn === false
8841
+ ? null
8842
+ : /* @__PURE__ */ jsx(HtmlHeaderCell, {
8843
+ sort: sortAndOffset ?? [],
8844
+ label: 'Id',
8845
+ onClick: handleSort,
8846
+ }),
8847
+ objToArray(cells, ({label}, cellId) =>
8848
+ /* @__PURE__ */ jsx(
8849
+ HtmlHeaderCell,
8850
+ {
8851
+ cellId,
8852
+ label,
8853
+ sort: sortAndOffset ?? [],
8854
+ onClick: handleSort,
8855
+ },
8856
+ cellId,
8857
+ ),
8858
+ ),
8859
+ extraHeaders(extraCellsAfter, 1),
8860
+ ],
8861
+ }),
8862
+ }),
8863
+ /* @__PURE__ */ jsx('tbody', {
8864
+ children: arrayMap(rowIds, (rowId) => {
8865
+ const rowProps = {...cellComponentProps, rowId};
8866
+ return /* @__PURE__ */ jsxs(
8867
+ 'tr',
8617
8868
  {
8618
- ...getProps(getCheckpointComponentProps, checkpointId),
8619
- checkpoints: resolvedCheckpoints,
8620
- checkpointId,
8621
- debugIds,
8869
+ children: [
8870
+ extraRowCells(extraCellsBefore, rowProps),
8871
+ idColumn === false
8872
+ ? null
8873
+ : /* @__PURE__ */ jsx('th', {title: rowId, children: rowId}),
8874
+ objToArray(
8875
+ cells,
8876
+ ({component: CellView, getComponentProps}, cellId) =>
8877
+ /* @__PURE__ */ jsx(
8878
+ 'td',
8879
+ {
8880
+ children: /* @__PURE__ */ jsx(CellView, {
8881
+ ...getProps(getComponentProps, rowId, cellId),
8882
+ ...rowProps,
8883
+ cellId,
8884
+ }),
8885
+ },
8886
+ cellId,
8887
+ ),
8888
+ ),
8889
+ extraRowCells(extraCellsAfter, rowProps, 1),
8890
+ ],
8622
8891
  },
8623
- checkpointId,
8624
- ),
8625
- ),
8626
- separator,
8627
- );
8628
- };
8629
- const Provider = ({
8630
- store,
8631
- storesById,
8632
- metrics,
8633
- metricsById,
8634
- indexes,
8635
- indexesById,
8636
- relationships,
8637
- relationshipsById,
8638
- queries,
8639
- queriesById,
8640
- checkpoints,
8641
- checkpointsById,
8642
- persister,
8643
- persistersById,
8644
- synchronizer,
8645
- synchronizersById,
8646
- children,
8892
+ rowId,
8893
+ );
8894
+ }),
8895
+ }),
8896
+ ],
8897
+ });
8898
+ const EditableThing = ({
8899
+ thing,
8900
+ onThingChange,
8901
+ className,
8902
+ hasSchema,
8903
+ showType = true,
8647
8904
  }) => {
8648
- const parentValue = useContext(Context);
8649
- const [extraThingsById, setExtraThingsById] = useState(() =>
8650
- arrayNew(8, () => ({})),
8651
- );
8652
- const addExtraThingById = useCallback(
8653
- (thingOffset, id, thing) =>
8654
- setExtraThingsById((extraThingsById2) =>
8655
- objGet(extraThingsById2[thingOffset], id) == thing
8656
- ? extraThingsById2
8657
- : arrayWith(extraThingsById2, thingOffset, {
8658
- ...extraThingsById2[thingOffset],
8659
- [id]: thing,
8660
- }),
8661
- ),
8662
- [],
8905
+ const [thingType, setThingType] = useState();
8906
+ const [currentThing, setCurrentThing] = useState();
8907
+ const [stringThing, setStringThing] = useState();
8908
+ const [numberThing, setNumberThing] = useState();
8909
+ const [booleanThing, setBooleanThing] = useState();
8910
+ if (currentThing !== thing) {
8911
+ setThingType(getCellOrValueType(thing));
8912
+ setCurrentThing(thing);
8913
+ setStringThing(String(thing));
8914
+ setNumberThing(Number(thing) || 0);
8915
+ setBooleanThing(Boolean(thing));
8916
+ }
8917
+ const handleThingChange = useCallback(
8918
+ (thing2, setTypedThing) => {
8919
+ setTypedThing(thing2);
8920
+ setCurrentThing(thing2);
8921
+ onThingChange(thing2);
8922
+ },
8923
+ [onThingChange],
8663
8924
  );
8664
- const delExtraThingById = useCallback(
8665
- (thingOffset, id) =>
8666
- setExtraThingsById((extraThingsById2) =>
8667
- !objHas(extraThingsById2[thingOffset], id)
8668
- ? extraThingsById2
8669
- : arrayWith(
8670
- extraThingsById2,
8671
- thingOffset,
8672
- objDel(extraThingsById2[thingOffset], id),
8925
+ const handleTypeChange = useCallback(() => {
8926
+ if (!hasSchema?.()) {
8927
+ const nextType = getTypeCase(thingType, NUMBER, BOOLEAN, STRING);
8928
+ const thing2 = getTypeCase(
8929
+ nextType,
8930
+ stringThing,
8931
+ numberThing,
8932
+ booleanThing,
8933
+ );
8934
+ setThingType(nextType);
8935
+ setCurrentThing(thing2);
8936
+ onThingChange(thing2);
8937
+ }
8938
+ }, [
8939
+ hasSchema,
8940
+ onThingChange,
8941
+ stringThing,
8942
+ numberThing,
8943
+ booleanThing,
8944
+ thingType,
8945
+ ]);
8946
+ const widget = getTypeCase(
8947
+ thingType,
8948
+ /* @__PURE__ */ jsx(
8949
+ 'input',
8950
+ {
8951
+ value: stringThing,
8952
+ onChange: useCallback(
8953
+ (event) =>
8954
+ handleThingChange(
8955
+ String(event[CURRENT_TARGET][_VALUE]),
8956
+ setStringThing,
8673
8957
  ),
8674
- ),
8675
- [],
8676
- );
8677
- return /* @__PURE__ */ jsx(Context.Provider, {
8678
- value: useMemo(
8679
- () => [
8680
- ...mergeParentThings(
8681
- 0 /* Store */,
8682
- parentValue,
8683
- store,
8684
- storesById,
8685
- extraThingsById,
8686
- ),
8687
- ...mergeParentThings(
8688
- 1 /* Metrics */,
8689
- parentValue,
8690
- metrics,
8691
- metricsById,
8692
- extraThingsById,
8693
- ),
8694
- ...mergeParentThings(
8695
- 2 /* Indexes */,
8696
- parentValue,
8697
- indexes,
8698
- indexesById,
8699
- extraThingsById,
8700
- ),
8701
- ...mergeParentThings(
8702
- 3 /* Relationships */,
8703
- parentValue,
8704
- relationships,
8705
- relationshipsById,
8706
- extraThingsById,
8707
- ),
8708
- ...mergeParentThings(
8709
- 4 /* Queries */,
8710
- parentValue,
8711
- queries,
8712
- queriesById,
8713
- extraThingsById,
8958
+ [handleThingChange],
8714
8959
  ),
8715
- ...mergeParentThings(
8716
- 5 /* Checkpoints */,
8717
- parentValue,
8718
- checkpoints,
8719
- checkpointsById,
8720
- extraThingsById,
8721
- ),
8722
- ...mergeParentThings(
8723
- 6 /* Persister */,
8724
- parentValue,
8725
- persister,
8726
- persistersById,
8727
- extraThingsById,
8960
+ },
8961
+ thingType,
8962
+ ),
8963
+ /* @__PURE__ */ jsx(
8964
+ 'input',
8965
+ {
8966
+ type: 'number',
8967
+ value: numberThing,
8968
+ onChange: useCallback(
8969
+ (event) =>
8970
+ handleThingChange(
8971
+ Number(event[CURRENT_TARGET][_VALUE] || 0),
8972
+ setNumberThing,
8973
+ ),
8974
+ [handleThingChange],
8728
8975
  ),
8729
- ...mergeParentThings(
8730
- 7 /* Synchronizer */,
8731
- parentValue,
8732
- synchronizer,
8733
- synchronizersById,
8734
- extraThingsById,
8976
+ },
8977
+ thingType,
8978
+ ),
8979
+ /* @__PURE__ */ jsx(
8980
+ 'input',
8981
+ {
8982
+ type: 'checkbox',
8983
+ checked: booleanThing,
8984
+ onChange: useCallback(
8985
+ (event) =>
8986
+ handleThingChange(
8987
+ Boolean(event[CURRENT_TARGET].checked),
8988
+ setBooleanThing,
8989
+ ),
8990
+ [handleThingChange],
8735
8991
  ),
8736
- addExtraThingById,
8737
- delExtraThingById,
8738
- ],
8739
- [
8740
- extraThingsById,
8741
- store,
8742
- storesById,
8743
- metrics,
8744
- metricsById,
8745
- indexes,
8746
- indexesById,
8747
- relationships,
8748
- relationshipsById,
8749
- queries,
8750
- queriesById,
8751
- checkpoints,
8752
- checkpointsById,
8753
- persister,
8754
- persistersById,
8755
- synchronizer,
8756
- synchronizersById,
8757
- parentValue,
8758
- addExtraThingById,
8759
- delExtraThingById,
8760
- ],
8992
+ },
8993
+ thingType,
8761
8994
  ),
8762
- children,
8995
+ );
8996
+ return /* @__PURE__ */ jsxs('div', {
8997
+ className,
8998
+ children: [
8999
+ showType && widget
9000
+ ? /* @__PURE__ */ jsx('button', {
9001
+ title: thingType,
9002
+ className: thingType,
9003
+ onClick: handleTypeChange,
9004
+ children: thingType,
9005
+ })
9006
+ : null,
9007
+ widget,
9008
+ ],
8763
9009
  });
8764
9010
  };
9011
+
9012
+ const EditableCellView = ({
9013
+ tableId,
9014
+ rowId,
9015
+ cellId,
9016
+ store,
9017
+ className,
9018
+ showType,
9019
+ }) =>
9020
+ /* @__PURE__ */ jsx(EditableThing, {
9021
+ thing: useCell(tableId, rowId, cellId, store),
9022
+ onThingChange: useSetCellCallback(
9023
+ tableId,
9024
+ rowId,
9025
+ cellId,
9026
+ (cell) => cell,
9027
+ [],
9028
+ store,
9029
+ ),
9030
+ className: className ?? EDITABLE + CELL,
9031
+ showType,
9032
+ hasSchema: useStoreOrStoreById(store)?.hasTablesSchema,
9033
+ });
9034
+
9035
+ const EditableValueView = ({valueId, store, className, showType}) =>
9036
+ /* @__PURE__ */ jsx(EditableThing, {
9037
+ thing: useValue(valueId, store),
9038
+ onThingChange: useSetValueCallback(valueId, (value) => value, [], store),
9039
+ className: className ?? EDITABLE + VALUE,
9040
+ showType,
9041
+ hasSchema: useStoreOrStoreById(store)?.hasValuesSchema,
9042
+ });
9043
+
8765
9044
  const wrap = (children, separator, encloseWithId, id) => {
8766
9045
  const separated =
8767
9046
  isUndefined(separator) || !isArray(children)
@@ -8769,10 +9048,53 @@ const wrap = (children, separator, encloseWithId, id) => {
8769
9048
  : arrayMap(children, (child, c) => (c > 0 ? [separator, child] : child));
8770
9049
  return encloseWithId ? [id, ':{', separated, '}'] : separated;
8771
9050
  };
8772
- const useCustomOrDefaultCellIds = (customCellIds, tableId, rowId, store) => {
8773
- const defaultCellIds = useCellIds(tableId, rowId, store);
8774
- return customCellIds ?? defaultCellIds;
8775
- };
9051
+
9052
+ const CheckpointView = ({checkpoints, checkpointId, debugIds}) =>
9053
+ wrap(
9054
+ useCheckpoint(checkpointId, checkpoints) ?? EMPTY_STRING,
9055
+ void 0,
9056
+ debugIds,
9057
+ checkpointId,
9058
+ );
9059
+
9060
+ const ResultCellView = ({queryId, rowId, cellId, queries, debugIds}) =>
9061
+ wrap(
9062
+ EMPTY_STRING +
9063
+ (useResultCell(queryId, rowId, cellId, queries) ?? EMPTY_STRING),
9064
+ void 0,
9065
+ debugIds,
9066
+ cellId,
9067
+ );
9068
+
9069
+ const ResultRowView = ({
9070
+ queryId,
9071
+ rowId,
9072
+ queries,
9073
+ resultCellComponent: ResultCell = ResultCellView,
9074
+ getResultCellComponentProps,
9075
+ separator,
9076
+ debugIds,
9077
+ }) =>
9078
+ wrap(
9079
+ arrayMap(useResultCellIds(queryId, rowId, queries), (cellId) =>
9080
+ /* @__PURE__ */ jsx(
9081
+ ResultCell,
9082
+ {
9083
+ ...getProps(getResultCellComponentProps, cellId),
9084
+ queryId,
9085
+ rowId,
9086
+ cellId,
9087
+ queries,
9088
+ debugIds,
9089
+ },
9090
+ cellId,
9091
+ ),
9092
+ ),
9093
+ separator,
9094
+ debugIds,
9095
+ rowId,
9096
+ );
9097
+
8776
9098
  const CellView = ({tableId, rowId, cellId, store, debugIds}) =>
8777
9099
  wrap(
8778
9100
  EMPTY_STRING + (useCell(tableId, rowId, cellId, store) ?? EMPTY_STRING),
@@ -8780,6 +9102,12 @@ const CellView = ({tableId, rowId, cellId, store, debugIds}) =>
8780
9102
  debugIds,
8781
9103
  cellId,
8782
9104
  );
9105
+
9106
+ const useCustomOrDefaultCellIds = (customCellIds, tableId, rowId, store) => {
9107
+ const defaultCellIds = useCellIds(tableId, rowId, store);
9108
+ return customCellIds ?? defaultCellIds;
9109
+ };
9110
+
8783
9111
  const RowView = ({
8784
9112
  tableId,
8785
9113
  rowId,
@@ -8811,93 +9139,20 @@ const RowView = ({
8811
9139
  debugIds,
8812
9140
  rowId,
8813
9141
  );
8814
- const TableView$1 = (props) =>
8815
- tableView(props, useRowIds(props.tableId, props.store));
8816
- const SortedTableView = ({cellId, descending, offset, limit, ...props}) =>
8817
- tableView(
8818
- props,
8819
- useSortedRowIds(
8820
- props.tableId,
8821
- cellId,
8822
- descending,
8823
- offset,
8824
- limit,
8825
- props.store,
8826
- ),
8827
- );
8828
- const TablesView = ({
8829
- store,
8830
- tableComponent: Table = TableView$1,
8831
- getTableComponentProps,
8832
- separator,
8833
- debugIds,
8834
- }) =>
8835
- wrap(
8836
- arrayMap(useTableIds(store), (tableId) =>
8837
- /* @__PURE__ */ jsx(
8838
- Table,
8839
- {
8840
- ...getProps(getTableComponentProps, tableId),
8841
- tableId,
8842
- store,
8843
- debugIds,
8844
- },
8845
- tableId,
8846
- ),
8847
- ),
9142
+
9143
+ const tableView = (
9144
+ {
9145
+ tableId,
9146
+ store,
9147
+ rowComponent: Row = RowView,
9148
+ getRowComponentProps,
9149
+ customCellIds,
8848
9150
  separator,
8849
- );
8850
- const ValueView = ({valueId, store, debugIds}) =>
8851
- wrap(
8852
- EMPTY_STRING + (useValue(valueId, store) ?? EMPTY_STRING),
8853
- void 0,
8854
9151
  debugIds,
8855
- valueId,
8856
- );
8857
- const ValuesView$1 = ({
8858
- store,
8859
- valueComponent: Value = ValueView,
8860
- getValueComponentProps,
8861
- separator,
8862
- debugIds,
8863
- }) =>
8864
- wrap(
8865
- arrayMap(useValueIds(store), (valueId) =>
8866
- /* @__PURE__ */ jsx(
8867
- Value,
8868
- {
8869
- ...getProps(getValueComponentProps, valueId),
8870
- valueId,
8871
- store,
8872
- debugIds,
8873
- },
8874
- valueId,
8875
- ),
8876
- ),
8877
- separator,
8878
- );
8879
- const MetricView = ({metricId, metrics, debugIds}) =>
9152
+ },
9153
+ rowIds,
9154
+ ) =>
8880
9155
  wrap(
8881
- useMetric(metricId, metrics) ?? EMPTY_STRING,
8882
- void 0,
8883
- debugIds,
8884
- metricId,
8885
- );
8886
- const SliceView$1 = ({
8887
- indexId,
8888
- sliceId,
8889
- indexes,
8890
- rowComponent: Row = RowView,
8891
- getRowComponentProps,
8892
- separator,
8893
- debugIds,
8894
- }) => {
8895
- const [resolvedIndexes, store, tableId] = getIndexStoreTableId(
8896
- useIndexesOrIndexesById(indexes),
8897
- indexId,
8898
- );
8899
- const rowIds = useSliceRowIds(indexId, sliceId, resolvedIndexes);
8900
- return wrap(
8901
9156
  arrayMap(rowIds, (rowId) =>
8902
9157
  /* @__PURE__ */ jsx(
8903
9158
  Row,
@@ -8905,6 +9160,7 @@ const SliceView$1 = ({
8905
9160
  ...getProps(getRowComponentProps, rowId),
8906
9161
  tableId,
8907
9162
  rowId,
9163
+ customCellIds,
8908
9164
  store,
8909
9165
  debugIds,
8910
9166
  },
@@ -8913,340 +9169,316 @@ const SliceView$1 = ({
8913
9169
  ),
8914
9170
  separator,
8915
9171
  debugIds,
8916
- sliceId,
9172
+ tableId,
8917
9173
  );
8918
- };
8919
- const IndexView$1 = ({
8920
- indexId,
8921
- indexes,
8922
- sliceComponent: Slice = SliceView$1,
8923
- getSliceComponentProps,
8924
- separator,
8925
- debugIds,
8926
- }) =>
9174
+ const resultTableView = (
9175
+ {
9176
+ queryId,
9177
+ queries,
9178
+ resultRowComponent: ResultRow = ResultRowView,
9179
+ getResultRowComponentProps,
9180
+ separator,
9181
+ debugIds,
9182
+ },
9183
+ rowIds,
9184
+ ) =>
8927
9185
  wrap(
8928
- arrayMap(useSliceIds(indexId, indexes), (sliceId) =>
9186
+ arrayMap(rowIds, (rowId) =>
8929
9187
  /* @__PURE__ */ jsx(
8930
- Slice,
9188
+ ResultRow,
8931
9189
  {
8932
- ...getProps(getSliceComponentProps, sliceId),
8933
- indexId,
8934
- sliceId,
8935
- indexes,
9190
+ ...getProps(getResultRowComponentProps, rowId),
9191
+ queryId,
9192
+ rowId,
9193
+ queries,
8936
9194
  debugIds,
8937
9195
  },
8938
- sliceId,
9196
+ rowId,
8939
9197
  ),
8940
9198
  ),
8941
9199
  separator,
8942
9200
  debugIds,
8943
- indexId,
9201
+ queryId,
8944
9202
  );
8945
- const RemoteRowView = ({
8946
- relationshipId,
8947
- localRowId,
8948
- relationships,
8949
- rowComponent: Row = RowView,
8950
- getRowComponentProps,
8951
- debugIds,
8952
- }) => {
8953
- const [resolvedRelationships, store, , remoteTableId] =
9203
+ const useComponentPerRow = (
9204
+ {
9205
+ relationshipId,
9206
+ relationships,
9207
+ rowComponent: Row = RowView,
9208
+ getRowComponentProps,
9209
+ separator,
9210
+ debugIds,
9211
+ },
9212
+ getRowIdsHook,
9213
+ rowId,
9214
+ ) => {
9215
+ const [resolvedRelationships, store, localTableId] =
8954
9216
  getRelationshipsStoreTableIds(
8955
9217
  useRelationshipsOrRelationshipsById(relationships),
8956
9218
  relationshipId,
8957
9219
  );
8958
- const rowId = useRemoteRowId(
8959
- relationshipId,
8960
- localRowId,
8961
- resolvedRelationships,
8962
- );
9220
+ const rowIds = getRowIdsHook(relationshipId, rowId, resolvedRelationships);
8963
9221
  return wrap(
8964
- isUndefined(remoteTableId) || isUndefined(rowId)
8965
- ? null
8966
- : /* @__PURE__ */ jsx(
8967
- Row,
8968
- {
8969
- ...getProps(getRowComponentProps, rowId),
8970
- tableId: remoteTableId,
8971
- rowId,
8972
- store,
8973
- debugIds,
8974
- },
8975
- rowId,
8976
- ),
8977
- void 0,
8978
- debugIds,
8979
- localRowId,
8980
- );
8981
- };
8982
- const LocalRowsView = (props) =>
8983
- useComponentPerRow(props, useLocalRowIds, props.remoteRowId);
8984
- const LinkedRowsView = (props) =>
8985
- useComponentPerRow(props, useLinkedRowIds, props.firstRowId);
8986
- const ResultCellView = ({queryId, rowId, cellId, queries, debugIds}) =>
8987
- wrap(
8988
- EMPTY_STRING +
8989
- (useResultCell(queryId, rowId, cellId, queries) ?? EMPTY_STRING),
8990
- void 0,
8991
- debugIds,
8992
- cellId,
8993
- );
8994
- const ResultRowView = ({
8995
- queryId,
8996
- rowId,
8997
- queries,
8998
- resultCellComponent: ResultCell = ResultCellView,
8999
- getResultCellComponentProps,
9000
- separator,
9001
- debugIds,
9002
- }) =>
9003
- wrap(
9004
- arrayMap(useResultCellIds(queryId, rowId, queries), (cellId) =>
9222
+ arrayMap(rowIds, (rowId2) =>
9005
9223
  /* @__PURE__ */ jsx(
9006
- ResultCell,
9224
+ Row,
9007
9225
  {
9008
- ...getProps(getResultCellComponentProps, cellId),
9009
- queryId,
9010
- rowId,
9011
- cellId,
9012
- queries,
9226
+ ...getProps(getRowComponentProps, rowId2),
9227
+ tableId: localTableId,
9228
+ rowId: rowId2,
9229
+ store,
9013
9230
  debugIds,
9014
9231
  },
9015
- cellId,
9232
+ rowId2,
9016
9233
  ),
9017
9234
  ),
9018
9235
  separator,
9019
9236
  debugIds,
9020
9237
  rowId,
9021
9238
  );
9022
- const ResultTableView = (props) =>
9023
- resultTableView(props, useResultRowIds(props.queryId, props.queries));
9024
- const ResultSortedTableView = ({cellId, descending, offset, limit, ...props}) =>
9025
- resultTableView(
9026
- props,
9027
- useResultSortedRowIds(
9028
- props.queryId,
9029
- cellId,
9030
- descending,
9031
- offset,
9032
- limit,
9033
- props.queries,
9034
- ),
9035
- );
9036
- const CheckpointView = ({checkpoints, checkpointId, debugIds}) =>
9037
- wrap(
9038
- useCheckpoint(checkpointId, checkpoints) ?? EMPTY_STRING,
9039
- void 0,
9239
+ };
9240
+ const getUseCheckpointView =
9241
+ (getCheckpoints) =>
9242
+ ({
9243
+ checkpoints,
9244
+ checkpointComponent: Checkpoint = CheckpointView,
9245
+ getCheckpointComponentProps,
9246
+ separator,
9040
9247
  debugIds,
9041
- checkpointId,
9042
- );
9248
+ }) => {
9249
+ const resolvedCheckpoints = useCheckpointsOrCheckpointsById(checkpoints);
9250
+ return wrap(
9251
+ arrayMap(
9252
+ getCheckpoints(useCheckpointIds(resolvedCheckpoints)),
9253
+ (checkpointId) =>
9254
+ /* @__PURE__ */ jsx(
9255
+ Checkpoint,
9256
+ {
9257
+ ...getProps(getCheckpointComponentProps, checkpointId),
9258
+ checkpoints: resolvedCheckpoints,
9259
+ checkpointId,
9260
+ debugIds,
9261
+ },
9262
+ checkpointId,
9263
+ ),
9264
+ ),
9265
+ separator,
9266
+ );
9267
+ };
9268
+
9043
9269
  const BackwardCheckpointsView = getUseCheckpointView(
9044
9270
  (checkpointIds) => checkpointIds[0],
9045
9271
  );
9272
+
9046
9273
  const CurrentCheckpointView = getUseCheckpointView((checkpointIds) =>
9047
9274
  isUndefined(checkpointIds[1]) ? [] : [checkpointIds[1]],
9048
9275
  );
9276
+
9049
9277
  const ForwardCheckpointsView = getUseCheckpointView(
9050
9278
  (checkpointIds) => checkpointIds[2],
9051
9279
  );
9052
9280
 
9053
- const EDITABLE = 'editable';
9054
- const LEFT_ARROW = '\u2190';
9055
- const UP_ARROW = '\u2191';
9056
- const RIGHT_ARROW = '\u2192';
9057
- const DOWN_ARROW = '\u2193';
9058
- const useDottedCellIds = (tableId, store) =>
9059
- arrayMap(useTableCellIds(tableId, store), (cellId) => tableId + DOT + cellId);
9060
- const useCallbackOrUndefined = (callback, deps, test) => {
9061
- const returnCallback = useCallback(callback, deps);
9062
- return test ? returnCallback : void 0;
9063
- };
9064
- const useParams = (...args) =>
9065
- useMemo(
9066
- () => args,
9067
- // eslint-disable-next-line react-hooks/exhaustive-deps
9068
- args,
9069
- );
9070
- const useStoreCellComponentProps = (store, tableId) =>
9071
- useMemo(() => ({store, tableId}), [store, tableId]);
9072
- const useQueriesCellComponentProps = (queries, queryId) =>
9073
- useMemo(() => ({queries, queryId}), [queries, queryId]);
9074
- const useSortingAndPagination = (
9075
- cellId,
9076
- descending = false,
9077
- sortOnClick,
9078
- offset = 0,
9079
- limit,
9080
- total,
9081
- paginator,
9082
- onChange,
9083
- ) => {
9084
- const [[currentCellId, currentDescending, currentOffset], setState] =
9085
- useState([cellId, descending, offset]);
9086
- const setStateAndChange = useCallback(
9087
- (sortAndOffset) => {
9088
- setState(sortAndOffset);
9089
- onChange?.(sortAndOffset);
9090
- },
9091
- [onChange],
9092
- );
9093
- const handleSort = useCallbackOrUndefined(
9094
- (cellId2) =>
9095
- setStateAndChange([
9096
- cellId2,
9097
- cellId2 == currentCellId ? !currentDescending : false,
9098
- currentOffset,
9099
- ]),
9100
- [setStateAndChange, currentCellId, currentDescending, currentOffset],
9101
- sortOnClick,
9102
- );
9103
- const handleChangeOffset = useCallback(
9104
- (offset2) => setStateAndChange([currentCellId, currentDescending, offset2]),
9105
- [setStateAndChange, currentCellId, currentDescending],
9281
+ const SliceView$1 = ({
9282
+ indexId,
9283
+ sliceId,
9284
+ indexes,
9285
+ rowComponent: Row = RowView,
9286
+ getRowComponentProps,
9287
+ separator,
9288
+ debugIds,
9289
+ }) => {
9290
+ const [resolvedIndexes, store, tableId] = getIndexStoreTableId(
9291
+ useIndexesOrIndexesById(indexes),
9292
+ indexId,
9106
9293
  );
9107
- const PaginatorComponent =
9108
- paginator === true ? SortedTablePaginator : paginator;
9109
- return [
9110
- [currentCellId, currentDescending, currentOffset],
9111
- handleSort,
9112
- useMemo(
9113
- () =>
9114
- paginator === false
9115
- ? null
9116
- : /* @__PURE__ */ jsx(PaginatorComponent, {
9117
- offset: currentOffset,
9118
- limit,
9119
- total,
9120
- onChange: handleChangeOffset,
9121
- }),
9122
- [
9123
- paginator,
9124
- PaginatorComponent,
9125
- currentOffset,
9126
- limit,
9127
- total,
9128
- handleChangeOffset,
9129
- ],
9294
+ const rowIds = useSliceRowIds(indexId, sliceId, resolvedIndexes);
9295
+ return wrap(
9296
+ arrayMap(rowIds, (rowId) =>
9297
+ /* @__PURE__ */ jsx(
9298
+ Row,
9299
+ {
9300
+ ...getProps(getRowComponentProps, rowId),
9301
+ tableId,
9302
+ rowId,
9303
+ store,
9304
+ debugIds,
9305
+ },
9306
+ rowId,
9307
+ ),
9130
9308
  ),
9131
- ];
9309
+ separator,
9310
+ debugIds,
9311
+ sliceId,
9312
+ );
9132
9313
  };
9133
- const useCells = (defaultCellIds, customCells, defaultCellComponent) =>
9134
- useMemo(() => {
9135
- const cellIds = customCells ?? defaultCellIds;
9136
- return objMap(
9137
- isArray(cellIds)
9138
- ? objNew(arrayMap(cellIds, (cellId) => [cellId, cellId]))
9139
- : cellIds,
9140
- (labelOrCustomCell, cellId) => ({
9141
- ...{label: cellId, component: defaultCellComponent},
9142
- ...(isString(labelOrCustomCell)
9143
- ? {label: labelOrCustomCell}
9144
- : labelOrCustomCell),
9145
- }),
9146
- );
9147
- }, [customCells, defaultCellComponent, defaultCellIds]);
9148
- const HtmlTable = ({
9149
- className,
9150
- headerRow,
9151
- idColumn,
9152
- params: [
9153
- cells,
9154
- cellComponentProps,
9155
- rowIds,
9156
- sortAndOffset,
9157
- handleSort,
9158
- paginatorComponent,
9159
- ],
9160
- }) =>
9161
- /* @__PURE__ */ jsxs('table', {
9162
- className,
9163
- children: [
9164
- paginatorComponent
9165
- ? /* @__PURE__ */ jsx('caption', {children: paginatorComponent})
9166
- : null,
9167
- headerRow === false
9168
- ? null
9169
- : /* @__PURE__ */ jsx('thead', {
9170
- children: /* @__PURE__ */ jsxs('tr', {
9171
- children: [
9172
- idColumn === false
9173
- ? null
9174
- : /* @__PURE__ */ jsx(HtmlHeaderCell, {
9175
- sort: sortAndOffset ?? [],
9176
- label: 'Id',
9177
- onClick: handleSort,
9178
- }),
9179
- objToArray(cells, ({label}, cellId) =>
9180
- /* @__PURE__ */ jsx(
9181
- HtmlHeaderCell,
9182
- {
9183
- cellId,
9184
- label,
9185
- sort: sortAndOffset ?? [],
9186
- onClick: handleSort,
9187
- },
9188
- cellId,
9189
- ),
9190
- ),
9191
- ],
9192
- }),
9193
- }),
9194
- /* @__PURE__ */ jsx('tbody', {
9195
- children: arrayMap(rowIds, (rowId) =>
9196
- /* @__PURE__ */ jsxs(
9197
- 'tr',
9198
- {
9199
- children: [
9200
- idColumn === false
9201
- ? null
9202
- : /* @__PURE__ */ jsx('th', {children: rowId}),
9203
- objToArray(
9204
- cells,
9205
- ({component: CellView2, getComponentProps}, cellId) =>
9206
- /* @__PURE__ */ jsx(
9207
- 'td',
9208
- {
9209
- children: /* @__PURE__ */ jsx(CellView2, {
9210
- ...getProps(getComponentProps, rowId, cellId),
9211
- ...cellComponentProps,
9212
- rowId,
9213
- cellId,
9214
- }),
9215
- },
9216
- cellId,
9217
- ),
9218
- ),
9219
- ],
9220
- },
9314
+
9315
+ const IndexView$1 = ({
9316
+ indexId,
9317
+ indexes,
9318
+ sliceComponent: Slice = SliceView$1,
9319
+ getSliceComponentProps,
9320
+ separator,
9321
+ debugIds,
9322
+ }) =>
9323
+ wrap(
9324
+ arrayMap(useSliceIds(indexId, indexes), (sliceId) =>
9325
+ /* @__PURE__ */ jsx(
9326
+ Slice,
9327
+ {
9328
+ ...getProps(getSliceComponentProps, sliceId),
9329
+ indexId,
9330
+ sliceId,
9331
+ indexes,
9332
+ debugIds,
9333
+ },
9334
+ sliceId,
9335
+ ),
9336
+ ),
9337
+ separator,
9338
+ debugIds,
9339
+ indexId,
9340
+ );
9341
+
9342
+ const LinkedRowsView = (props) =>
9343
+ useComponentPerRow(props, useLinkedRowIds, props.firstRowId);
9344
+
9345
+ const LocalRowsView = (props) =>
9346
+ useComponentPerRow(props, useLocalRowIds, props.remoteRowId);
9347
+
9348
+ const MetricView = ({metricId, metrics, debugIds}) =>
9349
+ wrap(
9350
+ useMetric(metricId, metrics) ?? EMPTY_STRING,
9351
+ void 0,
9352
+ debugIds,
9353
+ metricId,
9354
+ );
9355
+
9356
+ const RemoteRowView = ({
9357
+ relationshipId,
9358
+ localRowId,
9359
+ relationships,
9360
+ rowComponent: Row = RowView,
9361
+ getRowComponentProps,
9362
+ debugIds,
9363
+ }) => {
9364
+ const [resolvedRelationships, store, , remoteTableId] =
9365
+ getRelationshipsStoreTableIds(
9366
+ useRelationshipsOrRelationshipsById(relationships),
9367
+ relationshipId,
9368
+ );
9369
+ const rowId = useRemoteRowId(
9370
+ relationshipId,
9371
+ localRowId,
9372
+ resolvedRelationships,
9373
+ );
9374
+ return wrap(
9375
+ isUndefined(remoteTableId) || isUndefined(rowId)
9376
+ ? null
9377
+ : /* @__PURE__ */ jsx(
9378
+ Row,
9379
+ {
9380
+ ...getProps(getRowComponentProps, rowId),
9381
+ tableId: remoteTableId,
9221
9382
  rowId,
9222
- ),
9383
+ store,
9384
+ debugIds,
9385
+ },
9386
+ rowId,
9223
9387
  ),
9224
- }),
9225
- ],
9226
- });
9227
- const HtmlHeaderCell = ({
9228
- cellId,
9229
- sort: [sortCellId, sortDescending],
9230
- label = cellId ?? EMPTY_STRING,
9231
- onClick,
9388
+ void 0,
9389
+ debugIds,
9390
+ localRowId,
9391
+ );
9392
+ };
9393
+
9394
+ const ResultSortedTableView = ({cellId, descending, offset, limit, ...props}) =>
9395
+ resultTableView(
9396
+ props,
9397
+ useResultSortedRowIds(
9398
+ props.queryId,
9399
+ cellId,
9400
+ descending,
9401
+ offset,
9402
+ limit,
9403
+ props.queries,
9404
+ ),
9405
+ );
9406
+
9407
+ const ResultTableView = (props) =>
9408
+ resultTableView(props, useResultRowIds(props.queryId, props.queries));
9409
+
9410
+ const SortedTableView = ({cellId, descending, offset, limit, ...props}) =>
9411
+ tableView(
9412
+ props,
9413
+ useSortedRowIds(
9414
+ props.tableId,
9415
+ cellId,
9416
+ descending,
9417
+ offset,
9418
+ limit,
9419
+ props.store,
9420
+ ),
9421
+ );
9422
+
9423
+ const TableView$1 = (props) =>
9424
+ tableView(props, useRowIds(props.tableId, props.store));
9425
+
9426
+ const TablesView$1 = ({
9427
+ store,
9428
+ tableComponent: Table = TableView$1,
9429
+ getTableComponentProps,
9430
+ separator,
9431
+ debugIds,
9232
9432
  }) =>
9233
- /* @__PURE__ */ jsxs('th', {
9234
- onClick: useCallbackOrUndefined(
9235
- () => onClick?.(cellId),
9236
- [onClick, cellId],
9237
- onClick,
9433
+ wrap(
9434
+ arrayMap(useTableIds(store), (tableId) =>
9435
+ /* @__PURE__ */ jsx(
9436
+ Table,
9437
+ {
9438
+ ...getProps(getTableComponentProps, tableId),
9439
+ tableId,
9440
+ store,
9441
+ debugIds,
9442
+ },
9443
+ tableId,
9444
+ ),
9238
9445
  ),
9239
- className:
9240
- isUndefined(sortDescending) || sortCellId != cellId
9241
- ? void 0
9242
- : `sorted ${sortDescending ? 'de' : 'a'}scending`,
9243
- children: [
9244
- isUndefined(sortDescending) || sortCellId != cellId
9245
- ? null
9246
- : (sortDescending ? DOWN_ARROW : UP_ARROW) + ' ',
9247
- label,
9248
- ],
9249
- });
9446
+ separator,
9447
+ );
9448
+
9449
+ const ValueView = ({valueId, store, debugIds}) =>
9450
+ wrap(
9451
+ EMPTY_STRING + (useValue(valueId, store) ?? EMPTY_STRING),
9452
+ void 0,
9453
+ debugIds,
9454
+ valueId,
9455
+ );
9456
+
9457
+ const ValuesView$1 = ({
9458
+ store,
9459
+ valueComponent: Value = ValueView,
9460
+ getValueComponentProps,
9461
+ separator,
9462
+ debugIds,
9463
+ }) =>
9464
+ wrap(
9465
+ arrayMap(useValueIds(store), (valueId) =>
9466
+ /* @__PURE__ */ jsx(
9467
+ Value,
9468
+ {
9469
+ ...getProps(getValueComponentProps, valueId),
9470
+ valueId,
9471
+ store,
9472
+ debugIds,
9473
+ },
9474
+ valueId,
9475
+ ),
9476
+ ),
9477
+ separator,
9478
+ );
9479
+
9480
+ const useDottedCellIds = (tableId, store) =>
9481
+ arrayMap(useTableCellIds(tableId, store), (cellId) => tableId + DOT + cellId);
9250
9482
  const RelationshipInHtmlRow = ({
9251
9483
  localRowId,
9252
9484
  params: [
@@ -9257,17 +9489,31 @@ const RelationshipInHtmlRow = ({
9257
9489
  relationshipId,
9258
9490
  relationships,
9259
9491
  store,
9492
+ extraCellsBefore,
9493
+ extraCellsAfter,
9260
9494
  ],
9261
9495
  }) => {
9262
9496
  const remoteRowId = useRemoteRowId(relationshipId, localRowId, relationships);
9497
+ const rowProps = {
9498
+ tableId: localTableId ?? '',
9499
+ rowId: localRowId,
9500
+ store,
9501
+ };
9263
9502
  return /* @__PURE__ */ jsxs('tr', {
9264
9503
  children: [
9504
+ extraRowCells(extraCellsBefore, rowProps),
9265
9505
  idColumn === false
9266
9506
  ? null
9267
9507
  : /* @__PURE__ */ jsxs(Fragment, {
9268
9508
  children: [
9269
- /* @__PURE__ */ jsx('th', {children: localRowId}),
9270
- /* @__PURE__ */ jsx('th', {children: remoteRowId}),
9509
+ /* @__PURE__ */ jsx('th', {
9510
+ title: localRowId,
9511
+ children: localRowId,
9512
+ }),
9513
+ /* @__PURE__ */ jsx('th', {
9514
+ title: remoteRowId,
9515
+ children: remoteRowId,
9516
+ }),
9271
9517
  ],
9272
9518
  }),
9273
9519
  objToArray(
@@ -9297,145 +9543,215 @@ const RelationshipInHtmlRow = ({
9297
9543
  );
9298
9544
  },
9299
9545
  ),
9546
+ extraRowCells(extraCellsAfter, rowProps, 1),
9547
+ ],
9548
+ });
9549
+ };
9550
+ const RelationshipInHtmlTable = ({
9551
+ relationshipId,
9552
+ relationships,
9553
+ editable,
9554
+ customCells,
9555
+ extraCellsBefore,
9556
+ extraCellsAfter,
9557
+ className,
9558
+ headerRow,
9559
+ idColumn = true,
9560
+ }) => {
9561
+ const [resolvedRelationships, store, localTableId, remoteTableId] =
9562
+ getRelationshipsStoreTableIds(
9563
+ useRelationshipsOrRelationshipsById(relationships),
9564
+ relationshipId,
9565
+ );
9566
+ const cells = useCells(
9567
+ [
9568
+ ...useDottedCellIds(localTableId, store),
9569
+ ...useDottedCellIds(remoteTableId, store),
9570
+ ],
9571
+ customCells,
9572
+ editable ? EditableCellView : CellView,
9573
+ );
9574
+ const params = useParams(
9575
+ idColumn,
9576
+ cells,
9577
+ localTableId,
9578
+ remoteTableId,
9579
+ relationshipId,
9580
+ resolvedRelationships,
9581
+ store,
9582
+ extraCellsBefore,
9583
+ extraCellsAfter,
9584
+ );
9585
+ return /* @__PURE__ */ jsxs('table', {
9586
+ className,
9587
+ children: [
9588
+ headerRow === false
9589
+ ? null
9590
+ : /* @__PURE__ */ jsx('thead', {
9591
+ children: /* @__PURE__ */ jsxs('tr', {
9592
+ children: [
9593
+ extraHeaders(extraCellsBefore),
9594
+ idColumn === false
9595
+ ? null
9596
+ : /* @__PURE__ */ jsxs(Fragment, {
9597
+ children: [
9598
+ /* @__PURE__ */ jsxs('th', {
9599
+ children: [localTableId, '.Id'],
9600
+ }),
9601
+ /* @__PURE__ */ jsxs('th', {
9602
+ children: [remoteTableId, '.Id'],
9603
+ }),
9604
+ ],
9605
+ }),
9606
+ objToArray(cells, ({label}, cellId) =>
9607
+ /* @__PURE__ */ jsx('th', {children: label}, cellId),
9608
+ ),
9609
+ extraHeaders(extraCellsAfter, 1),
9610
+ ],
9611
+ }),
9612
+ }),
9613
+ /* @__PURE__ */ jsx('tbody', {
9614
+ children: arrayMap(useRowIds(localTableId, store), (localRowId) =>
9615
+ /* @__PURE__ */ jsx(
9616
+ RelationshipInHtmlRow,
9617
+ {
9618
+ localRowId,
9619
+ params,
9620
+ },
9621
+ localRowId,
9622
+ ),
9623
+ ),
9624
+ }),
9300
9625
  ],
9301
9626
  });
9302
9627
  };
9303
- const EditableThing = ({
9304
- thing,
9305
- onThingChange,
9306
- className,
9307
- hasSchema,
9308
- showType = true,
9628
+
9629
+ const LEFT_ARROW = '\u2190';
9630
+ const RIGHT_ARROW = '\u2192';
9631
+ const useSortingAndPagination = (
9632
+ cellId,
9633
+ descending = false,
9634
+ sortOnClick,
9635
+ offset = 0,
9636
+ limit,
9637
+ total,
9638
+ paginator,
9639
+ onChange,
9640
+ ) => {
9641
+ const [[currentCellId, currentDescending, currentOffset], setState] =
9642
+ useState([cellId, descending, offset]);
9643
+ const setStateAndChange = useCallback(
9644
+ (sortAndOffset) => {
9645
+ setState(sortAndOffset);
9646
+ onChange?.(sortAndOffset);
9647
+ },
9648
+ [onChange],
9649
+ );
9650
+ const handleSort = useCallbackOrUndefined(
9651
+ (cellId2) =>
9652
+ setStateAndChange([
9653
+ cellId2,
9654
+ cellId2 == currentCellId ? !currentDescending : false,
9655
+ currentOffset,
9656
+ ]),
9657
+ [setStateAndChange, currentCellId, currentDescending, currentOffset],
9658
+ sortOnClick,
9659
+ );
9660
+ const handleChangeOffset = useCallback(
9661
+ (offset2) => setStateAndChange([currentCellId, currentDescending, offset2]),
9662
+ [setStateAndChange, currentCellId, currentDescending],
9663
+ );
9664
+ const PaginatorComponent =
9665
+ paginator === true ? SortedTablePaginator : paginator;
9666
+ return [
9667
+ [currentCellId, currentDescending, currentOffset],
9668
+ handleSort,
9669
+ useMemo(
9670
+ () =>
9671
+ paginator === false
9672
+ ? null
9673
+ : /* @__PURE__ */ jsx(PaginatorComponent, {
9674
+ offset: currentOffset,
9675
+ limit,
9676
+ total,
9677
+ onChange: handleChangeOffset,
9678
+ }),
9679
+ [
9680
+ paginator,
9681
+ PaginatorComponent,
9682
+ currentOffset,
9683
+ limit,
9684
+ total,
9685
+ handleChangeOffset,
9686
+ ],
9687
+ ),
9688
+ ];
9689
+ };
9690
+ const SortedTablePaginator = ({
9691
+ onChange,
9692
+ total,
9693
+ offset = 0,
9694
+ limit = total,
9695
+ singular = 'row',
9696
+ plural = singular + 's',
9309
9697
  }) => {
9310
- const [thingType, setThingType] = useState();
9311
- const [currentThing, setCurrentThing] = useState();
9312
- const [stringThing, setStringThing] = useState();
9313
- const [numberThing, setNumberThing] = useState();
9314
- const [booleanThing, setBooleanThing] = useState();
9315
- if (currentThing !== thing) {
9316
- setThingType(getCellOrValueType(thing));
9317
- setCurrentThing(thing);
9318
- setStringThing(String(thing));
9319
- setNumberThing(Number(thing) || 0);
9320
- setBooleanThing(Boolean(thing));
9698
+ if (offset > total || offset < 0) {
9699
+ offset = 0;
9700
+ onChange(0);
9321
9701
  }
9322
- const handleThingChange = useCallback(
9323
- (thing2, setTypedThing) => {
9324
- setTypedThing(thing2);
9325
- setCurrentThing(thing2);
9326
- onThingChange(thing2);
9327
- },
9328
- [onThingChange],
9702
+ const handlePrevClick = useCallbackOrUndefined(
9703
+ () => onChange(offset - limit),
9704
+ [onChange, offset, limit],
9705
+ offset > 0,
9329
9706
  );
9330
- const handleTypeChange = useCallback(() => {
9331
- if (!hasSchema?.()) {
9332
- const nextType = getTypeCase(thingType, NUMBER, BOOLEAN, STRING);
9333
- const thing2 = getTypeCase(
9334
- nextType,
9335
- stringThing,
9336
- numberThing,
9337
- booleanThing,
9338
- );
9339
- setThingType(nextType);
9340
- setCurrentThing(thing2);
9341
- onThingChange(thing2);
9342
- }
9343
- }, [
9344
- hasSchema,
9345
- onThingChange,
9346
- stringThing,
9347
- numberThing,
9348
- booleanThing,
9349
- thingType,
9350
- ]);
9351
- return /* @__PURE__ */ jsxs('div', {
9352
- className,
9707
+ const handleNextClick = useCallbackOrUndefined(
9708
+ () => onChange(offset + limit),
9709
+ [onChange, offset, limit],
9710
+ offset + limit < total,
9711
+ );
9712
+ return /* @__PURE__ */ jsxs(Fragment, {
9353
9713
  children: [
9354
- showType
9355
- ? /* @__PURE__ */ jsx('button', {
9356
- className: thingType,
9357
- onClick: handleTypeChange,
9358
- children: thingType,
9359
- })
9360
- : null,
9361
- getTypeCase(
9362
- thingType,
9363
- /* @__PURE__ */ jsx(
9364
- 'input',
9365
- {
9366
- value: stringThing,
9367
- onChange: useCallback(
9368
- (event) =>
9369
- handleThingChange(
9370
- String(event[CURRENT_TARGET][_VALUE]),
9371
- setStringThing,
9372
- ),
9373
- [handleThingChange],
9374
- ),
9375
- },
9376
- thingType,
9377
- ),
9378
- /* @__PURE__ */ jsx(
9379
- 'input',
9380
- {
9381
- type: 'number',
9382
- value: numberThing,
9383
- onChange: useCallback(
9384
- (event) =>
9385
- handleThingChange(
9386
- Number(event[CURRENT_TARGET][_VALUE] || 0),
9387
- setNumberThing,
9388
- ),
9389
- [handleThingChange],
9390
- ),
9391
- },
9392
- thingType,
9393
- ),
9394
- /* @__PURE__ */ jsx(
9395
- 'input',
9396
- {
9397
- type: 'checkbox',
9398
- checked: booleanThing,
9399
- onChange: useCallback(
9400
- (event) =>
9401
- handleThingChange(
9402
- Boolean(event[CURRENT_TARGET].checked),
9403
- setBooleanThing,
9404
- ),
9405
- [handleThingChange],
9406
- ),
9407
- },
9408
- thingType,
9409
- ),
9410
- ),
9714
+ total > limit &&
9715
+ /* @__PURE__ */ jsxs(Fragment, {
9716
+ children: [
9717
+ /* @__PURE__ */ jsx('button', {
9718
+ className: 'previous',
9719
+ disabled: offset == 0,
9720
+ onClick: handlePrevClick,
9721
+ children: LEFT_ARROW,
9722
+ }),
9723
+ /* @__PURE__ */ jsx('button', {
9724
+ className: 'next',
9725
+ disabled: offset + limit >= total,
9726
+ onClick: handleNextClick,
9727
+ children: RIGHT_ARROW,
9728
+ }),
9729
+ offset + 1,
9730
+ ' to ',
9731
+ mathMin(total, offset + limit),
9732
+ ' of ',
9733
+ ],
9734
+ }),
9735
+ total,
9736
+ ' ',
9737
+ total != 1 ? plural : singular,
9411
9738
  ],
9412
9739
  });
9413
9740
  };
9414
- const TableInHtmlTable = ({tableId, store, editable, customCells, ...props}) =>
9415
- /* @__PURE__ */ jsx(HtmlTable, {
9416
- ...props,
9417
- params: useParams(
9418
- useCells(
9419
- useTableCellIds(tableId, store),
9420
- customCells,
9421
- editable ? EditableCellView : CellView,
9422
- ),
9423
- useStoreCellComponentProps(store, tableId),
9424
- useRowIds(tableId, store),
9425
- ),
9426
- });
9427
- const SortedTableInHtmlTable = ({
9428
- tableId,
9741
+
9742
+ const ResultSortedTableInHtmlTable = ({
9743
+ queryId,
9429
9744
  cellId,
9430
9745
  descending,
9431
9746
  offset,
9432
9747
  limit,
9433
- store,
9434
- editable,
9748
+ queries,
9435
9749
  sortOnClick,
9436
9750
  paginator = false,
9437
- onChange,
9438
9751
  customCells,
9752
+ extraCellsBefore,
9753
+ extraCellsAfter,
9754
+ onChange,
9439
9755
  ...props
9440
9756
  }) => {
9441
9757
  const [sortAndOffset, handleSort, paginatorComponent] =
@@ -9445,7 +9761,7 @@ const SortedTableInHtmlTable = ({
9445
9761
  sortOnClick,
9446
9762
  offset,
9447
9763
  limit,
9448
- useRowCount(tableId, store),
9764
+ useResultRowCount(queryId, queries),
9449
9765
  paginator,
9450
9766
  onChange,
9451
9767
  );
@@ -9453,72 +9769,52 @@ const SortedTableInHtmlTable = ({
9453
9769
  ...props,
9454
9770
  params: useParams(
9455
9771
  useCells(
9456
- useTableCellIds(tableId, store),
9772
+ useResultTableCellIds(queryId, queries),
9457
9773
  customCells,
9458
- editable ? EditableCellView : CellView,
9774
+ ResultCellView,
9459
9775
  ),
9460
- useStoreCellComponentProps(store, tableId),
9461
- useSortedRowIds(tableId, ...sortAndOffset, limit, store),
9776
+ useQueriesCellComponentProps(queries, queryId),
9777
+ useResultSortedRowIds(queryId, ...sortAndOffset, limit, queries),
9778
+ extraCellsBefore,
9779
+ extraCellsAfter,
9462
9780
  sortAndOffset,
9463
9781
  handleSort,
9464
9782
  paginatorComponent,
9465
9783
  ),
9466
9784
  });
9467
- };
9468
- const ValuesInHtmlTable = ({
9469
- store,
9470
- editable = false,
9471
- valueComponent: Value = editable ? EditableValueView : ValueView,
9472
- getValueComponentProps,
9473
- className,
9474
- headerRow,
9475
- idColumn,
9476
- }) =>
9477
- /* @__PURE__ */ jsxs('table', {
9478
- className,
9479
- children: [
9480
- headerRow === false
9481
- ? null
9482
- : /* @__PURE__ */ jsx('thead', {
9483
- children: /* @__PURE__ */ jsxs('tr', {
9484
- children: [
9485
- idColumn === false
9486
- ? null
9487
- : /* @__PURE__ */ jsx('th', {children: 'Id'}),
9488
- /* @__PURE__ */ jsx('th', {children: VALUE}),
9489
- ],
9490
- }),
9491
- }),
9492
- /* @__PURE__ */ jsx('tbody', {
9493
- children: arrayMap(useValueIds(store), (valueId) =>
9494
- /* @__PURE__ */ jsxs(
9495
- 'tr',
9496
- {
9497
- children: [
9498
- idColumn === false
9499
- ? null
9500
- : /* @__PURE__ */ jsx('th', {children: valueId}),
9501
- /* @__PURE__ */ jsx('td', {
9502
- children: /* @__PURE__ */ jsx(Value, {
9503
- ...getProps(getValueComponentProps, valueId),
9504
- valueId,
9505
- store,
9506
- }),
9507
- }),
9508
- ],
9509
- },
9510
- valueId,
9511
- ),
9512
- ),
9513
- }),
9514
- ],
9785
+ };
9786
+
9787
+ const ResultTableInHtmlTable = ({
9788
+ queryId,
9789
+ queries,
9790
+ customCells,
9791
+ extraCellsBefore,
9792
+ extraCellsAfter,
9793
+ ...props
9794
+ }) =>
9795
+ /* @__PURE__ */ jsx(HtmlTable, {
9796
+ ...props,
9797
+ params: useParams(
9798
+ useCells(
9799
+ useResultTableCellIds(queryId, queries),
9800
+ customCells,
9801
+ ResultCellView,
9802
+ ),
9803
+ useQueriesCellComponentProps(queries, queryId),
9804
+ useResultRowIds(queryId, queries),
9805
+ extraCellsBefore,
9806
+ extraCellsAfter,
9807
+ ),
9515
9808
  });
9809
+
9516
9810
  const SliceInHtmlTable = ({
9517
9811
  indexId,
9518
9812
  sliceId,
9519
9813
  indexes,
9520
9814
  editable,
9521
9815
  customCells,
9816
+ extraCellsBefore,
9817
+ extraCellsAfter,
9522
9818
  ...props
9523
9819
  }) => {
9524
9820
  const [resolvedIndexes, store, tableId] = getIndexStoreTableId(
@@ -9535,105 +9831,26 @@ const SliceInHtmlTable = ({
9535
9831
  ),
9536
9832
  useStoreCellComponentProps(store, tableId),
9537
9833
  useSliceRowIds(indexId, sliceId, resolvedIndexes),
9834
+ extraCellsBefore,
9835
+ extraCellsAfter,
9538
9836
  ),
9539
9837
  });
9540
9838
  };
9541
- const RelationshipInHtmlTable = ({
9542
- relationshipId,
9543
- relationships,
9544
- editable,
9545
- customCells,
9546
- className,
9547
- headerRow,
9548
- idColumn = true,
9549
- }) => {
9550
- const [resolvedRelationships, store, localTableId, remoteTableId] =
9551
- getRelationshipsStoreTableIds(
9552
- useRelationshipsOrRelationshipsById(relationships),
9553
- relationshipId,
9554
- );
9555
- const cells = useCells(
9556
- [
9557
- ...useDottedCellIds(localTableId, store),
9558
- ...useDottedCellIds(remoteTableId, store),
9559
- ],
9560
- customCells,
9561
- editable ? EditableCellView : CellView,
9562
- );
9563
- const params = useParams(
9564
- idColumn,
9565
- cells,
9566
- localTableId,
9567
- remoteTableId,
9568
- relationshipId,
9569
- resolvedRelationships,
9570
- store,
9571
- );
9572
- return /* @__PURE__ */ jsxs('table', {
9573
- className,
9574
- children: [
9575
- headerRow === false
9576
- ? null
9577
- : /* @__PURE__ */ jsx('thead', {
9578
- children: /* @__PURE__ */ jsxs('tr', {
9579
- children: [
9580
- idColumn === false
9581
- ? null
9582
- : /* @__PURE__ */ jsxs(Fragment, {
9583
- children: [
9584
- /* @__PURE__ */ jsxs('th', {
9585
- children: [localTableId, '.Id'],
9586
- }),
9587
- /* @__PURE__ */ jsxs('th', {
9588
- children: [remoteTableId, '.Id'],
9589
- }),
9590
- ],
9591
- }),
9592
- objToArray(cells, ({label}, cellId) =>
9593
- /* @__PURE__ */ jsx('th', {children: label}, cellId),
9594
- ),
9595
- ],
9596
- }),
9597
- }),
9598
- /* @__PURE__ */ jsx('tbody', {
9599
- children: arrayMap(useRowIds(localTableId, store), (localRowId) =>
9600
- /* @__PURE__ */ jsx(
9601
- RelationshipInHtmlRow,
9602
- {
9603
- localRowId,
9604
- params,
9605
- },
9606
- localRowId,
9607
- ),
9608
- ),
9609
- }),
9610
- ],
9611
- });
9612
- };
9613
- const ResultTableInHtmlTable = ({queryId, queries, customCells, ...props}) =>
9614
- /* @__PURE__ */ jsx(HtmlTable, {
9615
- ...props,
9616
- params: useParams(
9617
- useCells(
9618
- useResultTableCellIds(queryId, queries),
9619
- customCells,
9620
- ResultCellView,
9621
- ),
9622
- useQueriesCellComponentProps(queries, queryId),
9623
- useResultRowIds(queryId, queries),
9624
- ),
9625
- });
9626
- const ResultSortedTableInHtmlTable = ({
9627
- queryId,
9839
+
9840
+ const SortedTableInHtmlTable = ({
9841
+ tableId,
9628
9842
  cellId,
9629
9843
  descending,
9630
9844
  offset,
9631
9845
  limit,
9632
- queries,
9846
+ store,
9847
+ editable,
9633
9848
  sortOnClick,
9634
9849
  paginator = false,
9635
- customCells,
9636
9850
  onChange,
9851
+ customCells,
9852
+ extraCellsBefore,
9853
+ extraCellsAfter,
9637
9854
  ...props
9638
9855
  }) => {
9639
9856
  const [sortAndOffset, handleSort, paginatorComponent] =
@@ -9643,7 +9860,7 @@ const ResultSortedTableInHtmlTable = ({
9643
9860
  sortOnClick,
9644
9861
  offset,
9645
9862
  limit,
9646
- useResultRowCount(queryId, queries),
9863
+ useRowCount(tableId, store),
9647
9864
  paginator,
9648
9865
  onChange,
9649
9866
  );
@@ -9651,99 +9868,117 @@ const ResultSortedTableInHtmlTable = ({
9651
9868
  ...props,
9652
9869
  params: useParams(
9653
9870
  useCells(
9654
- useResultTableCellIds(queryId, queries),
9871
+ useTableCellIds(tableId, store),
9655
9872
  customCells,
9656
- ResultCellView,
9873
+ editable ? EditableCellView : CellView,
9657
9874
  ),
9658
- useQueriesCellComponentProps(queries, queryId),
9659
- useResultSortedRowIds(queryId, ...sortAndOffset, limit, queries),
9875
+ useStoreCellComponentProps(store, tableId),
9876
+ useSortedRowIds(tableId, ...sortAndOffset, limit, store),
9877
+ extraCellsBefore,
9878
+ extraCellsAfter,
9660
9879
  sortAndOffset,
9661
9880
  handleSort,
9662
9881
  paginatorComponent,
9663
9882
  ),
9664
9883
  });
9665
9884
  };
9666
- const EditableCellView = ({
9885
+
9886
+ const TableInHtmlTable = ({
9667
9887
  tableId,
9668
- rowId,
9669
- cellId,
9670
9888
  store,
9671
- className,
9672
- showType,
9889
+ editable,
9890
+ customCells,
9891
+ extraCellsBefore,
9892
+ extraCellsAfter,
9893
+ ...props
9673
9894
  }) =>
9674
- /* @__PURE__ */ jsx(EditableThing, {
9675
- thing: useCell(tableId, rowId, cellId, store),
9676
- onThingChange: useSetCellCallback(
9677
- tableId,
9678
- rowId,
9679
- cellId,
9680
- (cell) => cell,
9681
- [],
9682
- store,
9895
+ /* @__PURE__ */ jsx(HtmlTable, {
9896
+ ...props,
9897
+ params: useParams(
9898
+ useCells(
9899
+ useTableCellIds(tableId, store),
9900
+ customCells,
9901
+ editable ? EditableCellView : CellView,
9902
+ ),
9903
+ useStoreCellComponentProps(store, tableId),
9904
+ useRowIds(tableId, store),
9905
+ extraCellsBefore,
9906
+ extraCellsAfter,
9683
9907
  ),
9684
- className: className ?? EDITABLE + CELL,
9685
- showType,
9686
- hasSchema: useStoreOrStoreById(store)?.hasTablesSchema,
9687
- });
9688
- const EditableValueView = ({valueId, store, className, showType}) =>
9689
- /* @__PURE__ */ jsx(EditableThing, {
9690
- thing: useValue(valueId, store),
9691
- onThingChange: useSetValueCallback(valueId, (value) => value, [], store),
9692
- className: className ?? EDITABLE + VALUE,
9693
- showType,
9694
- hasSchema: useStoreOrStoreById(store)?.hasValuesSchema,
9695
9908
  });
9696
- const SortedTablePaginator = ({
9697
- onChange,
9698
- total,
9699
- offset = 0,
9700
- limit = total,
9701
- singular = 'row',
9702
- plural = singular + 's',
9703
- }) => {
9704
- if (offset > total || offset < 0) {
9705
- offset = 0;
9706
- onChange(0);
9707
- }
9708
- const handlePrevClick = useCallbackOrUndefined(
9709
- () => onChange(offset - limit),
9710
- [onChange, offset, limit],
9711
- offset > 0,
9712
- );
9713
- const handleNextClick = useCallbackOrUndefined(
9714
- () => onChange(offset + limit),
9715
- [onChange, offset, limit],
9716
- offset + limit < total,
9909
+
9910
+ const extraValueCells = (
9911
+ extraValueCells2 = [],
9912
+ extraValueCellProps,
9913
+ after = 0,
9914
+ ) =>
9915
+ arrayMap(extraValueCells2, ({component: Component}, index) =>
9916
+ /* @__PURE__ */ jsx(
9917
+ 'td',
9918
+ {
9919
+ className: EXTRA,
9920
+ children: /* @__PURE__ */ jsx(Component, {...extraValueCellProps}),
9921
+ },
9922
+ extraKey(index, after),
9923
+ ),
9717
9924
  );
9718
- return /* @__PURE__ */ jsxs(Fragment, {
9925
+ const ValuesInHtmlTable = ({
9926
+ store,
9927
+ editable = false,
9928
+ valueComponent: Value = editable ? EditableValueView : ValueView,
9929
+ getValueComponentProps,
9930
+ extraCellsBefore,
9931
+ extraCellsAfter,
9932
+ className,
9933
+ headerRow,
9934
+ idColumn,
9935
+ }) =>
9936
+ /* @__PURE__ */ jsxs('table', {
9937
+ className,
9719
9938
  children: [
9720
- total > limit &&
9721
- /* @__PURE__ */ jsxs(Fragment, {
9722
- children: [
9723
- /* @__PURE__ */ jsx('button', {
9724
- className: 'previous',
9725
- disabled: offset == 0,
9726
- onClick: handlePrevClick,
9727
- children: LEFT_ARROW,
9728
- }),
9729
- /* @__PURE__ */ jsx('button', {
9730
- className: 'next',
9731
- disabled: offset + limit >= total,
9732
- onClick: handleNextClick,
9733
- children: RIGHT_ARROW,
9939
+ headerRow === false
9940
+ ? null
9941
+ : /* @__PURE__ */ jsx('thead', {
9942
+ children: /* @__PURE__ */ jsxs('tr', {
9943
+ children: [
9944
+ extraHeaders(extraCellsBefore),
9945
+ idColumn === false
9946
+ ? null
9947
+ : /* @__PURE__ */ jsx('th', {children: 'Id'}),
9948
+ /* @__PURE__ */ jsx('th', {children: VALUE}),
9949
+ extraHeaders(extraCellsAfter, 1),
9950
+ ],
9734
9951
  }),
9735
- offset + 1,
9736
- ' to ',
9737
- mathMin(total, offset + limit),
9738
- ' of ',
9739
- ],
9952
+ }),
9953
+ /* @__PURE__ */ jsx('tbody', {
9954
+ children: arrayMap(useValueIds(store), (valueId) => {
9955
+ const valueProps = {valueId, store};
9956
+ return /* @__PURE__ */ jsxs(
9957
+ 'tr',
9958
+ {
9959
+ children: [
9960
+ extraValueCells(extraCellsBefore, valueProps),
9961
+ idColumn === false
9962
+ ? null
9963
+ : /* @__PURE__ */ jsx('th', {
9964
+ title: valueId,
9965
+ children: valueId,
9966
+ }),
9967
+ /* @__PURE__ */ jsx('td', {
9968
+ children: /* @__PURE__ */ jsx(Value, {
9969
+ ...getProps(getValueComponentProps, valueId),
9970
+ ...valueProps,
9971
+ }),
9972
+ }),
9973
+ extraValueCells(extraCellsAfter, valueProps, 1),
9974
+ ],
9975
+ },
9976
+ valueId,
9977
+ );
9740
9978
  }),
9741
- total,
9742
- ' ',
9743
- total != 1 ? plural : singular,
9979
+ }),
9744
9980
  ],
9745
9981
  });
9746
- };
9747
9982
 
9748
9983
  const UNIQUE_ID = 'tinybaseInspector';
9749
9984
  const TITLE = 'TinyBase Inspector';
@@ -9777,16 +10012,9 @@ const Nub = ({s}) => {
9777
10012
  title: TITLE,
9778
10013
  'data-position': position,
9779
10014
  });
9780
- };
9781
-
9782
- const Details = ({
9783
- uniqueId,
9784
- summary,
9785
- editable,
9786
- handleEditable,
9787
- children,
9788
- s,
9789
- }) => {
10015
+ };
10016
+
10017
+ const Details = ({uniqueId, title, editable, handleEditable, children, s}) => {
9790
10018
  const open = !!useCell(STATE_TABLE, uniqueId, OPEN_CELL, s);
9791
10019
  const handleToggle = useSetCellCallback(
9792
10020
  STATE_TABLE,
@@ -9802,16 +10030,17 @@ const Details = ({
9802
10030
  children: [
9803
10031
  /* @__PURE__ */ jsxs('summary', {
9804
10032
  children: [
9805
- summary,
10033
+ /* @__PURE__ */ jsx('span', {children: title}),
9806
10034
  handleEditable
9807
10035
  ? /* @__PURE__ */ jsx('img', {
9808
10036
  onClick: handleEditable,
9809
10037
  className: editable ? 'done' : 'edit',
10038
+ title: editable ? 'Done editing' : 'Edit',
9810
10039
  })
9811
10040
  : null,
9812
10041
  ],
9813
10042
  }),
9814
- children,
10043
+ /* @__PURE__ */ jsx('div', {children}),
9815
10044
  ],
9816
10045
  });
9817
10046
  };
@@ -9819,7 +10048,7 @@ const Details = ({
9819
10048
  const IndexView = ({indexes, indexesId, indexId, s}) =>
9820
10049
  /* @__PURE__ */ jsx(Details, {
9821
10050
  uniqueId: getUniqueId('i', indexesId, indexId),
9822
- summary: 'Index: ' + indexId,
10051
+ title: 'Index: ' + indexId,
9823
10052
  s,
9824
10053
  children: arrayMap(useSliceIds(indexId, indexes), (sliceId) =>
9825
10054
  /* @__PURE__ */ jsx(
@@ -9840,7 +10069,7 @@ const SliceView = ({indexes, indexesId, indexId, sliceId, s}) => {
9840
10069
  const [editable, handleEditable] = useEditable(uniqueId, s);
9841
10070
  return /* @__PURE__ */ jsx(Details, {
9842
10071
  uniqueId,
9843
- summary: 'Slice: ' + sliceId,
10072
+ title: 'Slice: ' + sliceId,
9844
10073
  editable,
9845
10074
  handleEditable,
9846
10075
  s,
@@ -9859,7 +10088,7 @@ const IndexesView = ({indexesId, s}) => {
9859
10088
  ? null
9860
10089
  : /* @__PURE__ */ jsx(Details, {
9861
10090
  uniqueId: getUniqueId('i', indexesId),
9862
- summary: 'Indexes: ' + (indexesId ?? DEFAULT),
10091
+ title: 'Indexes: ' + (indexesId ?? DEFAULT),
9863
10092
  s,
9864
10093
  children: arrayIsEmpty(indexIds)
9865
10094
  ? 'No indexes defined'
@@ -9881,7 +10110,7 @@ const IndexesView = ({indexesId, s}) => {
9881
10110
  const MetricRow = ({metrics, metricId}) =>
9882
10111
  /* @__PURE__ */ jsxs('tr', {
9883
10112
  children: [
9884
- /* @__PURE__ */ jsx('th', {children: metricId}),
10113
+ /* @__PURE__ */ jsx('th', {title: metricId, children: metricId}),
9885
10114
  /* @__PURE__ */ jsx('td', {children: metrics?.getTableId(metricId)}),
9886
10115
  /* @__PURE__ */ jsx('td', {children: useMetric(metricId, metrics)}),
9887
10116
  ],
@@ -9893,7 +10122,7 @@ const MetricsView = ({metricsId, s}) => {
9893
10122
  ? null
9894
10123
  : /* @__PURE__ */ jsx(Details, {
9895
10124
  uniqueId: getUniqueId('m', metricsId),
9896
- summary: 'Metrics: ' + (metricsId ?? DEFAULT),
10125
+ title: 'Metrics: ' + (metricsId ?? DEFAULT),
9897
10126
  s,
9898
10127
  children: arrayIsEmpty(metricIds)
9899
10128
  ? 'No metrics defined'
@@ -9935,7 +10164,7 @@ const QueryView = ({queries, queriesId, queryId, s}) => {
9935
10164
  );
9936
10165
  return /* @__PURE__ */ jsx(Details, {
9937
10166
  uniqueId,
9938
- summary: 'Query: ' + queryId,
10167
+ title: 'Query: ' + queryId,
9939
10168
  s,
9940
10169
  children: /* @__PURE__ */ jsx(ResultSortedTableInHtmlTable, {
9941
10170
  queryId,
@@ -9957,7 +10186,7 @@ const QueriesView = ({queriesId, s}) => {
9957
10186
  ? null
9958
10187
  : /* @__PURE__ */ jsx(Details, {
9959
10188
  uniqueId: getUniqueId('q', queriesId),
9960
- summary: 'Queries: ' + (queriesId ?? DEFAULT),
10189
+ title: 'Queries: ' + (queriesId ?? DEFAULT),
9961
10190
  s,
9962
10191
  children: arrayIsEmpty(queryIds)
9963
10192
  ? 'No queries defined'
@@ -9986,7 +10215,7 @@ const RelationshipView = ({
9986
10215
  const [editable, handleEditable] = useEditable(uniqueId, s);
9987
10216
  return /* @__PURE__ */ jsx(Details, {
9988
10217
  uniqueId,
9989
- summary: 'Relationship: ' + relationshipId,
10218
+ title: 'Relationship: ' + relationshipId,
9990
10219
  editable,
9991
10220
  handleEditable,
9992
10221
  s,
@@ -10004,7 +10233,7 @@ const RelationshipsView = ({relationshipsId, s}) => {
10004
10233
  ? null
10005
10234
  : /* @__PURE__ */ jsx(Details, {
10006
10235
  uniqueId: getUniqueId('r', relationshipsId),
10007
- summary: 'Relationships: ' + (relationshipsId ?? DEFAULT),
10236
+ title: 'Relationships: ' + (relationshipsId ?? DEFAULT),
10008
10237
  s,
10009
10238
  children: arrayIsEmpty(relationshipIds)
10010
10239
  ? 'No relationships defined'
@@ -10023,6 +10252,312 @@ const RelationshipsView = ({relationshipsId, s}) => {
10023
10252
  });
10024
10253
  };
10025
10254
 
10255
+ const getNewIdFromSuggestedId = (suggestedId, has) => {
10256
+ let newId;
10257
+ let suffix = 0;
10258
+ while (
10259
+ has(
10260
+ (newId =
10261
+ suggestedId +
10262
+ (suffix > 0 ? ' (copy' + (suffix > 1 ? ' ' + suffix : '') + ')' : '')),
10263
+ )
10264
+ ) {
10265
+ suffix++;
10266
+ }
10267
+ return newId;
10268
+ };
10269
+ const ConfirmableActions = ({actions, ...props}) => {
10270
+ const [confirming, setConfirming] = useState();
10271
+ const handleDone = useCallback(() => setConfirming(null), []);
10272
+ useEffect(() => {
10273
+ if (confirming != null) {
10274
+ const handleKeyDown = (e) => {
10275
+ if (confirming != null && e.key === 'Escape') {
10276
+ e.preventDefault();
10277
+ handleDone();
10278
+ }
10279
+ };
10280
+ document.addEventListener('keydown', handleKeyDown);
10281
+ return () => document.removeEventListener('keydown', handleKeyDown);
10282
+ }
10283
+ }, [confirming, handleDone]);
10284
+ if (confirming != null) {
10285
+ const [, , Component] = actions[confirming];
10286
+ return /* @__PURE__ */ jsxs(Fragment, {
10287
+ children: [
10288
+ /* @__PURE__ */ jsx(Component, {onDone: handleDone, ...props}),
10289
+ /* @__PURE__ */ jsx('img', {
10290
+ onClick: handleDone,
10291
+ title: 'Cancel',
10292
+ className: 'cancel',
10293
+ }),
10294
+ ],
10295
+ });
10296
+ } else {
10297
+ return actions.map(([icon, title], index) =>
10298
+ /* @__PURE__ */ jsx(
10299
+ 'img',
10300
+ {
10301
+ title,
10302
+ className: icon,
10303
+ onClick: () => setConfirming(index),
10304
+ },
10305
+ index,
10306
+ ),
10307
+ );
10308
+ }
10309
+ };
10310
+ const NewId = ({onDone, suggestedId, has, set, prompt = 'New Id'}) => {
10311
+ const [newId, setNewId] = useState(suggestedId);
10312
+ const [newIdOk, setNewIdOk] = useState(true);
10313
+ const [previousSuggestedId, setPreviousSuggestedNewId] =
10314
+ useState(suggestedId);
10315
+ const handleNewIdChange = (e) => {
10316
+ setNewId(e.target.value);
10317
+ setNewIdOk(!has(e.target.value));
10318
+ };
10319
+ const handleClick = useCallback(() => {
10320
+ if (has(newId)) {
10321
+ setNewIdOk(false);
10322
+ } else {
10323
+ set(newId);
10324
+ onDone();
10325
+ }
10326
+ }, [onDone, setNewIdOk, has, set, newId]);
10327
+ const handleKeyDown = useCallback(
10328
+ (e) => {
10329
+ if (e.key === 'Enter') {
10330
+ e.preventDefault();
10331
+ handleClick();
10332
+ }
10333
+ },
10334
+ [handleClick],
10335
+ );
10336
+ if (suggestedId != previousSuggestedId) {
10337
+ setNewId(suggestedId);
10338
+ setPreviousSuggestedNewId(suggestedId);
10339
+ }
10340
+ return /* @__PURE__ */ jsxs(Fragment, {
10341
+ children: [
10342
+ prompt + ': ',
10343
+ /* @__PURE__ */ jsx('input', {
10344
+ type: 'text',
10345
+ value: newId,
10346
+ onChange: handleNewIdChange,
10347
+ onKeyDown: handleKeyDown,
10348
+ autoFocus: true,
10349
+ }),
10350
+ ' ',
10351
+ /* @__PURE__ */ jsx('img', {
10352
+ onClick: handleClick,
10353
+ title: newIdOk ? 'Confirm' : 'Id already exists',
10354
+ className: newIdOk ? 'ok' : 'okDis',
10355
+ }),
10356
+ ],
10357
+ });
10358
+ };
10359
+ const Delete = ({onClick, prompt = 'Delete'}) => {
10360
+ const handleKeyDown = useCallback(
10361
+ (e) => {
10362
+ if (e.key === 'Enter') {
10363
+ e.preventDefault();
10364
+ onClick();
10365
+ }
10366
+ },
10367
+ [onClick],
10368
+ );
10369
+ useEffect(() => {
10370
+ document.addEventListener('keydown', handleKeyDown);
10371
+ return () => document.removeEventListener('keydown', handleKeyDown);
10372
+ }, [handleKeyDown]);
10373
+ return /* @__PURE__ */ jsxs(Fragment, {
10374
+ children: [
10375
+ prompt,
10376
+ '? ',
10377
+ /* @__PURE__ */ jsx('img', {onClick, title: 'Confirm', className: 'ok'}),
10378
+ ],
10379
+ });
10380
+ };
10381
+ const Actions = ({left, right}) =>
10382
+ /* @__PURE__ */ jsxs('div', {
10383
+ className: 'actions',
10384
+ children: [
10385
+ /* @__PURE__ */ jsx('div', {children: left}),
10386
+ /* @__PURE__ */ jsx('div', {children: right}),
10387
+ ],
10388
+ });
10389
+
10390
+ const useHasTableCallback = (storeOrStoreId) => {
10391
+ const store = useStoreOrStoreById(storeOrStoreId);
10392
+ return useCallback((tableId) => store?.hasTable(tableId) ?? false, [store]);
10393
+ };
10394
+ const AddTable = ({onDone, store}) => {
10395
+ const has = useHasTableCallback(store);
10396
+ return /* @__PURE__ */ jsx(NewId, {
10397
+ onDone,
10398
+ suggestedId: getNewIdFromSuggestedId('table', has),
10399
+ has,
10400
+ set: useSetTableCallback(
10401
+ (newId) => newId,
10402
+ () => ({row: {cell: ''}}),
10403
+ [],
10404
+ store,
10405
+ ),
10406
+ prompt: 'Add table',
10407
+ });
10408
+ };
10409
+ const DeleteTables = ({onDone, store}) =>
10410
+ /* @__PURE__ */ jsx(Delete, {
10411
+ onClick: useDelTablesCallback(store, onDone),
10412
+ prompt: 'Delete all tables',
10413
+ });
10414
+ const TablesActions = ({store}) =>
10415
+ /* @__PURE__ */ jsx(Actions, {
10416
+ left: /* @__PURE__ */ jsx(ConfirmableActions, {
10417
+ actions: [['add', 'Add table', AddTable]],
10418
+ store,
10419
+ }),
10420
+ right: useHasTables(store)
10421
+ ? /* @__PURE__ */ jsx(ConfirmableActions, {
10422
+ actions: [['delete', 'Delete all tables', DeleteTables]],
10423
+ store,
10424
+ })
10425
+ : null,
10426
+ });
10427
+ const AddRow = ({onDone, tableId, store}) => {
10428
+ const has = useHasRowCallback(store, tableId);
10429
+ return /* @__PURE__ */ jsx(NewId, {
10430
+ onDone,
10431
+ suggestedId: getNewIdFromSuggestedId('row', has),
10432
+ has,
10433
+ set: useSetRowCallback(
10434
+ tableId,
10435
+ (newId) => newId,
10436
+ (_, store2) =>
10437
+ objNew(
10438
+ arrayMap(store2.getTableCellIds(tableId), (cellId) => [cellId, '']),
10439
+ ),
10440
+ ),
10441
+ prompt: 'Add row',
10442
+ });
10443
+ };
10444
+ const CloneTable = ({onDone, tableId, store: storeOrStoreId}) => {
10445
+ const store = useStoreOrStoreById(storeOrStoreId);
10446
+ const has = useHasTableCallback(store);
10447
+ return /* @__PURE__ */ jsx(NewId, {
10448
+ onDone,
10449
+ suggestedId: getNewIdFromSuggestedId(tableId, has),
10450
+ has,
10451
+ set: useSetTableCallback(
10452
+ (tableId2) => tableId2,
10453
+ (_, store2) => store2.getTable(tableId),
10454
+ ),
10455
+ prompt: 'Clone table to',
10456
+ });
10457
+ };
10458
+ const DeleteTable = ({onDone, tableId, store}) =>
10459
+ /* @__PURE__ */ jsx(Delete, {
10460
+ onClick: useDelTableCallback(tableId, store, onDone),
10461
+ prompt: 'Delete table',
10462
+ });
10463
+ const TableActions1 = ({tableId, store}) =>
10464
+ /* @__PURE__ */ jsx(ConfirmableActions, {
10465
+ actions: [['add', 'Add row', AddRow]],
10466
+ store,
10467
+ tableId,
10468
+ });
10469
+ const TableActions2 = ({tableId, store}) =>
10470
+ /* @__PURE__ */ jsx(ConfirmableActions, {
10471
+ actions: [
10472
+ ['clone', 'Clone table', CloneTable],
10473
+ ['delete', 'Delete table', DeleteTable],
10474
+ ],
10475
+ store,
10476
+ tableId,
10477
+ });
10478
+ const useHasRowCallback = (storeOrStoreId, tableId) => {
10479
+ const store = useStoreOrStoreById(storeOrStoreId);
10480
+ return useCallback(
10481
+ (rowId) => store?.hasRow(tableId, rowId) ?? false,
10482
+ [store, tableId],
10483
+ );
10484
+ };
10485
+ const AddCell = ({onDone, tableId, rowId, store: storeOrStoreId}) => {
10486
+ const store = useStoreOrStoreById(storeOrStoreId);
10487
+ const has = useCallback(
10488
+ (cellId) => store.hasCell(tableId, rowId, cellId),
10489
+ [store, tableId, rowId],
10490
+ );
10491
+ return /* @__PURE__ */ jsx(NewId, {
10492
+ onDone,
10493
+ suggestedId: getNewIdFromSuggestedId('cell', has),
10494
+ has,
10495
+ set: useSetCellCallback(
10496
+ tableId,
10497
+ rowId,
10498
+ (newId) => newId,
10499
+ () => '',
10500
+ [],
10501
+ store,
10502
+ ),
10503
+ prompt: 'Add cell',
10504
+ });
10505
+ };
10506
+ const CloneRow = ({onDone, tableId, rowId, store: storeOrStoreId}) => {
10507
+ const store = useStoreOrStoreById(storeOrStoreId);
10508
+ const has = useHasRowCallback(store, tableId);
10509
+ return /* @__PURE__ */ jsx(NewId, {
10510
+ onDone,
10511
+ suggestedId: getNewIdFromSuggestedId(rowId, has),
10512
+ has,
10513
+ set: useSetRowCallback(
10514
+ tableId,
10515
+ (newId) => newId,
10516
+ (_, store2) => store2.getRow(tableId, rowId),
10517
+ [rowId],
10518
+ ),
10519
+ prompt: 'Clone row to',
10520
+ });
10521
+ };
10522
+ const DeleteRow = ({onDone, tableId, rowId, store}) =>
10523
+ /* @__PURE__ */ jsx(Delete, {
10524
+ onClick: useDelRowCallback(tableId, rowId, store, onDone),
10525
+ prompt: 'Delete row',
10526
+ });
10527
+ const RowActions = ({tableId, rowId, store}) =>
10528
+ /* @__PURE__ */ jsx(ConfirmableActions, {
10529
+ actions: [
10530
+ ['add', 'Add cell', AddCell],
10531
+ ['clone', 'Clone row', CloneRow],
10532
+ ['delete', 'Delete row', DeleteRow],
10533
+ ],
10534
+ store,
10535
+ tableId,
10536
+ rowId,
10537
+ });
10538
+ const CellDelete = ({onDone, tableId, rowId, cellId, store}) =>
10539
+ /* @__PURE__ */ jsx(Delete, {
10540
+ onClick: useDelCellCallback(tableId, rowId, cellId, true, store, onDone),
10541
+ prompt: 'Delete cell',
10542
+ });
10543
+ const CellActions = ({tableId, rowId, cellId, store}) =>
10544
+ /* @__PURE__ */ jsx(ConfirmableActions, {
10545
+ actions: [['delete', 'Delete cell', CellDelete]],
10546
+ store,
10547
+ tableId,
10548
+ rowId,
10549
+ cellId,
10550
+ });
10551
+
10552
+ const rowActions = [{label: '', component: RowActions}];
10553
+ const EditableCellViewWithActions = (props) =>
10554
+ /* @__PURE__ */ jsxs(Fragment, {
10555
+ children: [
10556
+ /* @__PURE__ */ jsx(EditableCellView, {...props}),
10557
+ useHasCell(props.tableId, props.rowId, props.cellId, props.store) &&
10558
+ /* @__PURE__ */ jsx(CellActions, {...props}),
10559
+ ],
10560
+ });
10026
10561
  const TableView = ({tableId, store, storeId, s}) => {
10027
10562
  const uniqueId = getUniqueId('t', storeId, tableId);
10028
10563
  const [cellId, descending, offset] = jsonParse(
@@ -10037,66 +10572,183 @@ const TableView = ({tableId, store, storeId, s}) => {
10037
10572
  s,
10038
10573
  );
10039
10574
  const [editable, handleEditable] = useEditable(uniqueId, s);
10040
- return /* @__PURE__ */ jsx(Details, {
10575
+ const CellComponent = editable ? EditableCellViewWithActions : CellView;
10576
+ return /* @__PURE__ */ jsxs(Details, {
10041
10577
  uniqueId,
10042
- summary: TABLE$1 + ': ' + tableId,
10578
+ title: TABLE$1 + ': ' + tableId,
10043
10579
  editable,
10044
10580
  handleEditable,
10045
10581
  s,
10046
- children: /* @__PURE__ */ jsx(SortedTableInHtmlTable, {
10047
- tableId,
10582
+ children: [
10583
+ /* @__PURE__ */ jsx(SortedTableInHtmlTable, {
10584
+ tableId,
10585
+ store,
10586
+ cellId,
10587
+ descending,
10588
+ offset,
10589
+ limit: 10,
10590
+ paginator: true,
10591
+ sortOnClick: true,
10592
+ onChange: handleChange,
10593
+ editable,
10594
+ extraCellsAfter: editable ? rowActions : [],
10595
+ customCells: objNew(
10596
+ arrayMap(useTableCellIds(tableId, store), (cellId2) => [
10597
+ cellId2,
10598
+ {label: cellId2, component: CellComponent},
10599
+ ]),
10600
+ ),
10601
+ }),
10602
+ editable
10603
+ ? /* @__PURE__ */ jsxs('div', {
10604
+ className: 'actions',
10605
+ children: [
10606
+ /* @__PURE__ */ jsx('div', {
10607
+ children: /* @__PURE__ */ jsx(TableActions1, {tableId, store}),
10608
+ }),
10609
+ /* @__PURE__ */ jsx('div', {
10610
+ children: /* @__PURE__ */ jsx(TableActions2, {tableId, store}),
10611
+ }),
10612
+ ],
10613
+ })
10614
+ : null,
10615
+ ],
10616
+ });
10617
+ };
10618
+ const TablesView = ({store, storeId, s}) => {
10619
+ const uniqueId = getUniqueId('ts', storeId);
10620
+ const [editable, handleEditable] = useEditable(uniqueId, s);
10621
+ const tableIds = useTableIds(store);
10622
+ return /* @__PURE__ */ jsxs(Details, {
10623
+ uniqueId,
10624
+ title: TABLES,
10625
+ editable,
10626
+ handleEditable,
10627
+ s,
10628
+ children: [
10629
+ arrayIsEmpty(tableIds)
10630
+ ? /* @__PURE__ */ jsx('caption', {children: 'No tables.'})
10631
+ : sortedIdsMap(tableIds, (tableId) =>
10632
+ /* @__PURE__ */ jsx(
10633
+ TableView,
10634
+ {
10635
+ store,
10636
+ storeId,
10637
+ tableId,
10638
+ s,
10639
+ },
10640
+ tableId,
10641
+ ),
10642
+ ),
10643
+ editable ? /* @__PURE__ */ jsx(TablesActions, {store}) : null,
10644
+ ],
10645
+ });
10646
+ };
10647
+
10648
+ const useHasValueCallback = (storeOrStoreId) => {
10649
+ const store = useStoreOrStoreById(storeOrStoreId);
10650
+ return useCallback((valueId) => store?.hasValue(valueId) ?? false, [store]);
10651
+ };
10652
+ const AddValue = ({onDone, store}) => {
10653
+ const has = useHasValueCallback(store);
10654
+ return /* @__PURE__ */ jsx(NewId, {
10655
+ onDone,
10656
+ suggestedId: getNewIdFromSuggestedId('value', has),
10657
+ has,
10658
+ set: useSetValueCallback(
10659
+ (newId) => newId,
10660
+ () => '',
10661
+ [],
10662
+ store,
10663
+ ),
10664
+ prompt: 'Add value',
10665
+ });
10666
+ };
10667
+ const DeleteValues = ({onDone, store}) =>
10668
+ /* @__PURE__ */ jsx(Delete, {
10669
+ onClick: useDelValuesCallback(store, onDone),
10670
+ prompt: 'Delete all values',
10671
+ });
10672
+ const ValuesActions = ({store}) =>
10673
+ /* @__PURE__ */ jsx(Actions, {
10674
+ left: /* @__PURE__ */ jsx(ConfirmableActions, {
10675
+ actions: [['add', 'Add value', AddValue]],
10048
10676
  store,
10049
- cellId,
10050
- descending,
10051
- offset,
10052
- limit: 10,
10053
- paginator: true,
10054
- sortOnClick: true,
10055
- onChange: handleChange,
10056
- editable,
10057
10677
  }),
10678
+ right: useHasValues(store)
10679
+ ? /* @__PURE__ */ jsx(ConfirmableActions, {
10680
+ actions: [['delete', 'Delete all values', DeleteValues]],
10681
+ store,
10682
+ })
10683
+ : null,
10684
+ });
10685
+ const CloneValue = ({onDone, valueId, store}) => {
10686
+ const has = useHasValueCallback(store);
10687
+ return /* @__PURE__ */ jsx(NewId, {
10688
+ onDone,
10689
+ suggestedId: getNewIdFromSuggestedId(valueId, has),
10690
+ has,
10691
+ set: useSetValueCallback(
10692
+ (newId) => newId,
10693
+ (_, store2) => store2.getValue(valueId) ?? '',
10694
+ [valueId],
10695
+ store,
10696
+ ),
10697
+ prompt: 'Clone value to',
10058
10698
  });
10059
10699
  };
10700
+ const DeleteValue = ({onDone, valueId, store}) =>
10701
+ /* @__PURE__ */ jsx(Delete, {
10702
+ onClick: useDelValueCallback(valueId, store, onDone),
10703
+ prompt: 'Delete value',
10704
+ });
10705
+ const ValueActions = ({valueId, store}) =>
10706
+ /* @__PURE__ */ jsx(ConfirmableActions, {
10707
+ actions: [
10708
+ ['clone', 'Clone value', CloneValue],
10709
+ ['delete', 'Delete value', DeleteValue],
10710
+ ],
10711
+ store,
10712
+ valueId,
10713
+ });
10714
+
10715
+ const valueActions = [{label: '', component: ValueActions}];
10060
10716
  const ValuesView = ({store, storeId, s}) => {
10061
10717
  const uniqueId = getUniqueId('v', storeId);
10062
10718
  const [editable, handleEditable] = useEditable(uniqueId, s);
10063
- return arrayIsEmpty(useValueIds(store))
10064
- ? null
10065
- : /* @__PURE__ */ jsx(Details, {
10066
- uniqueId,
10067
- summary: VALUES,
10068
- editable,
10069
- handleEditable,
10070
- s,
10071
- children: /* @__PURE__ */ jsx(ValuesInHtmlTable, {store, editable}),
10072
- });
10719
+ return /* @__PURE__ */ jsxs(Details, {
10720
+ uniqueId,
10721
+ title: VALUES,
10722
+ editable,
10723
+ handleEditable,
10724
+ s,
10725
+ children: [
10726
+ arrayIsEmpty(useValueIds(store))
10727
+ ? /* @__PURE__ */ jsx('caption', {children: 'No values.'})
10728
+ : /* @__PURE__ */ jsx(ValuesInHtmlTable, {
10729
+ store,
10730
+ editable,
10731
+ extraCellsAfter: editable ? valueActions : [],
10732
+ }),
10733
+ editable ? /* @__PURE__ */ jsx(ValuesActions, {store}) : null,
10734
+ ],
10735
+ });
10073
10736
  };
10737
+
10074
10738
  const StoreView = ({storeId, s}) => {
10075
10739
  const store = useStore(storeId);
10076
- const tableIds = useTableIds(store);
10077
10740
  return isUndefined(store)
10078
10741
  ? null
10079
10742
  : /* @__PURE__ */ jsxs(Details, {
10080
10743
  uniqueId: getUniqueId('s', storeId),
10081
- summary:
10744
+ title:
10082
10745
  (store.isMergeable() ? 'Mergeable' : '') +
10083
10746
  'Store: ' +
10084
10747
  (storeId ?? DEFAULT),
10085
10748
  s,
10086
10749
  children: [
10087
10750
  /* @__PURE__ */ jsx(ValuesView, {storeId, store, s}),
10088
- sortedIdsMap(tableIds, (tableId) =>
10089
- /* @__PURE__ */ jsx(
10090
- TableView,
10091
- {
10092
- store,
10093
- storeId,
10094
- tableId,
10095
- s,
10096
- },
10097
- tableId,
10098
- ),
10099
- ),
10751
+ /* @__PURE__ */ jsx(TablesView, {storeId, store, s}),
10100
10752
  ],
10101
10753
  });
10102
10754
  };
@@ -10217,6 +10869,7 @@ class ErrorBoundary extends PureComponent {
10217
10869
 
10218
10870
  const Header = ({s}) => {
10219
10871
  const position = useValue(POSITION_VALUE, s) ?? 1;
10872
+ const handleClick = () => open('https://tinybase.org', '_blank');
10220
10873
  const handleClose = useSetValueCallback(OPEN_VALUE, () => false, [], s);
10221
10874
  const handleDock = useSetValueCallback(
10222
10875
  POSITION_VALUE,
@@ -10226,7 +10879,11 @@ const Header = ({s}) => {
10226
10879
  );
10227
10880
  return /* @__PURE__ */ jsxs('header', {
10228
10881
  children: [
10229
- /* @__PURE__ */ jsx('img', {title: TITLE}),
10882
+ /* @__PURE__ */ jsx('img', {
10883
+ className: 'flat',
10884
+ title: TITLE,
10885
+ onClick: handleClick,
10886
+ }),
10230
10887
  /* @__PURE__ */ jsx('span', {children: TITLE}),
10231
10888
  arrayMap(POSITIONS, (name, p) =>
10232
10889
  p == position
@@ -10241,7 +10898,11 @@ const Header = ({s}) => {
10241
10898
  p,
10242
10899
  ),
10243
10900
  ),
10244
- /* @__PURE__ */ jsx('img', {onClick: handleClose, title: 'Close'}),
10901
+ /* @__PURE__ */ jsx('img', {
10902
+ className: 'flat',
10903
+ onClick: handleClose,
10904
+ title: 'Close',
10905
+ }),
10245
10906
  ],
10246
10907
  });
10247
10908
  };
@@ -10264,70 +10925,237 @@ const Panel = ({s}) => {
10264
10925
  var img =
10265
10926
  "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";
10266
10927
 
10267
- const PENCIL = 'M20 80l5-15l40-40l10 10l-40 40l-15 5m5-15l10 10';
10268
- const PRE_CSS = 'content:url("';
10928
+ const PRE_CSS = 'url("';
10269
10929
  const POST_CSS = '")';
10270
- const PRE =
10271
- PRE_CSS +
10272
- `data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100' stroke-width='4' stroke='white' fill='none'>`;
10273
- const POST = `</svg>` + POST_CSS;
10274
- const LOGO_SVG = PRE_CSS + img + POST_CSS;
10930
+ const getCssSvg = (path, color = 'white') => ({
10931
+ content:
10932
+ PRE_CSS +
10933
+ `data:image/svg+xml,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 -960 960 960' fill='${color}'><path d='${path}' /></svg>` +
10934
+ POST_CSS,
10935
+ });
10936
+ const VERTICAL_THIN = 'v560h120v-560h-120Z';
10937
+ const VERTICAL_THICK = 'v560h360v-560h-360Z';
10938
+ const HORIZONTAL_THIN = 'v120h560v-120h-560Z';
10939
+ const HORIZONTAL_THICK = 'v360h560v-360h-560Z';
10940
+ const LOGO_SVG = {content: PRE_CSS + img + POST_CSS};
10275
10941
  const POSITIONS_SVG = arrayMap(
10276
10942
  [
10277
- [20, 20, 20, 60],
10278
- [20, 20, 60, 20],
10279
- [20, 60, 60, 20],
10280
- [60, 20, 20, 60],
10281
- [30, 30, 40, 40],
10943
+ `M200-760${VERTICAL_THIN} M400-760${VERTICAL_THICK}`,
10944
+ `M200-760${HORIZONTAL_THIN} M200-560${HORIZONTAL_THICK}`,
10945
+ `M200-760${HORIZONTAL_THICK} M200-320${HORIZONTAL_THIN}`,
10946
+ `M200-760${VERTICAL_THICK} M640-760${VERTICAL_THIN}`,
10282
10947
  ],
10283
- ([x, y, w, h]) =>
10284
- PRE +
10285
- `<rect x='20' y='20' width='60' height='60' fill='grey'/><rect x='${x}' y='${y}' width='${w}' height='${h}' fill='white'/>` +
10286
- POST,
10948
+ (path) =>
10949
+ getCssSvg(
10950
+ 'M200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Z' +
10951
+ path,
10952
+ ),
10953
+ );
10954
+ arrayPush(
10955
+ POSITIONS_SVG,
10956
+ getCssSvg(
10957
+ 'M120-120v-200h80v120h120v80H120Zm520 0v-80h120v-120h80v200H640ZM120-640v-200h200v80H200v120h-80Zm640 0v-120H640v-80h200v200h-80Z',
10958
+ ),
10959
+ );
10960
+ const CLOSE_SVG = getCssSvg(
10961
+ 'm336-280-56-56 144-144-144-143 56-56 144 144 143-144 56 56-144 143 144 144-56 56-143-144-144 144Z',
10962
+ );
10963
+ const EDIT_SVG = getCssSvg(
10964
+ 'M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z',
10965
+ );
10966
+ const DONE_SVG = getCssSvg(
10967
+ 'm622-453-56-56 82-82-57-57-82 82-56-56 195-195q12-12 26.5-17.5T705-840q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L622-453ZM200-200h57l195-195-28-29-29-28-195 195v57ZM792-56 509-338 290-120H120v-169l219-219L56-792l57-57 736 736-57 57Zm-32-648-56-56 56 56Zm-169 56 57 57-57-57ZM424-424l-29-28 57 57-28-29Z',
10968
+ );
10969
+ const ADD_SVG = getCssSvg(
10970
+ 'M440-280h80v-160h160v-80H520v-160h-80v160H280v80h160v160ZM200-120q-33 0-56.5-23.5T120-200v-560q0-33 23.5-56.5T200-840h560q33 0 56.5 23.5T840-760v560q0 33-23.5 56.5T760-120H200Zm0-80h560v-560H200v560Zm0-560v560-560Z',
10971
+ );
10972
+ const CLONE_SVG = getCssSvg(
10973
+ 'M520-400h80v-120h120v-80H600v-120h-80v120H400v80h120v120ZM320-240q-33 0-56.5-23.5T240-320v-480q0-33 23.5-56.5T320-880h480q33 0 56.5 23.5T880-800v480q0 33-23.5 56.5T800-240H320Zm0-80h480v-480H320v480ZM160-80q-33 0-56.5-23.5T80-160v-560h80v560h560v80H160Zm160-720v480-480Z',
10974
+ );
10975
+ const DELETE_SVG = getCssSvg(
10976
+ 'M280-120q-33 0-56.5-23.5T200-200v-520h-40v-80h200v-40h240v40h200v80h-40v520q0 33-23.5 56.5T680-120H280Zm400-600H280v520h400v-520ZM360-280h80v-360h-80v360Zm160 0h80v-360h-80v360ZM280-720v520-520Z',
10977
+ );
10978
+ const OK_SVG = getCssSvg(
10979
+ 'm424-296 282-282-56-56-226 226-114-114-56 56 170 170Zm56 216q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z',
10980
+ 'rgb(127,255,127)',
10981
+ );
10982
+ const OK_SVG_DISABLED = getCssSvg(
10983
+ 'm40-120 440-760 440 760H40Zm138-80h604L480-720 178-200Zm302-40q17 0 28.5-11.5T520-280q0-17-11.5-28.5T480-320q-17 0-28.5 11.5T440-280q0 17 11.5 28.5T480-240Zm-40-120h80v-200h-80v200Zm40-100Z',
10984
+ 'rgb(255,255,127)',
10985
+ );
10986
+ const CANCEL_SVG = getCssSvg(
10987
+ 'm336-280 144-144 144 144 56-56-144-144 144-144-56-56-144 144-144-144-56 56 144 144-144 144 56 56ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z',
10988
+ 'rgb(255,127,127)',
10989
+ );
10990
+ const DOWN_SVG = getCssSvg(
10991
+ 'M480-344 240-584l56-56 184 184 184-184 56 56-240 240Z',
10992
+ );
10993
+ const RIGHT_SVG = getCssSvg(
10994
+ 'M504-480 320-664l56-56 240 240-240 240-56-56 184-184Z',
10287
10995
  );
10288
- const CLOSE_SVG = PRE + `<path d='M20 20l60 60M20 80l60-60' />` + POST;
10289
- const EDIT_SVG = PRE + `<path d='${PENCIL}' />` + POST;
10290
- const DONE_SVG = PRE + `<path d='${PENCIL}M20 20l60 60' />` + POST;
10291
10996
 
10292
10997
  const SCROLLBAR = '*::-webkit-scrollbar';
10998
+ const BACKGROUND = 'background';
10999
+ const WIDTH = 'width';
11000
+ const MAX_WIDTH = 'max-' + WIDTH;
11001
+ const MIN_WIDTH = 'min-' + WIDTH;
11002
+ const HEIGHT = 'height';
11003
+ const BORDER = 'border';
11004
+ const BORDER_RADIUS = BORDER + '-radius';
11005
+ const PADDING = 'padding';
11006
+ const MARGIN = 'margin';
11007
+ const MARGIN_RIGHT = MARGIN + '-right';
11008
+ const TOP = 'top';
11009
+ const BOTTOM = 'bottom';
11010
+ const LEFT = 'left';
11011
+ const RIGHT = 'right';
11012
+ const COLOR = 'color';
11013
+ const POSITION = 'position';
11014
+ const BOX_SHADOW = 'box-shadow';
11015
+ const FONT_SIZE = 'font-size';
11016
+ const DISPLAY = 'display';
11017
+ const OVERFLOW = 'overflow';
11018
+ const CURSOR = 'cursor';
11019
+ const VERTICAL_ALIGN = 'vertical-align';
11020
+ const TEXT_ALIGN = 'text-align';
11021
+ const JUSTIFY_CONTENT = 'justify-content';
11022
+ const FIXED = 'fixed';
11023
+ const REVERT = 'revert';
11024
+ const UNSET = 'unset';
11025
+ const NONE = 'none';
11026
+ const FLEX = 'flex';
11027
+ const POINTER = 'pointer';
11028
+ const AUTO = 'auto';
11029
+ const HIDDEN = 'hidden';
11030
+ const NOWRAP = 'nowrap';
11031
+ const oklch = (lPercent, remainder = '% 0.01 ' + cssVar('hue')) =>
11032
+ `oklch(${lPercent}${remainder})`;
11033
+ const cssVar = (name) => `var(--${name})`;
11034
+ const rem = (...rems) => `${rems.join('rem ')}rem`;
11035
+ const px = (...pxs) => `${pxs.join('px ')}px`;
11036
+ const vw = (vw2 = 100) => `${vw2}vw`;
11037
+ const vh = (vh2 = 100) => `${vh2}vh`;
10293
11038
  const APP_STYLESHEET = arrayJoin(
10294
11039
  objToArray(
10295
11040
  {
10296
- '': 'all:initial;font-family:sans-serif;font-size:0.75rem;position:fixed;z-index:999999',
10297
- '*': 'all:revert',
10298
- '*::before': 'all:revert',
10299
- '*::after': 'all:revert',
10300
- [SCROLLBAR]: 'width:0.5rem;height:0.5rem;',
10301
- [SCROLLBAR + '-track']: 'background:#111',
10302
- [SCROLLBAR + '-thumb']: 'background:#999;border:1px solid #111',
10303
- [SCROLLBAR + '-thumb:hover']: 'background:#fff',
10304
- [SCROLLBAR + '-corner']: 'background:#111',
10305
- img: 'width:1rem;height:1rem;background:#111;border:0;vertical-align:text-bottom',
11041
+ '': {
11042
+ all: 'initial',
11043
+ [FONT_SIZE]: rem(0.75),
11044
+ [POSITION]: FIXED,
11045
+ 'font-family': 'inter,sans-serif',
11046
+ 'z-index': 999999,
11047
+ '--bg': oklch(20),
11048
+ '--bg2': oklch(15),
11049
+ '--bg3': oklch(25),
11050
+ '--bg4': oklch(30),
11051
+ '--fg': oklch(85),
11052
+ '--fg2': oklch(60),
11053
+ ['--' + BORDER]: px(1) + ' solid ' + cssVar('bg4'),
11054
+ ['--' + BOX_SHADOW]: px(0, 1, 2, 0) + ' #0007',
11055
+ },
11056
+ '*': {all: REVERT},
11057
+ '*::before': {all: REVERT},
11058
+ '*::after': {all: REVERT},
11059
+ [SCROLLBAR]: {[WIDTH]: rem(0.5), [HEIGHT]: rem(0.5)},
11060
+ [SCROLLBAR + '-thumb']: {[BACKGROUND]: cssVar('bg4')},
11061
+ [SCROLLBAR + '-thumb:hover']: {[BACKGROUND]: cssVar('bg4')},
11062
+ [SCROLLBAR + '-corner']: {[BACKGROUND]: NONE},
11063
+ [SCROLLBAR + '-track']: {[BACKGROUND]: NONE},
11064
+ img: {
11065
+ [WIDTH]: rem(0.8),
11066
+ [HEIGHT]: rem(0.8),
11067
+ [VERTICAL_ALIGN]: 'text-' + BOTTOM,
11068
+ [CURSOR]: POINTER,
11069
+ [MARGIN]: px(-2.5, 2, -2.5, 0),
11070
+ [PADDING]: px(2),
11071
+ [BORDER]: cssVar(BORDER),
11072
+ [BACKGROUND]: cssVar('bg3'),
11073
+ [BOX_SHADOW]: cssVar(BOX_SHADOW),
11074
+ [BORDER_RADIUS]: rem(0.25),
11075
+ },
11076
+ 'img.flat': {[BORDER]: NONE, [BACKGROUND]: NONE, [BOX_SHADOW]: NONE},
10306
11077
  // Nub
10307
- '>img': 'padding:0.25rem;bottom:0;right:0;position:fixed;' + LOGO_SVG,
11078
+ '>img': {
11079
+ [PADDING]: rem(0.25),
11080
+ [BOTTOM]: 0,
11081
+ [RIGHT]: 0,
11082
+ [POSITION]: FIXED,
11083
+ [HEIGHT]: UNSET,
11084
+ [MARGIN]: 0,
11085
+ ...LOGO_SVG,
11086
+ },
10308
11087
  ...objNew(
10309
- arrayMap(['bottom:0;left:0', 'top:0;right:0'], (css, p) => [
10310
- `>img[data-position='${p}']`,
10311
- css,
10312
- ]),
11088
+ arrayMap(
11089
+ [
11090
+ {[BOTTOM]: 0, [LEFT]: 0},
11091
+ {[TOP]: 0, [RIGHT]: 0},
11092
+ ],
11093
+ (css, p) => [`>img[data-position='${p}']`, css],
11094
+ ),
10313
11095
  ),
10314
11096
  // Panel
10315
- main: 'display:flex;flex-direction:column;background:#111d;color:#fff;position:fixed;',
11097
+ main: {
11098
+ [DISPLAY]: FLEX,
11099
+ [COLOR]: cssVar('fg'),
11100
+ [BACKGROUND]: cssVar('bg'),
11101
+ [OVERFLOW]: HIDDEN,
11102
+ [POSITION]: FIXED,
11103
+ [BOX_SHADOW]: cssVar(BOX_SHADOW),
11104
+ 'flex-direction': 'column',
11105
+ },
10316
11106
  ...objNew(
10317
11107
  arrayMap(
10318
11108
  [
10319
- 'bottom:0;left:0;width:35vw;height:100vh',
10320
- 'top:0;right:0;width:100vw;height:30vh',
10321
- 'bottom:0;left:0;width:100vw;height:30vh',
10322
- 'top:0;right:0;width:35vw;height:100vh',
10323
- 'top:0;right:0;width:100vw;height:100vh',
11109
+ {
11110
+ [BOTTOM]: 0,
11111
+ [LEFT]: 0,
11112
+ [WIDTH]: vw(35),
11113
+ [HEIGHT]: vh(),
11114
+ [BORDER + '-' + RIGHT]: cssVar(BORDER),
11115
+ },
11116
+ {
11117
+ [TOP]: 0,
11118
+ [RIGHT]: 0,
11119
+ [WIDTH]: vw(),
11120
+ [HEIGHT]: vh(30),
11121
+ [BORDER + '-' + BOTTOM]: cssVar(BORDER),
11122
+ },
11123
+ {
11124
+ [BOTTOM]: 0,
11125
+ [LEFT]: 0,
11126
+ [WIDTH]: vw(),
11127
+ [HEIGHT]: vh(30),
11128
+ [BORDER + '-' + TOP]: cssVar(BORDER),
11129
+ },
11130
+ {
11131
+ [TOP]: 0,
11132
+ [RIGHT]: 0,
11133
+ [WIDTH]: vw(35),
11134
+ [HEIGHT]: vh(),
11135
+ [BORDER + '-' + LEFT]: cssVar(BORDER),
11136
+ },
11137
+ {[TOP]: 0, [RIGHT]: 0, [WIDTH]: vw(), [HEIGHT]: vh()},
10324
11138
  ],
10325
11139
  (css, p) => [`main[data-position='${p}']`, css],
10326
11140
  ),
10327
11141
  ),
10328
11142
  // Header
10329
- header: 'display:flex;padding:0.25rem;background:#000;align-items:center',
10330
- 'header>img:nth-of-type(1)': LOGO_SVG,
11143
+ header: {
11144
+ [DISPLAY]: FLEX,
11145
+ [PADDING]: rem(0.5),
11146
+ [BOX_SHADOW]: cssVar(BOX_SHADOW),
11147
+ [BACKGROUND]: oklch(30, '% 0.008 var(--hue) / .5'),
11148
+ [WIDTH]: 'calc(100% - .5rem)',
11149
+ [POSITION]: 'absolute',
11150
+ [BORDER + '-' + BOTTOM]: cssVar(BORDER),
11151
+ 'align-items': 'center',
11152
+ 'backdrop-filter': 'blur(4px)',
11153
+ },
11154
+ 'header>img:nth-of-type(1)': {
11155
+ [HEIGHT]: rem(1),
11156
+ [WIDTH]: rem(1),
11157
+ ...LOGO_SVG,
11158
+ },
10331
11159
  'header>img:nth-of-type(6)': CLOSE_SVG,
10332
11160
  ...objNew(
10333
11161
  arrayMap(POSITIONS_SVG, (SVG, p) => [
@@ -10335,42 +11163,140 @@ const APP_STYLESHEET = arrayJoin(
10335
11163
  SVG,
10336
11164
  ]),
10337
11165
  ),
10338
- 'header>span':
10339
- 'flex:1;overflow:hidden;white-space:nowrap;text-overflow:ellipsis;margin-left:0.25rem',
11166
+ 'header>span': {
11167
+ [OVERFLOW]: HIDDEN,
11168
+ [FLEX]: 1,
11169
+ 'font-weight': 800,
11170
+ 'white-space': NOWRAP,
11171
+ 'text-overflow': 'ellipsis',
11172
+ },
10340
11173
  // Body
10341
- article: 'padding:0.25rem 0.25rem 0.25rem 0.5rem;overflow:auto;flex:1',
10342
- details: 'margin-left:0.75rem;width:fit-content;',
10343
- 'details img': 'display:none',
10344
- 'details[open]>summary img':
10345
- 'display:unset;background:none;margin-left:0.25rem',
10346
- 'details[open]>summary img.edit': EDIT_SVG,
10347
- 'details[open]>summary img.done': DONE_SVG,
10348
- summary:
10349
- 'margin-left:-0.75rem;line-height:1.25rem;user-select:none;width:fit-content',
11174
+ article: {[OVERFLOW]: AUTO, [FLEX]: 1, [PADDING + '-' + TOP]: rem(2)},
11175
+ details: {
11176
+ [MARGIN]: rem(0.5),
11177
+ [BORDER]: cssVar(BORDER),
11178
+ [BORDER_RADIUS]: rem(0.25),
11179
+ },
11180
+ summary: {
11181
+ [BACKGROUND]: cssVar('bg3'),
11182
+ [MARGIN]: px(-1),
11183
+ [BORDER]: cssVar(BORDER),
11184
+ [PADDING]: rem(0.25, 0.125),
11185
+ [DISPLAY]: FLEX,
11186
+ [BORDER_RADIUS]: rem(0.25),
11187
+ 'user-select': NONE,
11188
+ [JUSTIFY_CONTENT]: 'space-between',
11189
+ 'align-items': 'center',
11190
+ },
11191
+ 'summary>span::before': {
11192
+ [DISPLAY]: 'inline-block',
11193
+ [VERTICAL_ALIGN]: 'sub',
11194
+ [MARGIN]: px(2),
11195
+ [WIDTH]: rem(1),
11196
+ [HEIGHT]: rem(1),
11197
+ ...RIGHT_SVG,
11198
+ },
11199
+ 'details[open]>summary': {
11200
+ 'border-bottom-left-radius': 0,
11201
+ 'border-bottom-right-radius': 0,
11202
+ [MARGIN + '-' + BOTTOM]: 0,
11203
+ },
11204
+ 'details[open]>summary>span::before': DOWN_SVG,
11205
+ 'details>summary img': {[DISPLAY]: NONE},
11206
+ 'details[open]>summary img': {
11207
+ [DISPLAY]: UNSET,
11208
+ [MARGIN + '-' + LEFT]: rem(0.25),
11209
+ },
11210
+ 'details>div': {[OVERFLOW]: AUTO},
11211
+ caption: {
11212
+ [COLOR]: cssVar('fg2'),
11213
+ [PADDING]: rem(0.25, 0.5),
11214
+ [TEXT_ALIGN]: LEFT,
11215
+ 'white-space': NOWRAP,
11216
+ },
11217
+ 'caption button': {
11218
+ [WIDTH]: rem(1.5),
11219
+ [BORDER]: NONE,
11220
+ [BACKGROUND]: NONE,
11221
+ [COLOR]: cssVar('fg'),
11222
+ [PADDING]: 0,
11223
+ [CURSOR]: POINTER,
11224
+ },
11225
+ 'caption button[disabled]': {[COLOR]: cssVar('fg2')},
11226
+ '.actions': {
11227
+ [PADDING]: rem(0.75, 0.5),
11228
+ [MARGIN]: 0,
11229
+ [DISPLAY]: FLEX,
11230
+ [BORDER + '-' + TOP]: cssVar(BORDER),
11231
+ [JUSTIFY_CONTENT]: 'space-between',
11232
+ },
10350
11233
  // tables
10351
- table: 'border-collapse:collapse;table-layout:fixed;margin-bottom:0.5rem',
10352
- 'table input':
10353
- 'background:#111;color:unset;padding:0 0.25rem;border:0;font-size:unset;vertical-align:top;margin:0',
10354
- 'table input[type="number"]': 'width:4rem',
10355
- 'table tbody button':
10356
- 'font-size:0;background:#fff;border-radius:50%;margin:0 0.125rem 0 0;width:0.85rem;color:#111',
10357
- 'table button:first-letter': 'font-size:0.75rem',
10358
- thead: 'background:#222',
10359
- 'th:nth-of-type(1)': 'min-width:2rem;',
10360
- 'th.sorted': 'background:#000',
10361
- 'table caption': 'text-align:left;white-space:nowrap;line-height:1.25rem',
10362
- button: 'width:1.5rem;border:none;background:none;color:#fff;padding:0',
10363
- 'button[disabled]': 'color:#777',
10364
- 'button.next': 'margin-right:0.5rem',
10365
- [`th,#${UNIQUE_ID} td`]:
10366
- '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',
10367
- 'span.warn': 'margin:0.25rem;color:#d81b60',
11234
+ table: {
11235
+ [MIN_WIDTH]: '100%',
11236
+ 'border-collapse': 'collapse',
11237
+ 'table-layout': FIXED,
11238
+ },
11239
+ thead: {[BACKGROUND]: cssVar('bg')},
11240
+ [`th,#${UNIQUE_ID} td`]: {
11241
+ [OVERFLOW]: HIDDEN,
11242
+ [PADDING]: rem(0.25, 0.5),
11243
+ [MAX_WIDTH]: rem(20),
11244
+ [BORDER]: cssVar(BORDER),
11245
+ 'text-overflow': 'ellipsis',
11246
+ 'white-space': NOWRAP,
11247
+ 'border-width': px(1, 0, 0),
11248
+ [TEXT_ALIGN]: LEFT,
11249
+ },
11250
+ 'th:first-child': {
11251
+ [WIDTH]: rem(3),
11252
+ [MIN_WIDTH]: rem(3),
11253
+ [MAX_WIDTH]: rem(3),
11254
+ },
11255
+ 'th.sorted': {[BACKGROUND]: cssVar('bg3')},
11256
+ 'td.extra': {[TEXT_ALIGN]: RIGHT},
11257
+ 'tbody button': {
11258
+ [BACKGROUND]: NONE,
11259
+ [BORDER]: NONE,
11260
+ [FONT_SIZE]: 0,
11261
+ [WIDTH]: rem(0.8),
11262
+ [HEIGHT]: rem(0.8),
11263
+ [COLOR]: cssVar('fg2'),
11264
+ [MARGIN]: rem(0, 0.25, 0, -0.25),
11265
+ 'line-height': rem(0.8),
11266
+ },
11267
+ 'tbody button:first-letter': {[FONT_SIZE]: rem(0.8)},
11268
+ input: {
11269
+ [BACKGROUND]: cssVar('bg2'),
11270
+ [COLOR]: UNSET,
11271
+ [PADDING]: px(4),
11272
+ [BORDER]: 0,
11273
+ [MARGIN]: px(-4, 0),
11274
+ [FONT_SIZE]: UNSET,
11275
+ [MAX_WIDTH]: rem(6),
11276
+ },
11277
+ 'input:focus': {'outline-width': 0},
11278
+ 'input[type="number"]': {[WIDTH]: rem(3)},
11279
+ 'input[type="checkbox"]': {[VERTICAL_ALIGN]: px(-2)},
11280
+ '.editableCell': {[DISPLAY]: 'inline-block', [MARGIN_RIGHT]: px(2)},
11281
+ 'button.next': {[MARGIN_RIGHT]: rem(0.5)},
11282
+ 'img.edit': EDIT_SVG,
11283
+ 'img.done': DONE_SVG,
11284
+ 'img.add': ADD_SVG,
11285
+ 'img.clone': CLONE_SVG,
11286
+ 'img.delete': DELETE_SVG,
11287
+ 'img.ok': OK_SVG,
11288
+ 'img.okDis': OK_SVG_DISABLED,
11289
+ 'img.cancel': CANCEL_SVG,
11290
+ 'span.warn': {[MARGIN]: rem(2, 0.25), [COLOR]: '#d81b60'},
10368
11291
  },
10369
- (style, selector) => (style ? `#${UNIQUE_ID} ${selector}{${style}}` : ''),
11292
+ (style, selector) =>
11293
+ `#${UNIQUE_ID} ${selector}{${arrayJoin(
11294
+ objToArray(style, (value, property) => `${property}:${value};`),
11295
+ )}}`,
10370
11296
  ),
10371
11297
  );
10372
11298
 
10373
- const Inspector = ({position = 'right', open = false}) => {
11299
+ const Inspector = ({position = 'right', open = false, hue = 270}) => {
10374
11300
  const s = useCreateStore(createStore);
10375
11301
  const index = POSITIONS.indexOf(position);
10376
11302
  useCreatePersister(
@@ -10397,7 +11323,9 @@ const Inspector = ({position = 'right', open = false}) => {
10397
11323
  /* @__PURE__ */ jsx(Panel, {s}),
10398
11324
  ],
10399
11325
  }),
10400
- /* @__PURE__ */ jsx('style', {children: APP_STYLESHEET}),
11326
+ /* @__PURE__ */ jsxs('style', {
11327
+ children: [`#${UNIQUE_ID}{--hue:${hue}}`, APP_STYLESHEET],
11328
+ }),
10401
11329
  ],
10402
11330
  });
10403
11331
  };
@@ -10427,11 +11355,14 @@ export {
10427
11355
  createLocalSynchronizer,
10428
11356
  createMergeableStore,
10429
11357
  createMetrics,
11358
+ createOpfsPersister,
10430
11359
  createPartyKitPersister,
10431
11360
  createPglitePersister,
10432
11361
  createPostgresPersister,
10433
11362
  createPowerSyncPersister,
10434
11363
  createQueries,
11364
+ createReactNativeMmkvPersister,
11365
+ createReactNativeSqlitePersister,
10435
11366
  createRelationships,
10436
11367
  createRemotePersister,
10437
11368
  createSessionPersister,
@@ -10471,8 +11402,17 @@ export {
10471
11402
  Message,
10472
11403
  MetricView,
10473
11404
  objectStoreMatch,
11405
+ OFFSET_CHECKPOINTS,
11406
+ OFFSET_INDEXES,
11407
+ OFFSET_METRICS,
11408
+ OFFSET_PERSISTER,
11409
+ OFFSET_QUERIES,
11410
+ OFFSET_RELATIONSHIPS,
11411
+ OFFSET_STORE,
11412
+ OFFSET_SYNCHRONIZER,
10474
11413
  Persists,
10475
11414
  Provider,
11415
+ RelationshipInHtmlRow,
10476
11416
  RelationshipInHtmlTable,
10477
11417
  RemoteRowView,
10478
11418
  ResultCellView,
@@ -10489,7 +11429,7 @@ export {
10489
11429
  SortedTableView,
10490
11430
  Status,
10491
11431
  TableInHtmlTable,
10492
- TablesView,
11432
+ TablesView$1 as TablesView,
10493
11433
  TableView$1 as TableView,
10494
11434
  TinyBasePartyKitServer,
10495
11435
  useAddRowCallback,
@@ -10613,6 +11553,7 @@ export {
10613
11553
  useSortedRowIds,
10614
11554
  useSortedRowIdsListener,
10615
11555
  useSortedRowIdsListenerImpl,
11556
+ useSortingAndPagination,
10616
11557
  useStartTransactionListener,
10617
11558
  useStore,
10618
11559
  useStoreIds,