@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.d.mts
CHANGED
|
@@ -201,7 +201,7 @@ declare function useLister<P extends PresetMap>(): {
|
|
|
201
201
|
* - function: (body) => array
|
|
202
202
|
* - string: path selector
|
|
203
203
|
*/
|
|
204
|
-
type DataSelector<T> = any;
|
|
204
|
+
type DataSelector<T> = ((body: any) => T[]) | string;
|
|
205
205
|
type DataSearchConfig = {
|
|
206
206
|
default?: string;
|
|
207
207
|
};
|
package/dist/extra.d.ts
CHANGED
|
@@ -201,7 +201,7 @@ declare function useLister<P extends PresetMap>(): {
|
|
|
201
201
|
* - function: (body) => array
|
|
202
202
|
* - string: path selector
|
|
203
203
|
*/
|
|
204
|
-
type DataSelector<T> = any;
|
|
204
|
+
type DataSelector<T> = ((body: any) => T[]) | string;
|
|
205
205
|
type DataSearchConfig = {
|
|
206
206
|
default?: string;
|
|
207
207
|
};
|
package/dist/extra.js
CHANGED
|
@@ -26448,6 +26448,27 @@ function defaultSearchTarget(search) {
|
|
|
26448
26448
|
function isKey(x2) {
|
|
26449
26449
|
return typeof x2 === "string" || typeof x2 === "number";
|
|
26450
26450
|
}
|
|
26451
|
+
function stringifyForSearch(v2) {
|
|
26452
|
+
if (v2 == null) return "";
|
|
26453
|
+
if (typeof v2 === "string") return v2;
|
|
26454
|
+
if (typeof v2 === "number" || typeof v2 === "boolean" || typeof v2 === "bigint") {
|
|
26455
|
+
return String(v2);
|
|
26456
|
+
}
|
|
26457
|
+
if (v2 instanceof Date) {
|
|
26458
|
+
return Number.isNaN(v2.getTime()) ? "" : v2.toISOString();
|
|
26459
|
+
}
|
|
26460
|
+
if (Array.isArray(v2)) {
|
|
26461
|
+
return v2.map(stringifyForSearch).join(" ");
|
|
26462
|
+
}
|
|
26463
|
+
if (typeof v2 === "object") {
|
|
26464
|
+
try {
|
|
26465
|
+
return JSON.stringify(v2);
|
|
26466
|
+
} catch {
|
|
26467
|
+
return String(v2);
|
|
26468
|
+
}
|
|
26469
|
+
}
|
|
26470
|
+
return String(v2);
|
|
26471
|
+
}
|
|
26451
26472
|
function useData(opts) {
|
|
26452
26473
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
26453
26474
|
const ctx = React__namespace.useContext(Ctx);
|
|
@@ -26460,6 +26481,10 @@ function useData(opts) {
|
|
|
26460
26481
|
});
|
|
26461
26482
|
const [loading, setLoading] = React__namespace.useState(false);
|
|
26462
26483
|
const [error, setError] = React__namespace.useState(void 0);
|
|
26484
|
+
const dataRef = React__namespace.useRef(data);
|
|
26485
|
+
React__namespace.useEffect(() => {
|
|
26486
|
+
dataRef.current = data;
|
|
26487
|
+
}, [data]);
|
|
26463
26488
|
const [query, _setQuery] = React__namespace.useState("");
|
|
26464
26489
|
const [searchMode, _setSearchMode] = React__namespace.useState(
|
|
26465
26490
|
(_c = opts.searchMode) != null ? _c : "remote"
|
|
@@ -26497,6 +26522,11 @@ function useData(opts) {
|
|
|
26497
26522
|
const timerRef = React__namespace.useRef(null);
|
|
26498
26523
|
const didMountRef = React__namespace.useRef(false);
|
|
26499
26524
|
const skipNextModeEffectRef = React__namespace.useRef(false);
|
|
26525
|
+
React__namespace.useEffect(() => {
|
|
26526
|
+
return () => {
|
|
26527
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
26528
|
+
};
|
|
26529
|
+
}, []);
|
|
26500
26530
|
const inlineDef = React__namespace.useMemo(() => {
|
|
26501
26531
|
var _a2;
|
|
26502
26532
|
return makeInlineDef({
|
|
@@ -26542,7 +26572,7 @@ function useData(opts) {
|
|
|
26542
26572
|
const fetchImpl = React__namespace.useCallback(
|
|
26543
26573
|
async (override) => {
|
|
26544
26574
|
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
26545
|
-
if (!enabled) return
|
|
26575
|
+
if (!enabled) return dataRef.current;
|
|
26546
26576
|
const q2 = (_a2 = override == null ? void 0 : override.query) != null ? _a2 : query;
|
|
26547
26577
|
const f2 = (_b2 = override == null ? void 0 : override.filters) != null ? _b2 : filters;
|
|
26548
26578
|
const t4 = (_c2 = override == null ? void 0 : override.searchTarget) != null ? _c2 : searchTarget;
|
|
@@ -26556,6 +26586,7 @@ function useData(opts) {
|
|
|
26556
26586
|
search: payload
|
|
26557
26587
|
});
|
|
26558
26588
|
const list = (_f2 = (_e2 = res == null ? void 0 : res.rawList) != null ? _e2 : res == null ? void 0 : res.raw) != null ? _f2 : [];
|
|
26589
|
+
if (reqIdRef.current !== myReq) return list;
|
|
26559
26590
|
commitSelectedCache(list);
|
|
26560
26591
|
if (selectionMode !== "none" && selectionPrune === "missing") {
|
|
26561
26592
|
const nextIds = /* @__PURE__ */ new Set();
|
|
@@ -26567,29 +26598,27 @@ function useData(opts) {
|
|
|
26567
26598
|
(prev) => prev.filter((x2) => nextIds.has(x2))
|
|
26568
26599
|
);
|
|
26569
26600
|
}
|
|
26570
|
-
if (reqIdRef.current !== myReq) return list;
|
|
26571
26601
|
setData(list);
|
|
26572
26602
|
setLoading(false);
|
|
26573
26603
|
return list;
|
|
26574
26604
|
} catch (e4) {
|
|
26575
|
-
if (reqIdRef.current !== myReq) return
|
|
26605
|
+
if (reqIdRef.current !== myReq) return dataRef.current;
|
|
26576
26606
|
setError(e4);
|
|
26577
26607
|
setLoading(false);
|
|
26578
|
-
return
|
|
26608
|
+
return dataRef.current;
|
|
26579
26609
|
}
|
|
26580
26610
|
},
|
|
26581
26611
|
[
|
|
26582
|
-
commitSelectedCache,
|
|
26583
|
-
ctx,
|
|
26584
|
-
data,
|
|
26585
26612
|
enabled,
|
|
26586
|
-
filters,
|
|
26587
|
-
getItemKey,
|
|
26588
|
-
inlineDef,
|
|
26589
26613
|
query,
|
|
26614
|
+
filters,
|
|
26590
26615
|
searchTarget,
|
|
26616
|
+
ctx,
|
|
26617
|
+
inlineDef,
|
|
26618
|
+
commitSelectedCache,
|
|
26591
26619
|
selectionMode,
|
|
26592
|
-
selectionPrune
|
|
26620
|
+
selectionPrune,
|
|
26621
|
+
getItemKey
|
|
26593
26622
|
]
|
|
26594
26623
|
);
|
|
26595
26624
|
const refresh = React__namespace.useCallback(() => {
|
|
@@ -26615,18 +26644,9 @@ function useData(opts) {
|
|
|
26615
26644
|
},
|
|
26616
26645
|
[fetchImpl]
|
|
26617
26646
|
);
|
|
26618
|
-
const setSearchTarget = React__namespace.useCallback(
|
|
26619
|
-
(t4)
|
|
26620
|
-
|
|
26621
|
-
if (searchMode === "remote" || searchMode === "hybrid") {
|
|
26622
|
-
if (timerRef.current) clearTimeout(timerRef.current);
|
|
26623
|
-
timerRef.current = setTimeout(() => {
|
|
26624
|
-
void fetchImpl({ searchTarget: t4 });
|
|
26625
|
-
}, debounceMs);
|
|
26626
|
-
}
|
|
26627
|
-
},
|
|
26628
|
-
[debounceMs, fetchImpl, searchMode]
|
|
26629
|
-
);
|
|
26647
|
+
const setSearchTarget = React__namespace.useCallback((t4) => {
|
|
26648
|
+
_setSearchTarget(t4);
|
|
26649
|
+
}, []);
|
|
26630
26650
|
const setFilters = React__namespace.useCallback(
|
|
26631
26651
|
(next) => _setFilters(next),
|
|
26632
26652
|
[]
|
|
@@ -26694,7 +26714,7 @@ function useData(opts) {
|
|
|
26694
26714
|
);
|
|
26695
26715
|
}
|
|
26696
26716
|
return list.filter(
|
|
26697
|
-
(item) =>
|
|
26717
|
+
(item) => stringifyForSearch(item).toLowerCase().includes(ql)
|
|
26698
26718
|
);
|
|
26699
26719
|
}, [data, getItemKey, query, searchMode, searchTarget]);
|
|
26700
26720
|
const selectedIds = React__namespace.useMemo(() => {
|