@easyvision/easyvision-ui 1.9.3 → 1.10.0
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 +33 -1
- package/dist/index.cjs +107 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -1
- package/dist/index.d.ts +74 -1
- package/dist/index.js +106 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1449,7 +1449,7 @@ const filter: LoopbackFilter = {
|
|
|
1449
1449
|
|
|
1450
1450
|
The library makes no assumptions about how the HTTP requests are issued — `fetchPage` and `fetchCount` are plain async functions. Bring your own auth, base URL, error handling, etc.
|
|
1451
1451
|
|
|
1452
|
-
For non-LoopBack backends, inline a custom `fetchData` — see [Adapting an arbitrary API response](#adapting-an-arbitrary-api-response) below — or contribute a sibling adapter (
|
|
1452
|
+
For non-LoopBack backends, inline a custom `fetchData` — see [Adapting an arbitrary API response](#adapting-an-arbitrary-api-response) below — or contribute a sibling adapter following the same pattern (see `adapters/ingot.ts` below).
|
|
1453
1453
|
|
|
1454
1454
|
#### Local mode filtering with the same DSL — `matchLoopbackWhere`
|
|
1455
1455
|
|
|
@@ -1529,6 +1529,38 @@ Behavior on edge cases:
|
|
|
1529
1529
|
- Unknown `$operator` → `false` (fail-closed; surfaces typos early).
|
|
1530
1530
|
- Plain-object equality (`{ a: { b: 1 } }`) is not supported — use dotted paths (`'a.b'`) or `$and`.
|
|
1531
1531
|
|
|
1532
|
+
### API adapters: ingot (NML v3)
|
|
1533
|
+
|
|
1534
|
+
ingot keeps LoopBack's `?filter=` shape (`where`, `include`, `order`, `fields`, `limit`, `skip`) but only accepts operator names without `$`. The `ingot` prop (or `createIngotTableFetcher`) takes the same mongo-style `where` the multifilter builds and translates it on the way out, so multifilters, local mode and `externalFilter` stay unchanged:
|
|
1535
|
+
|
|
1536
|
+
| Multifilter emits | Sent to ingot |
|
|
1537
|
+
|---|---|
|
|
1538
|
+
| `$in` / `$nin` | `inq` / `nin` |
|
|
1539
|
+
| `$eq`, `$ne`/`$neq`, `$gt`, `$gte`, `$lt`, `$lte`, `$exists` | `eq`, `neq`, `gt`, `gte`, `lt`, `lte`, `exists` |
|
|
1540
|
+
| `$and` / `$or` | `and` / `or` |
|
|
1541
|
+
| text search (`$regex: '.*…*'`, `$options: 'i'`) | `ilike: '…'` (ingot's `like`/`ilike` are literal substring matches) |
|
|
1542
|
+
|
|
1543
|
+
Anything ingot cannot express — `$not`, a real regex pattern (ingot disables `regexp`), an unknown `$` operator — throws instead of being dropped, so a filter never silently widens. Operators already in ingot form pass through.
|
|
1544
|
+
|
|
1545
|
+
ingot returns the total in the `X-Total-Count` header of the page response, so there is no `fetchCount`: `fetchPage` returns `{ rows, totalCount }`.
|
|
1546
|
+
|
|
1547
|
+
```tsx
|
|
1548
|
+
<EasyVisionTable
|
|
1549
|
+
id="documents"
|
|
1550
|
+
ingot={{
|
|
1551
|
+
fetchPage: async (filter) => {
|
|
1552
|
+
const res = await api.get('/documents', { params: { filter: JSON.stringify(filter) } });
|
|
1553
|
+
return { rows: res.data, totalCount: Number(res.headers['x-total-count']) };
|
|
1554
|
+
},
|
|
1555
|
+
include: [{ relation: 'subject' }],
|
|
1556
|
+
defaultOrder: ['updatedAt DESC'],
|
|
1557
|
+
}}
|
|
1558
|
+
columns={columns}
|
|
1559
|
+
/>
|
|
1560
|
+
```
|
|
1561
|
+
|
|
1562
|
+
`toIngotWhere(where)` is exported for requests the table does not make (e.g. a `/count` or `/export` call with the same multifilter `where`).
|
|
1563
|
+
|
|
1532
1564
|
### Adapting an arbitrary API response
|
|
1533
1565
|
|
|
1534
1566
|
`fetchData` must return `{ rows: T[]; totalCount: number }`. Wrap whatever shape your backend gives you:
|
package/dist/index.cjs
CHANGED
|
@@ -2352,6 +2352,97 @@ function matchLeaf(value, condition) {
|
|
|
2352
2352
|
return true;
|
|
2353
2353
|
}
|
|
2354
2354
|
|
|
2355
|
+
// adapters/ingot.ts
|
|
2356
|
+
var OPERATORS = {
|
|
2357
|
+
$eq: "eq",
|
|
2358
|
+
$ne: "neq",
|
|
2359
|
+
$neq: "neq",
|
|
2360
|
+
$in: "inq",
|
|
2361
|
+
$nin: "nin",
|
|
2362
|
+
$gt: "gt",
|
|
2363
|
+
$gte: "gte",
|
|
2364
|
+
$lt: "lt",
|
|
2365
|
+
$lte: "lte",
|
|
2366
|
+
$exists: "exists"
|
|
2367
|
+
};
|
|
2368
|
+
var LOGICAL = { $and: "and", $or: "or" };
|
|
2369
|
+
var isPlainObject = (v) => typeof v === "object" && v !== null && !Array.isArray(v) && !(v instanceof Date);
|
|
2370
|
+
function regexToLiteral(pattern) {
|
|
2371
|
+
const body = pattern.replace(/^\.\*/, "");
|
|
2372
|
+
let literal = "";
|
|
2373
|
+
for (let i = 0; i < body.length; i++) {
|
|
2374
|
+
const ch = body[i];
|
|
2375
|
+
if (ch === "\\") {
|
|
2376
|
+
if (i + 1 >= body.length) return void 0;
|
|
2377
|
+
literal += body[++i];
|
|
2378
|
+
} else if (ch === "." && body[i + 1] === "*" && i + 2 === body.length) {
|
|
2379
|
+
break;
|
|
2380
|
+
} else if (".*+?^${}()|[]".includes(ch)) {
|
|
2381
|
+
return void 0;
|
|
2382
|
+
} else {
|
|
2383
|
+
literal += ch;
|
|
2384
|
+
}
|
|
2385
|
+
}
|
|
2386
|
+
return literal;
|
|
2387
|
+
}
|
|
2388
|
+
function translateOperators(field, ops) {
|
|
2389
|
+
const out = {};
|
|
2390
|
+
for (const [op, value] of Object.entries(ops)) {
|
|
2391
|
+
if (!op.startsWith("$")) {
|
|
2392
|
+
out[op] = value;
|
|
2393
|
+
} else if (op === "$regex") {
|
|
2394
|
+
const flags = ops.$options ?? "";
|
|
2395
|
+
if (flags !== "" && flags !== "i") {
|
|
2396
|
+
throw new Error(`ingot: unsupported $options "${String(flags)}" on "${field}" (only "i")`);
|
|
2397
|
+
}
|
|
2398
|
+
const literal = typeof value === "string" ? regexToLiteral(value) : void 0;
|
|
2399
|
+
if (literal === void 0) {
|
|
2400
|
+
throw new Error(`ingot: "${field}" uses a regex pattern; ingot only supports literal substring search`);
|
|
2401
|
+
}
|
|
2402
|
+
out[flags === "i" ? "ilike" : "like"] = literal;
|
|
2403
|
+
} else if (op === "$options") {
|
|
2404
|
+
if (!("$regex" in ops)) throw new Error(`ingot: $options without $regex on "${field}"`);
|
|
2405
|
+
} else if (op in OPERATORS) {
|
|
2406
|
+
out[OPERATORS[op]] = value;
|
|
2407
|
+
} else {
|
|
2408
|
+
throw new Error(`ingot: unsupported operator ${op} on "${field}"`);
|
|
2409
|
+
}
|
|
2410
|
+
}
|
|
2411
|
+
return out;
|
|
2412
|
+
}
|
|
2413
|
+
function toIngotWhere(where) {
|
|
2414
|
+
const out = {};
|
|
2415
|
+
for (const [key, value] of Object.entries(where)) {
|
|
2416
|
+
if (key in LOGICAL) {
|
|
2417
|
+
if (!Array.isArray(value)) throw new Error(`ingot: ${key} expects an array`);
|
|
2418
|
+
out[LOGICAL[key]] = value.map((sub) => toIngotWhere(sub));
|
|
2419
|
+
} else if (key.startsWith("$")) {
|
|
2420
|
+
throw new Error(`ingot: unsupported operator ${key}`);
|
|
2421
|
+
} else if (isPlainObject(value) && Object.keys(value).some((k) => k.startsWith("$"))) {
|
|
2422
|
+
out[key] = translateOperators(key, value);
|
|
2423
|
+
} else {
|
|
2424
|
+
out[key] = value;
|
|
2425
|
+
}
|
|
2426
|
+
}
|
|
2427
|
+
return out;
|
|
2428
|
+
}
|
|
2429
|
+
function createIngotTableFetcher(opts) {
|
|
2430
|
+
const { fetchPage, include, fields, defaultOrder, idFields } = opts;
|
|
2431
|
+
return async ({ page, itemsPerPage, sort, filter, idsOnly }) => {
|
|
2432
|
+
const order = sort ? [`${sort.column} ${sort.descending ? "DESC" : "ASC"}`] : defaultOrder ?? [];
|
|
2433
|
+
const effectiveFields = idsOnly ? idFields ?? ["id"] : fields;
|
|
2434
|
+
const effectiveInclude = idsOnly ? void 0 : include;
|
|
2435
|
+
return fetchPage({
|
|
2436
|
+
where: toIngotWhere(filter?.where ?? {}),
|
|
2437
|
+
skip: (page - 1) * itemsPerPage,
|
|
2438
|
+
limit: itemsPerPage,
|
|
2439
|
+
order,
|
|
2440
|
+
...effectiveInclude ? { include: effectiveInclude } : {},
|
|
2441
|
+
...effectiveFields ? { fields: effectiveFields } : {}
|
|
2442
|
+
});
|
|
2443
|
+
};
|
|
2444
|
+
}
|
|
2445
|
+
|
|
2355
2446
|
// export/sources.ts
|
|
2356
2447
|
var sources = /* @__PURE__ */ new Map();
|
|
2357
2448
|
var registerExportSource = (fullId, source) => {
|
|
@@ -2417,6 +2508,7 @@ function EasyVisionTable(props) {
|
|
|
2417
2508
|
data,
|
|
2418
2509
|
fetchData: fetchDataProp,
|
|
2419
2510
|
loopback,
|
|
2511
|
+
ingot,
|
|
2420
2512
|
onDataLoaded,
|
|
2421
2513
|
multifilter,
|
|
2422
2514
|
multifilterRef,
|
|
@@ -2455,9 +2547,19 @@ function EasyVisionTable(props) {
|
|
|
2455
2547
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2456
2548
|
[lbFetchPage, lbFetchCount, lbIncludeKey, lbFieldsKey, lbOrderKey]
|
|
2457
2549
|
);
|
|
2458
|
-
const
|
|
2459
|
-
const
|
|
2460
|
-
const
|
|
2550
|
+
const igFetchPage = ingot?.fetchPage;
|
|
2551
|
+
const igIncludeKey = JSON.stringify(ingot?.include ?? null);
|
|
2552
|
+
const igFieldsKey = JSON.stringify(ingot?.fields ?? null);
|
|
2553
|
+
const igOrderKey = JSON.stringify(ingot?.defaultOrder ?? null);
|
|
2554
|
+
const ingotFetcher = React9.useMemo(
|
|
2555
|
+
() => ingot ? createIngotTableFetcher(ingot) : void 0,
|
|
2556
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2557
|
+
[igFetchPage, igIncludeKey, igFieldsKey, igOrderKey]
|
|
2558
|
+
);
|
|
2559
|
+
const fetchData = fetchDataProp ?? loopbackFetcher ?? ingotFetcher;
|
|
2560
|
+
const apiShortcut = Boolean(loopback || ingot);
|
|
2561
|
+
const paginationMode = apiShortcut ? "api" : paginationModeProp;
|
|
2562
|
+
const orderingMode = apiShortcut ? "api" : orderingModeProp;
|
|
2461
2563
|
const getRowId = React9.useMemo(
|
|
2462
2564
|
() => getRowIdProp ?? ((row) => String(row?.id ?? "")),
|
|
2463
2565
|
[getRowIdProp]
|
|
@@ -3321,6 +3423,7 @@ exports.EasyVisionMultifilter = EasyVisionMultifilter;
|
|
|
3321
3423
|
exports.EasyVisionSelector = EasyVisionSelector;
|
|
3322
3424
|
exports.EasyVisionTable = EasyVisionTable;
|
|
3323
3425
|
exports.buildWorkbook = buildWorkbook;
|
|
3426
|
+
exports.createIngotTableFetcher = createIngotTableFetcher;
|
|
3324
3427
|
exports.createLoopbackTableFetcher = createLoopbackTableFetcher;
|
|
3325
3428
|
exports.defaultCell = defaultCell;
|
|
3326
3429
|
exports.downloadBlob = downloadBlob;
|
|
@@ -3330,5 +3433,6 @@ exports.getSlice = getSlice;
|
|
|
3330
3433
|
exports.matchLoopbackWhere = matchLoopbackWhere;
|
|
3331
3434
|
exports.sanitizeSheetName = sanitizeSheetName;
|
|
3332
3435
|
exports.toExportColumns = toExportColumns;
|
|
3436
|
+
exports.toIngotWhere = toIngotWhere;
|
|
3333
3437
|
//# sourceMappingURL=index.cjs.map
|
|
3334
3438
|
//# sourceMappingURL=index.cjs.map
|