@timeax/form-palette 0.0.30 → 0.0.31
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/Readme.md +651 -0
- package/dist/extra.d.mts +213 -40
- package/dist/extra.d.ts +213 -40
- package/dist/extra.js +624 -85
- package/dist/extra.js.map +1 -1
- package/dist/extra.mjs +622 -86
- package/dist/extra.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +241 -84
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +241 -84
- package/dist/index.mjs.map +1 -1
- package/dist/{variant-v0LBdshU.d.ts → variant-BhsBO5Yr.d.ts} +1 -1
- package/dist/{variant-BPDyK780.d.mts → variant-jHi2M5Ru.d.mts} +1 -1
- package/package.json +1 -1
package/dist/extra.mjs
CHANGED
|
@@ -216,19 +216,139 @@ function mapOptions(rawList, mapping, ctx) {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
// src/presets/lister/engine/search.ts
|
|
219
|
-
function
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
219
|
+
function getPath2(obj, path) {
|
|
220
|
+
if (!obj || !path) return void 0;
|
|
221
|
+
if (!path.includes(".")) return obj[path];
|
|
222
|
+
let cur = obj;
|
|
223
|
+
for (const part of path.split(".")) {
|
|
224
|
+
if (cur == null) return void 0;
|
|
225
|
+
cur = cur[part];
|
|
226
|
+
}
|
|
227
|
+
return cur;
|
|
228
|
+
}
|
|
229
|
+
function toText(v2) {
|
|
230
|
+
if (v2 == null) return "";
|
|
231
|
+
if (typeof v2 === "string") return v2;
|
|
232
|
+
if (typeof v2 === "number" || typeof v2 === "boolean") return String(v2);
|
|
233
|
+
return "";
|
|
234
|
+
}
|
|
235
|
+
function collectAllText(obj, out, depth = 2, budget = { n: 80 }) {
|
|
236
|
+
if (obj == null || budget.n <= 0) return;
|
|
237
|
+
const t4 = typeof obj;
|
|
238
|
+
if (t4 === "string" || t4 === "number" || t4 === "boolean") {
|
|
239
|
+
out.push(String(obj));
|
|
240
|
+
budget.n -= 1;
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (depth <= 0) return;
|
|
244
|
+
if (Array.isArray(obj)) {
|
|
245
|
+
for (const x2 of obj) collectAllText(x2, out, depth - 1, budget);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
if (t4 === "object") {
|
|
249
|
+
for (const k2 of Object.keys(obj)) {
|
|
250
|
+
collectAllText(obj[k2], out, depth - 1, budget);
|
|
251
|
+
if (budget.n <= 0) break;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
function matchQueryInText(q2, text) {
|
|
256
|
+
if (!q2) return true;
|
|
257
|
+
return text.toLowerCase().includes(q2);
|
|
258
|
+
}
|
|
259
|
+
function buildSearchTextForKeys(raw, keys) {
|
|
260
|
+
const parts = [];
|
|
261
|
+
for (const k2 of keys) {
|
|
262
|
+
const key = String(k2);
|
|
263
|
+
const v2 = getPath2(raw, key);
|
|
264
|
+
if (v2 == null) continue;
|
|
265
|
+
if (Array.isArray(v2)) {
|
|
266
|
+
for (const x2 of v2) {
|
|
267
|
+
const s4 = toText(x2);
|
|
268
|
+
if (s4) parts.push(s4);
|
|
269
|
+
}
|
|
270
|
+
continue;
|
|
271
|
+
}
|
|
272
|
+
const s3 = toText(v2);
|
|
273
|
+
if (s3) parts.push(s3);
|
|
274
|
+
}
|
|
275
|
+
return parts.join(" ");
|
|
276
|
+
}
|
|
277
|
+
function matchesSearch(raw, q2, search) {
|
|
278
|
+
if (!q2) return true;
|
|
279
|
+
if (search == null ? void 0 : search.searchAll) {
|
|
280
|
+
return matchQueryInText(q2, buildSearchTextAll(raw));
|
|
281
|
+
}
|
|
282
|
+
if (Array.isArray(search == null ? void 0 : search.searchOnly) && search.searchOnly.length) {
|
|
283
|
+
return matchQueryInText(
|
|
284
|
+
q2,
|
|
285
|
+
buildSearchTextForKeys(raw, search.searchOnly)
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
if (typeof (search == null ? void 0 : search.subject) === "string" && search.subject) {
|
|
289
|
+
return matchQueryInText(
|
|
290
|
+
q2,
|
|
291
|
+
buildSearchTextForKeys(raw, [search.subject])
|
|
292
|
+
);
|
|
293
|
+
}
|
|
294
|
+
return matchQueryInText(q2, buildSearchTextAll(raw));
|
|
295
|
+
}
|
|
296
|
+
function buildSearchTextAll(raw) {
|
|
297
|
+
const parts = [];
|
|
298
|
+
collectAllText(raw, parts, 2);
|
|
299
|
+
return parts.join(" ");
|
|
300
|
+
}
|
|
301
|
+
function isEmptyFilterValue(v2) {
|
|
302
|
+
if (v2 === void 0 || v2 === null) return true;
|
|
303
|
+
if (typeof v2 === "string" && v2.trim() === "") return true;
|
|
304
|
+
return Array.isArray(v2) && v2.length === 0;
|
|
305
|
+
}
|
|
306
|
+
function matchesFilters(raw, filters) {
|
|
307
|
+
if (!filters) return true;
|
|
308
|
+
for (const key of Object.keys(filters)) {
|
|
309
|
+
if (key === "search" || key === "subject" || key === "searchAll" || key === "searchOnly") {
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
const fv = filters[key];
|
|
313
|
+
if (isEmptyFilterValue(fv)) continue;
|
|
314
|
+
const rv = getPath2(raw, key);
|
|
315
|
+
if (Array.isArray(fv)) {
|
|
316
|
+
if (Array.isArray(rv)) {
|
|
317
|
+
const ok = rv.some((x2) => fv.includes(x2));
|
|
318
|
+
if (!ok) return false;
|
|
319
|
+
} else {
|
|
320
|
+
if (!fv.includes(rv)) return false;
|
|
321
|
+
}
|
|
322
|
+
continue;
|
|
323
|
+
}
|
|
324
|
+
if (Array.isArray(rv)) {
|
|
325
|
+
if (!rv.includes(fv)) return false;
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
if (String(rv) !== String(fv)) return false;
|
|
329
|
+
}
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
function filterRawListLocal(rawList, query, search, filters, opts) {
|
|
333
|
+
let list = Array.isArray(rawList) ? rawList : [];
|
|
334
|
+
const ctx = { query, search, filters };
|
|
335
|
+
const filtersLocal = (opts == null ? void 0 : opts.filtersSpec) && opts.filtersSpec.local;
|
|
336
|
+
if (typeof filtersLocal === "function") {
|
|
337
|
+
const out = filtersLocal(list, ctx);
|
|
338
|
+
if (Array.isArray(out)) list = out;
|
|
339
|
+
} else {
|
|
340
|
+
list = list.filter(
|
|
341
|
+
(r5) => matchesFilters(r5, filters)
|
|
342
|
+
);
|
|
343
|
+
}
|
|
229
344
|
const q2 = (query != null ? query : "").trim().toLowerCase();
|
|
230
|
-
if (!q2) return
|
|
231
|
-
|
|
345
|
+
if (!q2) return list;
|
|
346
|
+
const searchLocal = (opts == null ? void 0 : opts.searchSpec) && opts.searchSpec.local;
|
|
347
|
+
if (typeof searchLocal === "function") {
|
|
348
|
+
const out = searchLocal(list, ctx);
|
|
349
|
+
if (Array.isArray(out)) return out;
|
|
350
|
+
}
|
|
351
|
+
return list.filter((r5) => matchesSearch(r5, q2, search));
|
|
232
352
|
}
|
|
233
353
|
|
|
234
354
|
// src/presets/lister/engine/selection.ts
|
|
@@ -390,7 +510,8 @@ function initialSessionState(sessionId) {
|
|
|
390
510
|
filtersPatch: {},
|
|
391
511
|
effectiveFilters: void 0,
|
|
392
512
|
// IMPORTANT: these are now OPTION IDS (not db values)
|
|
393
|
-
selectedFilterValues: []
|
|
513
|
+
selectedFilterValues: [],
|
|
514
|
+
searchPayload: void 0
|
|
394
515
|
};
|
|
395
516
|
}
|
|
396
517
|
function buildSearchPayloadFromTarget(target) {
|
|
@@ -402,7 +523,7 @@ function buildSearchPayloadFromTarget(target) {
|
|
|
402
523
|
return subject ? { subject } : void 0;
|
|
403
524
|
}
|
|
404
525
|
if (target.mode === "only") {
|
|
405
|
-
const only = Array.isArray(target.only) ? target.only.filter(
|
|
526
|
+
const only = Array.isArray(target.only) ? target.only.filter((v2) => v2 !== null && v2 !== void 0) : void 0;
|
|
406
527
|
return only && only.length ? { searchOnly: only } : void 0;
|
|
407
528
|
}
|
|
408
529
|
return void 0;
|
|
@@ -659,16 +780,15 @@ function ListerProvider(props) {
|
|
|
659
780
|
);
|
|
660
781
|
const fetchAndHydrate = React.useCallback(
|
|
661
782
|
async (id, reason, override) => {
|
|
662
|
-
var _a2, _b2, _c2, _d, _e, _f, _g
|
|
783
|
+
var _a2, _b2, _c2, _d, _e, _f, _g;
|
|
663
784
|
const s0 = getSession(id);
|
|
664
785
|
if (!(s0 == null ? void 0 : s0.definition)) return;
|
|
665
786
|
const myReq = ((_a2 = reqIdBySessionRef.current[id]) != null ? _a2 : 0) + 1;
|
|
666
787
|
reqIdBySessionRef.current[id] = myReq;
|
|
667
788
|
const query = (_b2 = override == null ? void 0 : override.query) != null ? _b2 : s0.query;
|
|
668
789
|
const filters = (_d = (_c2 = override == null ? void 0 : override.filters) != null ? _c2 : s0.effectiveFilters) != null ? _d : s0.filters;
|
|
669
|
-
const
|
|
670
|
-
|
|
671
|
-
);
|
|
790
|
+
const hasSearchOverride = !!override && Object.prototype.hasOwnProperty.call(override, "search");
|
|
791
|
+
const search = hasSearchOverride ? override.search : (_e = s0.searchPayload) != null ? _e : buildSearchPayloadFromTarget(s0.searchTarget);
|
|
672
792
|
patchSession(id, {
|
|
673
793
|
errorCode: void 0,
|
|
674
794
|
loading: reason !== "refresh",
|
|
@@ -701,7 +821,7 @@ function ListerProvider(props) {
|
|
|
701
821
|
details: {
|
|
702
822
|
sessionId: id,
|
|
703
823
|
kind: s3 == null ? void 0 : s3.kind,
|
|
704
|
-
endpoint: (
|
|
824
|
+
endpoint: (_g = (_f = s3 == null ? void 0 : s3.definition) == null ? void 0 : _f.source) == null ? void 0 : _g.endpoint,
|
|
705
825
|
query,
|
|
706
826
|
filters,
|
|
707
827
|
search
|
|
@@ -755,7 +875,7 @@ function ListerProvider(props) {
|
|
|
755
875
|
nextPatch,
|
|
756
876
|
spec
|
|
757
877
|
);
|
|
758
|
-
shouldFetch = (spec == null ? void 0 : spec.autoFetch) !== false;
|
|
878
|
+
shouldFetch = (spec == null ? void 0 : spec.autoFetch) !== false && s4.searchMode !== "local";
|
|
759
879
|
return {
|
|
760
880
|
...s4,
|
|
761
881
|
filtersPatch: nextPatch,
|
|
@@ -844,7 +964,7 @@ function ListerProvider(props) {
|
|
|
844
964
|
);
|
|
845
965
|
const apiOpenAny = React.useCallback(
|
|
846
966
|
async (kindOrDef, filters, opts) => {
|
|
847
|
-
var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i;
|
|
967
|
+
var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
848
968
|
const mode = (_a2 = opts == null ? void 0 : opts.mode) != null ? _a2 : "single";
|
|
849
969
|
try {
|
|
850
970
|
const def = typeof kindOrDef === "string" ? getPreset(kindOrDef) : kindOrDef;
|
|
@@ -867,7 +987,8 @@ function ListerProvider(props) {
|
|
|
867
987
|
const pos = anchorToPos(opts == null ? void 0 : opts.anchor);
|
|
868
988
|
const filtersSpec = (_d = opts == null ? void 0 : opts.filtersSpec) != null ? _d : prev == null ? void 0 : prev.filtersSpec;
|
|
869
989
|
const filtersPatch = (_e = prev == null ? void 0 : prev.filtersPatch) != null ? _e : {};
|
|
870
|
-
const
|
|
990
|
+
const resolvedSearchMode = (_g = (_f = opts == null ? void 0 : opts.searchMode) != null ? _f : prev == null ? void 0 : prev.searchMode) != null ? _g : "remote";
|
|
991
|
+
const selectedFilterValues = (_h = prev == null ? void 0 : prev.selectedFilterValues) != null ? _h : [];
|
|
871
992
|
const effectiveFilters = computeEffectiveFilters(
|
|
872
993
|
filters,
|
|
873
994
|
filtersPatch,
|
|
@@ -875,10 +996,10 @@ function ListerProvider(props) {
|
|
|
875
996
|
);
|
|
876
997
|
const searchSpec = def == null ? void 0 : def.search;
|
|
877
998
|
const defaultCol = searchSpec == null ? void 0 : searchSpec.default;
|
|
878
|
-
const
|
|
879
|
-
const searchTarget = (
|
|
880
|
-
const initialQuery = (
|
|
881
|
-
const searchPayload = buildSearchPayloadFromTarget(searchTarget);
|
|
999
|
+
const defaultSearchTarget2 = defaultCol ? { mode: "subject", subject: defaultCol, only: null } : void 0;
|
|
1000
|
+
const searchTarget = (_i = prev == null ? void 0 : prev.searchTarget) != null ? _i : defaultSearchTarget2;
|
|
1001
|
+
const initialQuery = (_k = (_j = opts == null ? void 0 : opts.initialQuery) != null ? _j : prev == null ? void 0 : prev.query) != null ? _k : "";
|
|
1002
|
+
const searchPayload = (_l = prev == null ? void 0 : prev.searchPayload) != null ? _l : buildSearchPayloadFromTarget(searchTarget);
|
|
882
1003
|
const { rawList, optionsList } = await performFetch(
|
|
883
1004
|
def,
|
|
884
1005
|
effectiveFilters,
|
|
@@ -886,7 +1007,7 @@ function ListerProvider(props) {
|
|
|
886
1007
|
);
|
|
887
1008
|
return await new Promise(
|
|
888
1009
|
(resolve) => {
|
|
889
|
-
var _a3, _b3, _c3
|
|
1010
|
+
var _a3, _b3, _c3;
|
|
890
1011
|
const base = initialSessionState(sessionId);
|
|
891
1012
|
const nextSession = {
|
|
892
1013
|
...prev ? { ...prev } : base,
|
|
@@ -902,12 +1023,12 @@ function ListerProvider(props) {
|
|
|
902
1023
|
draggable: (_a3 = opts == null ? void 0 : opts.draggable) != null ? _a3 : true,
|
|
903
1024
|
position: pos,
|
|
904
1025
|
hasMoved: false,
|
|
905
|
-
searchMode:
|
|
1026
|
+
searchMode: resolvedSearchMode,
|
|
906
1027
|
query: initialQuery,
|
|
907
1028
|
searchSpec,
|
|
908
1029
|
searchTarget,
|
|
909
|
-
showRefresh: (
|
|
910
|
-
refreshMode: (
|
|
1030
|
+
showRefresh: (_b3 = opts == null ? void 0 : opts.showRefresh) != null ? _b3 : false,
|
|
1031
|
+
refreshMode: (_c3 = opts == null ? void 0 : opts.refreshMode) != null ? _c3 : "preserve-selection",
|
|
911
1032
|
// filters
|
|
912
1033
|
filtersSpec,
|
|
913
1034
|
filtersPatch,
|
|
@@ -1125,17 +1246,32 @@ function ListerProvider(props) {
|
|
|
1125
1246
|
);
|
|
1126
1247
|
const setSearchMode = React.useCallback(
|
|
1127
1248
|
(id, mode) => {
|
|
1249
|
+
var _a2;
|
|
1250
|
+
const s3 = getSession(id);
|
|
1251
|
+
if (!s3) return;
|
|
1252
|
+
const prevMode = s3.searchMode;
|
|
1128
1253
|
patchSession(id, { searchMode: mode });
|
|
1254
|
+
if (prevMode === mode) return;
|
|
1255
|
+
if (mode === "local") {
|
|
1256
|
+
fetchAndHydrate(id, "refresh", {
|
|
1257
|
+
filters: (_a2 = s3.effectiveFilters) != null ? _a2 : s3.filters,
|
|
1258
|
+
query: "",
|
|
1259
|
+
// base fetch (unsearched)
|
|
1260
|
+
search: void 0
|
|
1261
|
+
// force NO search payload
|
|
1262
|
+
});
|
|
1263
|
+
}
|
|
1129
1264
|
},
|
|
1130
|
-
[patchSession]
|
|
1265
|
+
[fetchAndHydrate, getSession, patchSession]
|
|
1131
1266
|
);
|
|
1132
1267
|
const scheduleRemoteFetch = React.useCallback(
|
|
1133
1268
|
(id, q2, payloadOverride) => {
|
|
1134
1269
|
if (timerBySessionRef.current[id])
|
|
1135
1270
|
clearTimeout(timerBySessionRef.current[id]);
|
|
1136
1271
|
timerBySessionRef.current[id] = setTimeout(() => {
|
|
1272
|
+
var _a2;
|
|
1137
1273
|
const s3 = getSession(id);
|
|
1138
|
-
const search = payloadOverride != null ? payloadOverride : buildSearchPayloadFromTarget(s3 == null ? void 0 : s3.searchTarget);
|
|
1274
|
+
const search = (_a2 = payloadOverride != null ? payloadOverride : s3 == null ? void 0 : s3.searchPayload) != null ? _a2 : buildSearchPayloadFromTarget(s3 == null ? void 0 : s3.searchTarget);
|
|
1139
1275
|
fetchAndHydrate(id, "search", { query: q2, search });
|
|
1140
1276
|
}, debounceMs);
|
|
1141
1277
|
},
|
|
@@ -1144,7 +1280,10 @@ function ListerProvider(props) {
|
|
|
1144
1280
|
const setSearchTarget = React.useCallback(
|
|
1145
1281
|
(id, target) => {
|
|
1146
1282
|
var _a2, _b2;
|
|
1147
|
-
patchSession(id, {
|
|
1283
|
+
patchSession(id, {
|
|
1284
|
+
searchTarget: target,
|
|
1285
|
+
searchPayload: void 0
|
|
1286
|
+
});
|
|
1148
1287
|
const s3 = getSession(id);
|
|
1149
1288
|
const mode = (_a2 = s3 == null ? void 0 : s3.searchMode) != null ? _a2 : "remote";
|
|
1150
1289
|
const q2 = (_b2 = s3 == null ? void 0 : s3.query) != null ? _b2 : "";
|
|
@@ -1156,7 +1295,7 @@ function ListerProvider(props) {
|
|
|
1156
1295
|
);
|
|
1157
1296
|
const searchLocalImpl = React.useCallback(
|
|
1158
1297
|
(id, q2, payload) => {
|
|
1159
|
-
patchSession(id, { query: q2 });
|
|
1298
|
+
patchSession(id, { query: q2, searchPayload: payload });
|
|
1160
1299
|
const s3 = getSession(id);
|
|
1161
1300
|
if (!s3) return;
|
|
1162
1301
|
if (s3.searchMode === "hybrid") {
|
|
@@ -1167,7 +1306,7 @@ function ListerProvider(props) {
|
|
|
1167
1306
|
);
|
|
1168
1307
|
const searchRemoteImpl = React.useCallback(
|
|
1169
1308
|
(id, q2, payload) => {
|
|
1170
|
-
patchSession(id, { query: q2 });
|
|
1309
|
+
patchSession(id, { query: q2, searchPayload: payload });
|
|
1171
1310
|
scheduleRemoteFetch(id, q2, payload);
|
|
1172
1311
|
},
|
|
1173
1312
|
[patchSession, scheduleRemoteFetch]
|
|
@@ -1195,13 +1334,30 @@ function ListerProvider(props) {
|
|
|
1195
1334
|
);
|
|
1196
1335
|
const getVisibleOptions = React.useCallback(
|
|
1197
1336
|
(id) => {
|
|
1337
|
+
var _a2, _b2, _c2, _d;
|
|
1198
1338
|
const s3 = getSession(id);
|
|
1199
1339
|
if (!s3) return [];
|
|
1200
|
-
if (s3.searchMode === "
|
|
1201
|
-
|
|
1202
|
-
if (
|
|
1203
|
-
|
|
1204
|
-
|
|
1340
|
+
if (s3.searchMode === "remote") return s3.optionsList;
|
|
1341
|
+
const def = s3.definition;
|
|
1342
|
+
if (!def) return [];
|
|
1343
|
+
const filters = (_a2 = s3.effectiveFilters) != null ? _a2 : s3.filters;
|
|
1344
|
+
const payload = (_b2 = s3.searchPayload) != null ? _b2 : buildSearchPayloadFromTarget(s3 == null ? void 0 : s3.searchTarget);
|
|
1345
|
+
const visibleRaw = filterRawListLocal(
|
|
1346
|
+
(_c2 = s3.rawList) != null ? _c2 : [],
|
|
1347
|
+
s3.query,
|
|
1348
|
+
payload,
|
|
1349
|
+
filters,
|
|
1350
|
+
{
|
|
1351
|
+
searchSpec: (_d = s3.searchSpec) != null ? _d : def.search,
|
|
1352
|
+
filtersSpec: s3.filtersSpec
|
|
1353
|
+
}
|
|
1354
|
+
);
|
|
1355
|
+
const mapCtx = { query: s3.query, filters };
|
|
1356
|
+
return mapOptions(
|
|
1357
|
+
visibleRaw,
|
|
1358
|
+
def.mapping,
|
|
1359
|
+
mapCtx
|
|
1360
|
+
);
|
|
1205
1361
|
},
|
|
1206
1362
|
[getSession]
|
|
1207
1363
|
);
|
|
@@ -1266,50 +1422,6 @@ function ListerProvider(props) {
|
|
|
1266
1422
|
);
|
|
1267
1423
|
return /* @__PURE__ */ jsx(Ctx.Provider, { value, children: props.children });
|
|
1268
1424
|
}
|
|
1269
|
-
function useLister() {
|
|
1270
|
-
const ctx = React.useContext(Ctx);
|
|
1271
|
-
if (!ctx)
|
|
1272
|
-
throw new Error("useLister must be used within <ListerProvider />");
|
|
1273
|
-
const api = React.useMemo(() => {
|
|
1274
|
-
const fetch = ((kindOrDef, filters, opts) => ctx.apiFetchAny(kindOrDef, filters, opts));
|
|
1275
|
-
const open = ((kindOrDef, filters, opts) => ctx.apiOpenAny(kindOrDef, filters, opts));
|
|
1276
|
-
return {
|
|
1277
|
-
fetch,
|
|
1278
|
-
open,
|
|
1279
|
-
registerPreset: (kind, def) => ctx.registerPreset(kind, def),
|
|
1280
|
-
getPreset: (kind) => ctx.getPreset(kind)
|
|
1281
|
-
};
|
|
1282
|
-
}, [ctx]);
|
|
1283
|
-
const active = ctx.store.activeId ? ctx.store.sessions[ctx.store.activeId] : void 0;
|
|
1284
|
-
return {
|
|
1285
|
-
api,
|
|
1286
|
-
store: ctx.store,
|
|
1287
|
-
state: active,
|
|
1288
|
-
actions: {
|
|
1289
|
-
focus: ctx.focus,
|
|
1290
|
-
dispose: ctx.dispose,
|
|
1291
|
-
apply: ctx.apply,
|
|
1292
|
-
cancel: ctx.cancel,
|
|
1293
|
-
close: ctx.close,
|
|
1294
|
-
toggle: ctx.toggle,
|
|
1295
|
-
select: ctx.select,
|
|
1296
|
-
deselect: ctx.deselect,
|
|
1297
|
-
clear: ctx.clear,
|
|
1298
|
-
setQuery: ctx.setQuery,
|
|
1299
|
-
setSearchMode: ctx.setSearchMode,
|
|
1300
|
-
setSearchTarget: ctx.setSearchTarget,
|
|
1301
|
-
searchLocal: ctx.searchLocal,
|
|
1302
|
-
searchRemote: ctx.searchRemote,
|
|
1303
|
-
refresh: ctx.refresh,
|
|
1304
|
-
setPosition: ctx.setPosition,
|
|
1305
|
-
getFilterCtx: ctx.getFilterCtx,
|
|
1306
|
-
applyFilterOption: ctx.applyFilterOption,
|
|
1307
|
-
registerPreset: ctx.registerPreset,
|
|
1308
|
-
getPreset: ctx.getPreset,
|
|
1309
|
-
getVisibleOptions: ctx.getVisibleOptions
|
|
1310
|
-
}
|
|
1311
|
-
};
|
|
1312
|
-
}
|
|
1313
1425
|
|
|
1314
1426
|
// ../../node_modules/clsx/dist/clsx.mjs
|
|
1315
1427
|
function r(e4) {
|
|
@@ -25800,6 +25912,7 @@ function SearchBar(props) {
|
|
|
25800
25912
|
}
|
|
25801
25913
|
};
|
|
25802
25914
|
const hasSearchTargetUI = !!searchSpec && (allowAll || specSubjects.length > 0 || specOnly.length > 0 || allowCustomSubject);
|
|
25915
|
+
console.log(searchMode);
|
|
25803
25916
|
return /* @__PURE__ */ jsx("div", { className: "px-3 py-2", onMouseDown: () => actions.focus(id), children: /* @__PURE__ */ jsx(
|
|
25804
25917
|
Input,
|
|
25805
25918
|
{
|
|
@@ -25971,7 +26084,7 @@ function SearchBar(props) {
|
|
|
25971
26084
|
{
|
|
25972
26085
|
variant: "select",
|
|
25973
26086
|
mode: "button",
|
|
25974
|
-
|
|
26087
|
+
defaultValue: searchMode,
|
|
25975
26088
|
triggerClassName: "border-none ring-0 shadow-none! px-1! cursor-pointer",
|
|
25976
26089
|
options: [
|
|
25977
26090
|
{
|
|
@@ -26248,6 +26361,429 @@ function FooterBar(props) {
|
|
|
26248
26361
|
}
|
|
26249
26362
|
);
|
|
26250
26363
|
}
|
|
26364
|
+
function useLister() {
|
|
26365
|
+
const ctx = React.useContext(Ctx);
|
|
26366
|
+
if (!ctx)
|
|
26367
|
+
throw new Error("useLister must be used within <ListerProvider />");
|
|
26368
|
+
const api = React.useMemo(() => {
|
|
26369
|
+
const fetch = ((kindOrDef, filters, opts) => ctx.apiFetchAny(kindOrDef, filters, opts));
|
|
26370
|
+
const open = ((kindOrDef, filters, opts) => ctx.apiOpenAny(kindOrDef, filters, opts));
|
|
26371
|
+
return {
|
|
26372
|
+
fetch,
|
|
26373
|
+
open,
|
|
26374
|
+
registerPreset: (kind, def) => ctx.registerPreset(kind, def),
|
|
26375
|
+
getPreset: (kind) => ctx.getPreset(kind)
|
|
26376
|
+
};
|
|
26377
|
+
}, [ctx]);
|
|
26378
|
+
const active = ctx.store.activeId ? ctx.store.sessions[ctx.store.activeId] : void 0;
|
|
26379
|
+
return {
|
|
26380
|
+
api,
|
|
26381
|
+
store: ctx.store,
|
|
26382
|
+
state: active,
|
|
26383
|
+
actions: {
|
|
26384
|
+
focus: ctx.focus,
|
|
26385
|
+
dispose: ctx.dispose,
|
|
26386
|
+
apply: ctx.apply,
|
|
26387
|
+
cancel: ctx.cancel,
|
|
26388
|
+
close: ctx.close,
|
|
26389
|
+
toggle: ctx.toggle,
|
|
26390
|
+
select: ctx.select,
|
|
26391
|
+
deselect: ctx.deselect,
|
|
26392
|
+
clear: ctx.clear,
|
|
26393
|
+
setQuery: ctx.setQuery,
|
|
26394
|
+
setSearchMode: ctx.setSearchMode,
|
|
26395
|
+
setSearchTarget: ctx.setSearchTarget,
|
|
26396
|
+
searchLocal: ctx.searchLocal,
|
|
26397
|
+
searchRemote: ctx.searchRemote,
|
|
26398
|
+
refresh: ctx.refresh,
|
|
26399
|
+
setPosition: ctx.setPosition,
|
|
26400
|
+
getFilterCtx: ctx.getFilterCtx,
|
|
26401
|
+
applyFilterOption: ctx.applyFilterOption,
|
|
26402
|
+
registerPreset: ctx.registerPreset,
|
|
26403
|
+
getPreset: ctx.getPreset,
|
|
26404
|
+
getVisibleOptions: ctx.getVisibleOptions
|
|
26405
|
+
}
|
|
26406
|
+
};
|
|
26407
|
+
}
|
|
26408
|
+
function defaultSearchTarget(search) {
|
|
26409
|
+
const def = search == null ? void 0 : search.default;
|
|
26410
|
+
return def ? { mode: "subject", subject: def, only: null } : void 0;
|
|
26411
|
+
}
|
|
26412
|
+
function isKey(x2) {
|
|
26413
|
+
return typeof x2 === "string" || typeof x2 === "number";
|
|
26414
|
+
}
|
|
26415
|
+
function useData(opts) {
|
|
26416
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
26417
|
+
const ctx = React.useContext(Ctx);
|
|
26418
|
+
if (!ctx) throw new Error("useData must be used within <ListerProvider />");
|
|
26419
|
+
const enabled = (_a = opts.enabled) != null ? _a : true;
|
|
26420
|
+
const debounceMs = (_b = opts.debounceMs) != null ? _b : 300;
|
|
26421
|
+
const [data, setData] = React.useState(() => {
|
|
26422
|
+
var _a2;
|
|
26423
|
+
return (_a2 = opts.initial) != null ? _a2 : [];
|
|
26424
|
+
});
|
|
26425
|
+
const [loading, setLoading] = React.useState(false);
|
|
26426
|
+
const [error, setError] = React.useState(void 0);
|
|
26427
|
+
const [query, _setQuery] = React.useState("");
|
|
26428
|
+
const [searchMode, _setSearchMode] = React.useState(
|
|
26429
|
+
(_c = opts.searchMode) != null ? _c : "remote"
|
|
26430
|
+
);
|
|
26431
|
+
const [searchTarget, _setSearchTarget] = React.useState(() => defaultSearchTarget(opts.search));
|
|
26432
|
+
const [filters, _setFilters] = React.useState(
|
|
26433
|
+
opts.filters
|
|
26434
|
+
);
|
|
26435
|
+
const selectionMode = (_e = (_d = opts.selection) == null ? void 0 : _d.mode) != null ? _e : "none";
|
|
26436
|
+
const selectionPrune = (_g = (_f = opts.selection) == null ? void 0 : _f.prune) != null ? _g : "never";
|
|
26437
|
+
const getItemKey = React.useMemo(() => {
|
|
26438
|
+
var _a2;
|
|
26439
|
+
const key = (_a2 = opts.selection) == null ? void 0 : _a2.key;
|
|
26440
|
+
if (!key) {
|
|
26441
|
+
return (item) => {
|
|
26442
|
+
var _a3;
|
|
26443
|
+
const v2 = (_a3 = item == null ? void 0 : item.id) != null ? _a3 : item == null ? void 0 : item.value;
|
|
26444
|
+
return isKey(v2) ? v2 : null;
|
|
26445
|
+
};
|
|
26446
|
+
}
|
|
26447
|
+
if (typeof key === "function") {
|
|
26448
|
+
return (item) => {
|
|
26449
|
+
const v2 = key(item);
|
|
26450
|
+
return isKey(v2) ? v2 : null;
|
|
26451
|
+
};
|
|
26452
|
+
}
|
|
26453
|
+
return (item) => {
|
|
26454
|
+
const v2 = item == null ? void 0 : item[key];
|
|
26455
|
+
return isKey(v2) ? v2 : null;
|
|
26456
|
+
};
|
|
26457
|
+
}, [(_h = opts.selection) == null ? void 0 : _h.key]);
|
|
26458
|
+
const [selectedIdsArr, setSelectedIdsArr] = React.useState([]);
|
|
26459
|
+
const selectedCacheRef = React.useRef(/* @__PURE__ */ new Map());
|
|
26460
|
+
const reqIdRef = React.useRef(0);
|
|
26461
|
+
const timerRef = React.useRef(null);
|
|
26462
|
+
const didMountRef = React.useRef(false);
|
|
26463
|
+
const skipNextModeEffectRef = React.useRef(false);
|
|
26464
|
+
const inlineDef = React.useMemo(() => {
|
|
26465
|
+
var _a2;
|
|
26466
|
+
return makeInlineDef({
|
|
26467
|
+
id: opts.id,
|
|
26468
|
+
endpoint: opts.endpoint,
|
|
26469
|
+
method: (_a2 = opts.method) != null ? _a2 : "GET",
|
|
26470
|
+
selector: opts.selector,
|
|
26471
|
+
buildRequest: opts.buildRequest,
|
|
26472
|
+
search: opts.search
|
|
26473
|
+
});
|
|
26474
|
+
}, [
|
|
26475
|
+
opts.id,
|
|
26476
|
+
opts.endpoint,
|
|
26477
|
+
opts.method,
|
|
26478
|
+
opts.selector,
|
|
26479
|
+
opts.buildRequest,
|
|
26480
|
+
opts.search
|
|
26481
|
+
]);
|
|
26482
|
+
const dataById = React.useMemo(() => {
|
|
26483
|
+
const map = /* @__PURE__ */ new Map();
|
|
26484
|
+
if (selectionMode === "none") return map;
|
|
26485
|
+
for (const item of data) {
|
|
26486
|
+
const k2 = getItemKey(item);
|
|
26487
|
+
if (k2 == null) continue;
|
|
26488
|
+
map.set(k2, item);
|
|
26489
|
+
}
|
|
26490
|
+
return map;
|
|
26491
|
+
}, [data, getItemKey, selectionMode]);
|
|
26492
|
+
const normalizeIds = React.useCallback((v2) => {
|
|
26493
|
+
return Array.isArray(v2) ? v2 : [v2];
|
|
26494
|
+
}, []);
|
|
26495
|
+
const commitSelectedCache = React.useCallback(
|
|
26496
|
+
(list) => {
|
|
26497
|
+
if (selectionMode === "none") return;
|
|
26498
|
+
for (const item of list) {
|
|
26499
|
+
const k2 = getItemKey(item);
|
|
26500
|
+
if (k2 == null) continue;
|
|
26501
|
+
selectedCacheRef.current.set(k2, item);
|
|
26502
|
+
}
|
|
26503
|
+
},
|
|
26504
|
+
[getItemKey, selectionMode]
|
|
26505
|
+
);
|
|
26506
|
+
const fetchImpl = React.useCallback(
|
|
26507
|
+
async (override) => {
|
|
26508
|
+
var _a2, _b2, _c2, _d2, _e2, _f2;
|
|
26509
|
+
if (!enabled) return data;
|
|
26510
|
+
const q2 = (_a2 = override == null ? void 0 : override.query) != null ? _a2 : query;
|
|
26511
|
+
const f2 = (_b2 = override == null ? void 0 : override.filters) != null ? _b2 : filters;
|
|
26512
|
+
const t4 = (_c2 = override == null ? void 0 : override.searchTarget) != null ? _c2 : searchTarget;
|
|
26513
|
+
const myReq = ++reqIdRef.current;
|
|
26514
|
+
setLoading(true);
|
|
26515
|
+
setError(void 0);
|
|
26516
|
+
try {
|
|
26517
|
+
const payload = (_d2 = override == null ? void 0 : override.search) != null ? _d2 : buildSearchPayloadFromTarget(t4);
|
|
26518
|
+
const res = await ctx.apiFetchAny(inlineDef, f2, {
|
|
26519
|
+
query: q2,
|
|
26520
|
+
search: payload
|
|
26521
|
+
});
|
|
26522
|
+
const list = (_f2 = (_e2 = res == null ? void 0 : res.rawList) != null ? _e2 : res == null ? void 0 : res.raw) != null ? _f2 : [];
|
|
26523
|
+
commitSelectedCache(list);
|
|
26524
|
+
if (selectionMode !== "none" && selectionPrune === "missing") {
|
|
26525
|
+
const nextIds = /* @__PURE__ */ new Set();
|
|
26526
|
+
for (const item of list) {
|
|
26527
|
+
const k2 = getItemKey(item);
|
|
26528
|
+
if (k2 != null) nextIds.add(k2);
|
|
26529
|
+
}
|
|
26530
|
+
setSelectedIdsArr(
|
|
26531
|
+
(prev) => prev.filter((x2) => nextIds.has(x2))
|
|
26532
|
+
);
|
|
26533
|
+
}
|
|
26534
|
+
if (reqIdRef.current !== myReq) return list;
|
|
26535
|
+
setData(list);
|
|
26536
|
+
setLoading(false);
|
|
26537
|
+
return list;
|
|
26538
|
+
} catch (e4) {
|
|
26539
|
+
if (reqIdRef.current !== myReq) return data;
|
|
26540
|
+
setError(e4);
|
|
26541
|
+
setLoading(false);
|
|
26542
|
+
return data;
|
|
26543
|
+
}
|
|
26544
|
+
},
|
|
26545
|
+
[
|
|
26546
|
+
commitSelectedCache,
|
|
26547
|
+
ctx,
|
|
26548
|
+
data,
|
|
26549
|
+
enabled,
|
|
26550
|
+
filters,
|
|
26551
|
+
getItemKey,
|
|
26552
|
+
inlineDef,
|
|
26553
|
+
query,
|
|
26554
|
+
searchTarget,
|
|
26555
|
+
selectionMode,
|
|
26556
|
+
selectionPrune
|
|
26557
|
+
]
|
|
26558
|
+
);
|
|
26559
|
+
const refresh = React.useCallback(() => {
|
|
26560
|
+
void fetchImpl();
|
|
26561
|
+
}, [fetchImpl]);
|
|
26562
|
+
const setQuery = React.useCallback((q2) => _setQuery(q2), []);
|
|
26563
|
+
const setSearchMode = React.useCallback(
|
|
26564
|
+
(m2) => {
|
|
26565
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
26566
|
+
if (m2 === "remote" || m2 === "hybrid") {
|
|
26567
|
+
skipNextModeEffectRef.current = true;
|
|
26568
|
+
_setSearchMode(m2);
|
|
26569
|
+
void fetchImpl();
|
|
26570
|
+
return;
|
|
26571
|
+
}
|
|
26572
|
+
_setSearchMode(m2);
|
|
26573
|
+
if (m2 === "local") {
|
|
26574
|
+
void fetchImpl({
|
|
26575
|
+
query: "",
|
|
26576
|
+
search: void 0
|
|
26577
|
+
});
|
|
26578
|
+
}
|
|
26579
|
+
},
|
|
26580
|
+
[fetchImpl]
|
|
26581
|
+
);
|
|
26582
|
+
const setSearchTarget = React.useCallback(
|
|
26583
|
+
(t4) => {
|
|
26584
|
+
_setSearchTarget(t4);
|
|
26585
|
+
if (searchMode === "remote" || searchMode === "hybrid") {
|
|
26586
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
26587
|
+
timerRef.current = setTimeout(() => {
|
|
26588
|
+
void fetchImpl({ searchTarget: t4 });
|
|
26589
|
+
}, debounceMs);
|
|
26590
|
+
}
|
|
26591
|
+
},
|
|
26592
|
+
[debounceMs, fetchImpl, searchMode]
|
|
26593
|
+
);
|
|
26594
|
+
const setFilters = React.useCallback(
|
|
26595
|
+
(next) => _setFilters(next),
|
|
26596
|
+
[]
|
|
26597
|
+
);
|
|
26598
|
+
const patchFilters = React.useCallback((patch) => {
|
|
26599
|
+
_setFilters((prev) => ({
|
|
26600
|
+
...prev != null ? prev : {},
|
|
26601
|
+
...patch
|
|
26602
|
+
}));
|
|
26603
|
+
}, []);
|
|
26604
|
+
const clearFilters = React.useCallback(() => _setFilters(void 0), []);
|
|
26605
|
+
const fetchOnMount = (_i = opts.fetchOnMount) != null ? _i : !opts.initial;
|
|
26606
|
+
React.useEffect(() => {
|
|
26607
|
+
if (!enabled) return;
|
|
26608
|
+
if (!fetchOnMount) return;
|
|
26609
|
+
void fetchImpl();
|
|
26610
|
+
}, []);
|
|
26611
|
+
React.useEffect(() => {
|
|
26612
|
+
if (!enabled) return;
|
|
26613
|
+
if (!didMountRef.current) {
|
|
26614
|
+
didMountRef.current = true;
|
|
26615
|
+
return;
|
|
26616
|
+
}
|
|
26617
|
+
if (searchMode !== "remote" && searchMode !== "hybrid") return;
|
|
26618
|
+
if (skipNextModeEffectRef.current) {
|
|
26619
|
+
skipNextModeEffectRef.current = false;
|
|
26620
|
+
return;
|
|
26621
|
+
}
|
|
26622
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
26623
|
+
timerRef.current = setTimeout(() => {
|
|
26624
|
+
void fetchImpl();
|
|
26625
|
+
}, debounceMs);
|
|
26626
|
+
return () => {
|
|
26627
|
+
if (timerRef.current) clearTimeout(timerRef.current);
|
|
26628
|
+
};
|
|
26629
|
+
}, [debounceMs, enabled, fetchImpl, query, searchMode, searchTarget]);
|
|
26630
|
+
React.useEffect(() => {
|
|
26631
|
+
if (!enabled) return;
|
|
26632
|
+
if (opts.autoFetchOnFilterChange === false) return;
|
|
26633
|
+
if (!didMountRef.current) return;
|
|
26634
|
+
if (searchMode !== "remote" && searchMode !== "hybrid") return;
|
|
26635
|
+
void fetchImpl();
|
|
26636
|
+
}, [enabled, fetchImpl, filters, opts.autoFetchOnFilterChange, searchMode]);
|
|
26637
|
+
const visible = React.useMemo(() => {
|
|
26638
|
+
if (searchMode !== "local" && searchMode !== "hybrid") return data;
|
|
26639
|
+
const payload = buildSearchPayloadFromTarget(searchTarget);
|
|
26640
|
+
let list = data;
|
|
26641
|
+
if ((payload == null ? void 0 : payload.searchOnly) && payload.searchOnly.length) {
|
|
26642
|
+
const allow = new Set(payload.searchOnly);
|
|
26643
|
+
list = list.filter((item) => {
|
|
26644
|
+
const k2 = getItemKey(item);
|
|
26645
|
+
return k2 != null && allow.has(k2);
|
|
26646
|
+
});
|
|
26647
|
+
}
|
|
26648
|
+
const q2 = query.trim();
|
|
26649
|
+
if (!q2) return list;
|
|
26650
|
+
const ql = q2.toLowerCase();
|
|
26651
|
+
if (payload == null ? void 0 : payload.subject) {
|
|
26652
|
+
const key = payload.subject;
|
|
26653
|
+
return list.filter(
|
|
26654
|
+
(item) => {
|
|
26655
|
+
var _a2;
|
|
26656
|
+
return String((_a2 = item == null ? void 0 : item[key]) != null ? _a2 : "").toLowerCase().includes(ql);
|
|
26657
|
+
}
|
|
26658
|
+
);
|
|
26659
|
+
}
|
|
26660
|
+
return list.filter(
|
|
26661
|
+
(item) => String(item != null ? item : "").toLowerCase().includes(ql)
|
|
26662
|
+
);
|
|
26663
|
+
}, [data, getItemKey, query, searchMode, searchTarget]);
|
|
26664
|
+
const selectedIds = React.useMemo(() => {
|
|
26665
|
+
var _a2;
|
|
26666
|
+
if (selectionMode === "none") return null;
|
|
26667
|
+
if (selectionMode === "single") return (_a2 = selectedIdsArr[0]) != null ? _a2 : null;
|
|
26668
|
+
return selectedIdsArr;
|
|
26669
|
+
}, [selectionMode, selectedIdsArr]);
|
|
26670
|
+
const isSelected = React.useCallback(
|
|
26671
|
+
(id) => {
|
|
26672
|
+
if (selectionMode === "none") return false;
|
|
26673
|
+
return selectedIdsArr.includes(id);
|
|
26674
|
+
},
|
|
26675
|
+
[selectedIdsArr, selectionMode]
|
|
26676
|
+
);
|
|
26677
|
+
const clearSelection = React.useCallback(() => {
|
|
26678
|
+
if (selectionMode === "none") return;
|
|
26679
|
+
setSelectedIdsArr([]);
|
|
26680
|
+
}, [selectionMode]);
|
|
26681
|
+
const select = React.useCallback(
|
|
26682
|
+
(idOrIds) => {
|
|
26683
|
+
if (selectionMode === "none") return;
|
|
26684
|
+
const ids = normalizeIds(idOrIds).filter(isKey);
|
|
26685
|
+
if (!ids.length) return;
|
|
26686
|
+
for (const id of ids) {
|
|
26687
|
+
const hit = dataById.get(id);
|
|
26688
|
+
if (hit) selectedCacheRef.current.set(id, hit);
|
|
26689
|
+
}
|
|
26690
|
+
if (selectionMode === "single") {
|
|
26691
|
+
setSelectedIdsArr([ids[0]]);
|
|
26692
|
+
return;
|
|
26693
|
+
}
|
|
26694
|
+
setSelectedIdsArr((prev) => {
|
|
26695
|
+
const set = new Set(prev);
|
|
26696
|
+
for (const id of ids) set.add(id);
|
|
26697
|
+
return Array.from(set);
|
|
26698
|
+
});
|
|
26699
|
+
},
|
|
26700
|
+
[dataById, normalizeIds, selectionMode]
|
|
26701
|
+
);
|
|
26702
|
+
const deselect = React.useCallback(
|
|
26703
|
+
(idOrIds) => {
|
|
26704
|
+
if (selectionMode === "none") return;
|
|
26705
|
+
const ids = new Set(normalizeIds(idOrIds).filter(isKey));
|
|
26706
|
+
if (!ids.size) return;
|
|
26707
|
+
setSelectedIdsArr((prev) => {
|
|
26708
|
+
const next = prev.filter((x2) => !ids.has(x2));
|
|
26709
|
+
if (selectionMode === "single") return next.slice(0, 1);
|
|
26710
|
+
return next;
|
|
26711
|
+
});
|
|
26712
|
+
},
|
|
26713
|
+
[normalizeIds, selectionMode]
|
|
26714
|
+
);
|
|
26715
|
+
const toggle = React.useCallback(
|
|
26716
|
+
(id) => {
|
|
26717
|
+
if (selectionMode === "none") return;
|
|
26718
|
+
const hit = dataById.get(id);
|
|
26719
|
+
if (hit) selectedCacheRef.current.set(id, hit);
|
|
26720
|
+
if (selectionMode === "single") {
|
|
26721
|
+
setSelectedIdsArr((prev) => prev[0] === id ? [] : [id]);
|
|
26722
|
+
return;
|
|
26723
|
+
}
|
|
26724
|
+
setSelectedIdsArr((prev) => {
|
|
26725
|
+
const set = new Set(prev);
|
|
26726
|
+
if (set.has(id)) set.delete(id);
|
|
26727
|
+
else set.add(id);
|
|
26728
|
+
return Array.from(set);
|
|
26729
|
+
});
|
|
26730
|
+
},
|
|
26731
|
+
[dataById, selectionMode]
|
|
26732
|
+
);
|
|
26733
|
+
const selected = React.useMemo(() => {
|
|
26734
|
+
var _a2, _b2, _c2, _d2;
|
|
26735
|
+
if (selectionMode === "none") return null;
|
|
26736
|
+
if (selectionMode === "single") {
|
|
26737
|
+
const id = selectedIdsArr[0];
|
|
26738
|
+
if (id == null) return null;
|
|
26739
|
+
return (_b2 = (_a2 = dataById.get(id)) != null ? _a2 : selectedCacheRef.current.get(id)) != null ? _b2 : null;
|
|
26740
|
+
}
|
|
26741
|
+
const out = [];
|
|
26742
|
+
for (const id of selectedIdsArr) {
|
|
26743
|
+
const item = (_d2 = (_c2 = dataById.get(id)) != null ? _c2 : selectedCacheRef.current.get(id)) != null ? _d2 : null;
|
|
26744
|
+
if (item) out.push(item);
|
|
26745
|
+
}
|
|
26746
|
+
return out;
|
|
26747
|
+
}, [dataById, selectedIdsArr, selectionMode]);
|
|
26748
|
+
const getSelection = React.useCallback(() => selected, [selected]);
|
|
26749
|
+
React.useEffect(() => {
|
|
26750
|
+
if (selectionMode === "none") {
|
|
26751
|
+
setSelectedIdsArr([]);
|
|
26752
|
+
return;
|
|
26753
|
+
}
|
|
26754
|
+
if (selectionMode === "single") {
|
|
26755
|
+
setSelectedIdsArr((prev) => prev.length ? [prev[0]] : []);
|
|
26756
|
+
}
|
|
26757
|
+
}, [selectionMode]);
|
|
26758
|
+
return {
|
|
26759
|
+
id: opts.id,
|
|
26760
|
+
data,
|
|
26761
|
+
visible,
|
|
26762
|
+
loading,
|
|
26763
|
+
error,
|
|
26764
|
+
query,
|
|
26765
|
+
setQuery,
|
|
26766
|
+
searchMode,
|
|
26767
|
+
setSearchMode,
|
|
26768
|
+
searchTarget,
|
|
26769
|
+
setSearchTarget,
|
|
26770
|
+
filters,
|
|
26771
|
+
setFilters,
|
|
26772
|
+
patchFilters,
|
|
26773
|
+
clearFilters,
|
|
26774
|
+
selectionMode,
|
|
26775
|
+
selectedIds,
|
|
26776
|
+
selected,
|
|
26777
|
+
select,
|
|
26778
|
+
deselect,
|
|
26779
|
+
toggle,
|
|
26780
|
+
clearSelection,
|
|
26781
|
+
isSelected,
|
|
26782
|
+
getSelection,
|
|
26783
|
+
refresh,
|
|
26784
|
+
fetch: fetchImpl
|
|
26785
|
+
};
|
|
26786
|
+
}
|
|
26251
26787
|
/*! Bundled license information:
|
|
26252
26788
|
|
|
26253
26789
|
lucide-react/dist/esm/shared/src/utils.js:
|
|
@@ -26298,6 +26834,6 @@ lucide-react/dist/esm/lucide-react.js:
|
|
|
26298
26834
|
*)
|
|
26299
26835
|
*/
|
|
26300
26836
|
|
|
26301
|
-
export { FooterBar, HeaderBar, json_editor_default as JsonEditor, ListerProvider, ListerUI, OptionList, SearchBar, useLister };
|
|
26837
|
+
export { Ctx, FooterBar, HeaderBar, json_editor_default as JsonEditor, ListerProvider, ListerUI, OptionList, SearchBar, buildSearchPayloadFromTarget, useData, useLister };
|
|
26302
26838
|
//# sourceMappingURL=extra.mjs.map
|
|
26303
26839
|
//# sourceMappingURL=extra.mjs.map
|