@easyvision/easyvision-ui 1.9.2 → 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 CHANGED
@@ -693,7 +693,7 @@ Override per field with `toCondition: (value) => unknown` (return either a primi
693
693
  | `onPerform` | `(snap) => void` | — | Fires when perform commits — from Buscar, `performOnMount`, the imperative `perform()` ref, or (live mode) any value/field change after the debounce. Dispatched on a microtask so calling `setState` inside is safe. |
694
694
  | `onChange` | `(snap) => void` | — | Every change (per keystroke / option toggle). |
695
695
  | `onStateChange` | `(snap) => void` | — | Same as `onChange`; provided for API symmetry. |
696
- | `showClearAll` | `boolean` | `editable` | Clears values & active fields. |
696
+ | `showClearAll` | `boolean` | `editable` | Resets values & active fields to their initial state (`defaultValue`s and `pinned`/`initiallyActive` fields). |
697
697
  | `labels` | `Partial<MultifilterLabels>` | Spanish defaults | |
698
698
  | `className`, `persist`, `clearWhen` | as in Input/Selector | | |
699
699
 
@@ -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 (e.g. `adapters/westack.ts`) following the same pattern.
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
@@ -1385,22 +1385,15 @@ var EasyVisionMultifilter = React9.forwardRef(function EasyVisionMultifilter2(pr
1385
1385
  );
1386
1386
  const [clearTick, setClearTick] = React9.useState(0);
1387
1387
  const clearAll = React9.useCallback(() => {
1388
- const seed = {};
1389
- if (config.searchField?.defaultValue !== void 0) {
1390
- seed[config.searchField.id] = config.searchField.defaultValue;
1391
- }
1392
1388
  patch({
1393
- values: seed,
1394
- activeFields: initialActive.filter((id2) => {
1395
- const def = config.fields.find((f) => f.id === id2);
1396
- return def?.pinned;
1397
- }).concat(config.searchField ? [config.searchField.id] : []),
1389
+ values: initialValues,
1390
+ activeFields: initialActive,
1398
1391
  lastConfirmedSnapshotJSON: null
1399
1392
  });
1400
1393
  if (lastConfirmedSnapshotJSON !== null && resolvedPerformMode !== "live") {
1401
1394
  setClearTick((n) => n + 1);
1402
1395
  }
1403
- }, [config, patch, initialActive, lastConfirmedSnapshotJSON, resolvedPerformMode]);
1396
+ }, [patch, initialValues, initialActive, lastConfirmedSnapshotJSON, resolvedPerformMode]);
1404
1397
  React9.useEffect(() => {
1405
1398
  if (clearTick > 0) performAction();
1406
1399
  }, [clearTick]);
@@ -2359,6 +2352,97 @@ function matchLeaf(value, condition) {
2359
2352
  return true;
2360
2353
  }
2361
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
+
2362
2446
  // export/sources.ts
2363
2447
  var sources = /* @__PURE__ */ new Map();
2364
2448
  var registerExportSource = (fullId, source) => {
@@ -2424,6 +2508,7 @@ function EasyVisionTable(props) {
2424
2508
  data,
2425
2509
  fetchData: fetchDataProp,
2426
2510
  loopback,
2511
+ ingot,
2427
2512
  onDataLoaded,
2428
2513
  multifilter,
2429
2514
  multifilterRef,
@@ -2462,9 +2547,19 @@ function EasyVisionTable(props) {
2462
2547
  // eslint-disable-next-line react-hooks/exhaustive-deps
2463
2548
  [lbFetchPage, lbFetchCount, lbIncludeKey, lbFieldsKey, lbOrderKey]
2464
2549
  );
2465
- const fetchData = fetchDataProp ?? loopbackFetcher;
2466
- const paginationMode = loopback ? "api" : paginationModeProp;
2467
- const orderingMode = loopback ? "api" : orderingModeProp;
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;
2468
2563
  const getRowId = React9.useMemo(
2469
2564
  () => getRowIdProp ?? ((row) => String(row?.id ?? "")),
2470
2565
  [getRowIdProp]
@@ -3328,6 +3423,7 @@ exports.EasyVisionMultifilter = EasyVisionMultifilter;
3328
3423
  exports.EasyVisionSelector = EasyVisionSelector;
3329
3424
  exports.EasyVisionTable = EasyVisionTable;
3330
3425
  exports.buildWorkbook = buildWorkbook;
3426
+ exports.createIngotTableFetcher = createIngotTableFetcher;
3331
3427
  exports.createLoopbackTableFetcher = createLoopbackTableFetcher;
3332
3428
  exports.defaultCell = defaultCell;
3333
3429
  exports.downloadBlob = downloadBlob;
@@ -3337,5 +3433,6 @@ exports.getSlice = getSlice;
3337
3433
  exports.matchLoopbackWhere = matchLoopbackWhere;
3338
3434
  exports.sanitizeSheetName = sanitizeSheetName;
3339
3435
  exports.toExportColumns = toExportColumns;
3436
+ exports.toIngotWhere = toIngotWhere;
3340
3437
  //# sourceMappingURL=index.cjs.map
3341
3438
  //# sourceMappingURL=index.cjs.map