@ai-matrx/records 0.81.0 → 0.81.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/react/index.cjs +32 -3
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +32 -3
- package/dist/react/index.js.map +1 -1
- package/package.json +18 -3
package/dist/react/index.js
CHANGED
|
@@ -7890,6 +7890,31 @@ function useHoldKey() {
|
|
|
7890
7890
|
return useContext3(HoldContext);
|
|
7891
7891
|
}
|
|
7892
7892
|
|
|
7893
|
+
// src/react/pageOrder.ts
|
|
7894
|
+
function pageOrderOf(sort, narrowed) {
|
|
7895
|
+
return { sortFields: (sort ?? []).map((key) => key.field), narrowed };
|
|
7896
|
+
}
|
|
7897
|
+
var same = (a, b) => {
|
|
7898
|
+
if (a === b) return true;
|
|
7899
|
+
if ((a === null || a === void 0 || a === "") && (b === null || b === void 0 || b === "")) return true;
|
|
7900
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
7901
|
+
};
|
|
7902
|
+
function patchMovesRows(held, fresh, order) {
|
|
7903
|
+
if (order.sortFields.length === 0 && !order.narrowed) return false;
|
|
7904
|
+
for (const row of held) {
|
|
7905
|
+
const next = fresh.get(row.id);
|
|
7906
|
+
if (!next) continue;
|
|
7907
|
+
const was = row.document ?? {};
|
|
7908
|
+
const now = next.document ?? {};
|
|
7909
|
+
if (order.narrowed) {
|
|
7910
|
+
if (!same(was, now)) return true;
|
|
7911
|
+
continue;
|
|
7912
|
+
}
|
|
7913
|
+
for (const field2 of order.sortFields) if (!same(was[field2], now[field2])) return true;
|
|
7914
|
+
}
|
|
7915
|
+
return false;
|
|
7916
|
+
}
|
|
7917
|
+
|
|
7893
7918
|
// src/react/hooks.ts
|
|
7894
7919
|
function useAsync(run, key, live) {
|
|
7895
7920
|
const client = useRecordsClient();
|
|
@@ -8073,7 +8098,7 @@ function useReverseLinks(tableId, columns, recordIds, limit = 3, offset = 0) {
|
|
|
8073
8098
|
tableId ? `reverse-links:${tableId}:${columnsKey}:${limit}:${offset}:${idsKey}:${writes}` : "reverse-links:none"
|
|
8074
8099
|
);
|
|
8075
8100
|
}
|
|
8076
|
-
function liveRowsFor(tableId) {
|
|
8101
|
+
function liveRowsFor(tableId, order = { sortFields: [], narrowed: false }) {
|
|
8077
8102
|
return (entry) => {
|
|
8078
8103
|
const client = entry.client;
|
|
8079
8104
|
const realtime = client.config.realtime;
|
|
@@ -8092,6 +8117,10 @@ function liveRowsFor(tableId) {
|
|
|
8092
8117
|
entry.refetch();
|
|
8093
8118
|
return;
|
|
8094
8119
|
}
|
|
8120
|
+
if (patchMovesRows(held, fresh, order)) {
|
|
8121
|
+
entry.refetch();
|
|
8122
|
+
return;
|
|
8123
|
+
}
|
|
8095
8124
|
entry.setData(
|
|
8096
8125
|
(current) => current === null ? current : {
|
|
8097
8126
|
...current,
|
|
@@ -8199,7 +8228,7 @@ function useRecords(tableId, options = {}) {
|
|
|
8199
8228
|
// on every render must not re-read the page on every render, and a parent
|
|
8200
8229
|
// that changes the question must re-read on the first one.
|
|
8201
8230
|
`records:${tableId ?? "none"}:${pageSize}:${page2}:${filterKey}:s${shape}`,
|
|
8202
|
-
liveRowsFor(tableId)
|
|
8231
|
+
liveRowsFor(tableId, pageOrderOf(void 0, filterKey !== "{}"))
|
|
8203
8232
|
);
|
|
8204
8233
|
const { live, liveReason } = liveStatus(useRecordsClient(), tableId);
|
|
8205
8234
|
return { ...useSharedRows(useKeptPage(tableId, base)), live, liveReason };
|
|
@@ -8227,7 +8256,7 @@ function useRecordPage(tableId, options = {}) {
|
|
|
8227
8256
|
return answered.ok ? { ok: true, data: { rows: answered.data.rows, total: answered.data.total, sortIgnored: answered.data.sort_ignored ?? [] } } : answered;
|
|
8228
8257
|
},
|
|
8229
8258
|
`page:${tableId ?? "none"}:${pageSize}:${page2}:${filterKey}:${search ?? ""}:${sortKey}:${viewId ?? ""}:s${shape}`,
|
|
8230
|
-
liveRowsFor(tableId)
|
|
8259
|
+
liveRowsFor(tableId, pageOrderOf(options.sort, filterKey !== "{}" || search !== null))
|
|
8231
8260
|
);
|
|
8232
8261
|
const { live, liveReason } = liveStatus(useRecordsClient(), tableId);
|
|
8233
8262
|
return { ...useSharedRows(useKeptPage(tableId, base)), live, liveReason };
|