@timeax/form-palette 0.0.34 → 0.0.35
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/dist/extra.d.mts +1 -1
- package/dist/extra.d.ts +1 -1
- package/dist/extra.js +44 -24
- package/dist/extra.js.map +1 -1
- package/dist/extra.mjs +44 -24
- package/dist/extra.mjs.map +1 -1
- package/package.json +1 -1
package/dist/extra.mjs
CHANGED
|
@@ -26411,6 +26411,27 @@ function defaultSearchTarget(search) {
|
|
|
26411
26411
|
function isKey(x2) {
|
|
26412
26412
|
return typeof x2 === "string" || typeof x2 === "number";
|
|
26413
26413
|
}
|
|
26414
|
+
function stringifyForSearch(v2) {
|
|
26415
|
+
if (v2 == null) return "";
|
|
26416
|
+
if (typeof v2 === "string") return v2;
|
|
26417
|
+
if (typeof v2 === "number" || typeof v2 === "boolean" || typeof v2 === "bigint") {
|
|
26418
|
+
return String(v2);
|
|
26419
|
+
}
|
|
26420
|
+
if (v2 instanceof Date) {
|
|
26421
|
+
return Number.isNaN(v2.getTime()) ? "" : v2.toISOString();
|
|
26422
|
+
}
|
|
26423
|
+
if (Array.isArray(v2)) {
|
|
26424
|
+
return v2.map(stringifyForSearch).join(" ");
|
|
26425
|
+
}
|
|
26426
|
+
if (typeof v2 === "object") {
|
|
26427
|
+
try {
|
|
26428
|
+
return JSON.stringify(v2);
|
|
26429
|
+
} catch {
|
|
26430
|
+
return String(v2);
|
|
26431
|
+
}
|
|
26432
|
+
}
|
|
26433
|
+
return String(v2);
|
|
26434
|
+
}
|
|
26414
26435
|
function useData(opts) {
|
|
26415
26436
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
26416
26437
|
const ctx = React.useContext(Ctx);
|
|
@@ -26423,6 +26444,10 @@ function useData(opts) {
|
|
|
26423
26444
|
});
|
|
26424
26445
|
const [loading, setLoading] = React.useState(false);
|
|
26425
26446
|
const [error, setError] = React.useState(void 0);
|
|
26447
|
+
const dataRef = React.useRef(data);
|
|
26448
|
+
React.useEffect(() => {
|
|
26449
|
+
dataRef.current = data;
|
|
26450
|
+
}, [data]);
|
|
26426
26451
|
const [query, _setQuery] = React.useState("");
|
|
26427
26452
|
const [searchMode, _setSearchMode] = React.useState(
|
|
26428
26453
|
(_c = opts.searchMode) != null ? _c : "remote"
|
|
@@ -26460,6 +26485,11 @@ function useData(opts) {
|
|
|
26460
26485
|
const timerRef = React.useRef(null);
|
|
26461
26486
|
const didMountRef = React.useRef(false);
|
|
26462
26487
|
const skipNextModeEffectRef = React.useRef(false);
|
|
26488
|
+
React.useEffect(() => {
|
|
26489
|
+
return () => {
|
|
26490
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
26491
|
+
};
|
|
26492
|
+
}, []);
|
|
26463
26493
|
const inlineDef = React.useMemo(() => {
|
|
26464
26494
|
var _a2;
|
|
26465
26495
|
return makeInlineDef({
|
|
@@ -26505,7 +26535,7 @@ function useData(opts) {
|
|
|
26505
26535
|
const fetchImpl = React.useCallback(
|
|
26506
26536
|
async (override) => {
|
|
26507
26537
|
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
26508
|
-
if (!enabled) return
|
|
26538
|
+
if (!enabled) return dataRef.current;
|
|
26509
26539
|
const q2 = (_a2 = override == null ? void 0 : override.query) != null ? _a2 : query;
|
|
26510
26540
|
const f2 = (_b2 = override == null ? void 0 : override.filters) != null ? _b2 : filters;
|
|
26511
26541
|
const t4 = (_c2 = override == null ? void 0 : override.searchTarget) != null ? _c2 : searchTarget;
|
|
@@ -26519,6 +26549,7 @@ function useData(opts) {
|
|
|
26519
26549
|
search: payload
|
|
26520
26550
|
});
|
|
26521
26551
|
const list = (_f2 = (_e2 = res == null ? void 0 : res.rawList) != null ? _e2 : res == null ? void 0 : res.raw) != null ? _f2 : [];
|
|
26552
|
+
if (reqIdRef.current !== myReq) return list;
|
|
26522
26553
|
commitSelectedCache(list);
|
|
26523
26554
|
if (selectionMode !== "none" && selectionPrune === "missing") {
|
|
26524
26555
|
const nextIds = /* @__PURE__ */ new Set();
|
|
@@ -26530,29 +26561,27 @@ function useData(opts) {
|
|
|
26530
26561
|
(prev) => prev.filter((x2) => nextIds.has(x2))
|
|
26531
26562
|
);
|
|
26532
26563
|
}
|
|
26533
|
-
if (reqIdRef.current !== myReq) return list;
|
|
26534
26564
|
setData(list);
|
|
26535
26565
|
setLoading(false);
|
|
26536
26566
|
return list;
|
|
26537
26567
|
} catch (e4) {
|
|
26538
|
-
if (reqIdRef.current !== myReq) return
|
|
26568
|
+
if (reqIdRef.current !== myReq) return dataRef.current;
|
|
26539
26569
|
setError(e4);
|
|
26540
26570
|
setLoading(false);
|
|
26541
|
-
return
|
|
26571
|
+
return dataRef.current;
|
|
26542
26572
|
}
|
|
26543
26573
|
},
|
|
26544
26574
|
[
|
|
26545
|
-
commitSelectedCache,
|
|
26546
|
-
ctx,
|
|
26547
|
-
data,
|
|
26548
26575
|
enabled,
|
|
26549
|
-
filters,
|
|
26550
|
-
getItemKey,
|
|
26551
|
-
inlineDef,
|
|
26552
26576
|
query,
|
|
26577
|
+
filters,
|
|
26553
26578
|
searchTarget,
|
|
26579
|
+
ctx,
|
|
26580
|
+
inlineDef,
|
|
26581
|
+
commitSelectedCache,
|
|
26554
26582
|
selectionMode,
|
|
26555
|
-
selectionPrune
|
|
26583
|
+
selectionPrune,
|
|
26584
|
+
getItemKey
|
|
26556
26585
|
]
|
|
26557
26586
|
);
|
|
26558
26587
|
const refresh = React.useCallback(() => {
|
|
@@ -26578,18 +26607,9 @@ function useData(opts) {
|
|
|
26578
26607
|
},
|
|
26579
26608
|
[fetchImpl]
|
|
26580
26609
|
);
|
|
26581
|
-
const setSearchTarget = React.useCallback(
|
|
26582
|
-
(t4)
|
|
26583
|
-
|
|
26584
|
-
if (searchMode === "remote" || searchMode === "hybrid") {
|
|
26585
|
-
if (timerRef.current) clearTimeout(timerRef.current);
|
|
26586
|
-
timerRef.current = setTimeout(() => {
|
|
26587
|
-
void fetchImpl({ searchTarget: t4 });
|
|
26588
|
-
}, debounceMs);
|
|
26589
|
-
}
|
|
26590
|
-
},
|
|
26591
|
-
[debounceMs, fetchImpl, searchMode]
|
|
26592
|
-
);
|
|
26610
|
+
const setSearchTarget = React.useCallback((t4) => {
|
|
26611
|
+
_setSearchTarget(t4);
|
|
26612
|
+
}, []);
|
|
26593
26613
|
const setFilters = React.useCallback(
|
|
26594
26614
|
(next) => _setFilters(next),
|
|
26595
26615
|
[]
|
|
@@ -26657,7 +26677,7 @@ function useData(opts) {
|
|
|
26657
26677
|
);
|
|
26658
26678
|
}
|
|
26659
26679
|
return list.filter(
|
|
26660
|
-
(item) =>
|
|
26680
|
+
(item) => stringifyForSearch(item).toLowerCase().includes(ql)
|
|
26661
26681
|
);
|
|
26662
26682
|
}, [data, getItemKey, query, searchMode, searchTarget]);
|
|
26663
26683
|
const selectedIds = React.useMemo(() => {
|