@ai-matrx/records 0.81.0 → 0.81.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.
- package/CHANGELOG.md +16 -0
- package/dist/core/index.cjs +26 -1
- package/dist/core/index.cjs.map +1 -1
- package/dist/core/index.js +26 -1
- package/dist/core/index.js.map +1 -1
- package/dist/index.cjs +26 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +26 -1
- package/dist/index.js.map +1 -1
- package/dist/memory/index.cjs +13 -0
- package/dist/memory/index.cjs.map +1 -1
- package/dist/memory/index.d.cts +3 -1
- package/dist/memory/index.d.ts +3 -1
- package/dist/memory/index.js +13 -0
- package/dist/memory/index.js.map +1 -1
- package/dist/react/index.cjs +58 -4
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.js +58 -4
- package/dist/react/index.js.map +1 -1
- package/dist/templates/index.cjs +8 -0
- package/dist/templates/index.cjs.map +1 -1
- package/dist/templates/index.d.cts +3 -3
- package/dist/templates/index.d.ts +3 -3
- package/dist/templates/index.js +8 -0
- package/dist/templates/index.js.map +1 -1
- package/dist/{types-yBZLtxrZ.d.cts → types-B4nQMkQT.d.cts} +5 -0
- package/dist/{types-CU_Tn2Np.d.ts → types-BtXYdZGh.d.ts} +5 -0
- package/package.json +18 -3
package/dist/react/index.cjs
CHANGED
|
@@ -8175,6 +8175,31 @@ function useHoldKey() {
|
|
|
8175
8175
|
return (0, import_react3.useContext)(HoldContext);
|
|
8176
8176
|
}
|
|
8177
8177
|
|
|
8178
|
+
// src/react/pageOrder.ts
|
|
8179
|
+
function pageOrderOf(sort, narrowed) {
|
|
8180
|
+
return { sortFields: (sort ?? []).map((key) => key.field), narrowed };
|
|
8181
|
+
}
|
|
8182
|
+
var same = (a, b) => {
|
|
8183
|
+
if (a === b) return true;
|
|
8184
|
+
if ((a === null || a === void 0 || a === "") && (b === null || b === void 0 || b === "")) return true;
|
|
8185
|
+
return JSON.stringify(a) === JSON.stringify(b);
|
|
8186
|
+
};
|
|
8187
|
+
function patchMovesRows(held, fresh, order) {
|
|
8188
|
+
if (order.sortFields.length === 0 && !order.narrowed) return false;
|
|
8189
|
+
for (const row of held) {
|
|
8190
|
+
const next = fresh.get(row.id);
|
|
8191
|
+
if (!next) continue;
|
|
8192
|
+
const was = row.document ?? {};
|
|
8193
|
+
const now = next.document ?? {};
|
|
8194
|
+
if (order.narrowed) {
|
|
8195
|
+
if (!same(was, now)) return true;
|
|
8196
|
+
continue;
|
|
8197
|
+
}
|
|
8198
|
+
for (const field2 of order.sortFields) if (!same(was[field2], now[field2])) return true;
|
|
8199
|
+
}
|
|
8200
|
+
return false;
|
|
8201
|
+
}
|
|
8202
|
+
|
|
8178
8203
|
// src/react/hooks.ts
|
|
8179
8204
|
function useAsync(run, key, live) {
|
|
8180
8205
|
const client = useRecordsClient();
|
|
@@ -8358,7 +8383,7 @@ function useReverseLinks(tableId, columns, recordIds, limit = 3, offset = 0) {
|
|
|
8358
8383
|
tableId ? `reverse-links:${tableId}:${columnsKey}:${limit}:${offset}:${idsKey}:${writes}` : "reverse-links:none"
|
|
8359
8384
|
);
|
|
8360
8385
|
}
|
|
8361
|
-
function liveRowsFor(tableId) {
|
|
8386
|
+
function liveRowsFor(tableId, order = { sortFields: [], narrowed: false }) {
|
|
8362
8387
|
return (entry) => {
|
|
8363
8388
|
const client = entry.client;
|
|
8364
8389
|
const realtime = client.config.realtime;
|
|
@@ -8377,6 +8402,10 @@ function liveRowsFor(tableId) {
|
|
|
8377
8402
|
entry.refetch();
|
|
8378
8403
|
return;
|
|
8379
8404
|
}
|
|
8405
|
+
if (patchMovesRows(held, fresh, order)) {
|
|
8406
|
+
entry.refetch();
|
|
8407
|
+
return;
|
|
8408
|
+
}
|
|
8380
8409
|
entry.setData(
|
|
8381
8410
|
(current) => current === null ? current : {
|
|
8382
8411
|
...current,
|
|
@@ -8484,7 +8513,7 @@ function useRecords(tableId, options = {}) {
|
|
|
8484
8513
|
// on every render must not re-read the page on every render, and a parent
|
|
8485
8514
|
// that changes the question must re-read on the first one.
|
|
8486
8515
|
`records:${tableId ?? "none"}:${pageSize}:${page2}:${filterKey}:s${shape}`,
|
|
8487
|
-
liveRowsFor(tableId)
|
|
8516
|
+
liveRowsFor(tableId, pageOrderOf(void 0, filterKey !== "{}"))
|
|
8488
8517
|
);
|
|
8489
8518
|
const { live, liveReason } = liveStatus(useRecordsClient(), tableId);
|
|
8490
8519
|
return { ...useSharedRows(useKeptPage(tableId, base)), live, liveReason };
|
|
@@ -8512,7 +8541,7 @@ function useRecordPage(tableId, options = {}) {
|
|
|
8512
8541
|
return answered.ok ? { ok: true, data: { rows: answered.data.rows, total: answered.data.total, sortIgnored: answered.data.sort_ignored ?? [] } } : answered;
|
|
8513
8542
|
},
|
|
8514
8543
|
`page:${tableId ?? "none"}:${pageSize}:${page2}:${filterKey}:${search ?? ""}:${sortKey}:${viewId ?? ""}:s${shape}`,
|
|
8515
|
-
liveRowsFor(tableId)
|
|
8544
|
+
liveRowsFor(tableId, pageOrderOf(options.sort, filterKey !== "{}" || search !== null))
|
|
8516
8545
|
);
|
|
8517
8546
|
const { live, liveReason } = liveStatus(useRecordsClient(), tableId);
|
|
8518
8547
|
return { ...useSharedRows(useKeptPage(tableId, base)), live, liveReason };
|
|
@@ -9713,7 +9742,32 @@ function readTypedDate(raw, opts = {}) {
|
|
|
9713
9742
|
let month = null;
|
|
9714
9743
|
let day = null;
|
|
9715
9744
|
const numeric = /^(\d{1,4})[/.\-](\d{1,2})[/.\-](\d{1,4})$/.exec(dateText);
|
|
9716
|
-
|
|
9745
|
+
const compact = /^(\d{8}|\d{6})$/.exec(dateText);
|
|
9746
|
+
if (compact) {
|
|
9747
|
+
const digits = compact[1];
|
|
9748
|
+
const order = localeDateOrder(opts.locale);
|
|
9749
|
+
const first2 = Number(digits.slice(0, 2));
|
|
9750
|
+
const mid2 = Number(digits.slice(2, 4));
|
|
9751
|
+
if (digits.length === 6) {
|
|
9752
|
+
year = twoDigitYear(Number(digits.slice(4)));
|
|
9753
|
+
if (order === "dmy") {
|
|
9754
|
+
day = first2;
|
|
9755
|
+
month = mid2;
|
|
9756
|
+
} else {
|
|
9757
|
+
month = first2;
|
|
9758
|
+
day = mid2;
|
|
9759
|
+
}
|
|
9760
|
+
} else {
|
|
9761
|
+
const yearLast = Number(digits.slice(4));
|
|
9762
|
+
const yearFirst = Number(digits.slice(0, 4));
|
|
9763
|
+
const localeReading = () => order === "dmy" ? [yearLast, mid2, first2] : [yearLast, first2, mid2];
|
|
9764
|
+
const [ly, lm, ld] = localeReading();
|
|
9765
|
+
const isoReading = [yearFirst, Number(digits.slice(4, 6)), Number(digits.slice(6))];
|
|
9766
|
+
const fits = (y, m, d) => checkDay(y, m, d, raw) === null;
|
|
9767
|
+
const useIso = order === "ymd" || !fits(ly, lm, ld) && fits(...isoReading);
|
|
9768
|
+
[year, month, day] = useIso ? isoReading : [ly, lm, ld];
|
|
9769
|
+
}
|
|
9770
|
+
} else if (numeric) {
|
|
9717
9771
|
const [a, b, c] = [numeric[1], numeric[2], numeric[3]];
|
|
9718
9772
|
if (a.length === 4) {
|
|
9719
9773
|
year = Number(a);
|