@easyvision/easyvision-ui 1.9.0 → 1.9.1

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
@@ -652,13 +652,13 @@ interface MultifilterSnapshot {
652
652
  ```
653
653
 
654
654
  The default `query.where` builder uses these conventions per type:
655
- - `text` → `{ [field]: { $regex: `.*${value}.*`, $options: 'i' } }`
655
+ - `text` → `{ [field]: { $regex: `.*${value}.*`, $options: 'i' } }` (regex metacharacters in `value` are escaped, so the text matches literally)
656
656
  - `selector` → `{ [field]: value }`
657
657
  - `multiselect` → `{ [field]: { $in: value } }`
658
658
  - `dateRange` → `{ [field]: { $gte, $lte } }` (ISO strings)
659
659
  - `numberRange` → `{ [field]: { $gte, $lte } }`
660
660
 
661
- Override per field with `toCondition: (value) => unknown` (return either a primitive — wrapped in `{ [field]: ... }` — or a full clause containing `$or`/`$and`, which is merged at the top level of `where`). Useful for searching multiple paths with one input, or for translating UI values into a backend-specific shape.
661
+ To search several paths with one input, give a `text` field `fields` instead of `field`. It builds one `$or` with the same escaped, case-insensitive match on each path:
662
662
 
663
663
  ```ts
664
664
  // Search bar that matches client.name OR title OR topics:
@@ -667,19 +667,12 @@ Override per field with `toCondition: (value) => unknown` (return either a primi
667
667
  type: 'text',
668
668
  prominent: true,
669
669
  pinned: true,
670
- toCondition: (v) => {
671
- const s = String(v ?? '').trim();
672
- if (!s) return undefined;
673
- const like = { $regex: `.*${s}.*`, $options: 'i' };
674
- return { $or: [
675
- { 'client.name': like },
676
- { title: like },
677
- { relatedTopicsText: like },
678
- ]};
679
- },
670
+ fields: ['client.name', 'title', 'relatedTopicsText'],
680
671
  }
681
672
  ```
682
673
 
674
+ Override per field with `toCondition: (value) => unknown` (return either a primitive — wrapped in `{ [field]: ... }` — or a full clause containing `$or`/`$and`, which is merged at the top level of `where`). Useful for translating UI values into a backend-specific shape. A `toCondition` replaces the default builder entirely, so if it builds a `$regex` from user text it must escape that text itself.
675
+
683
676
  > `transform` is the deprecated old name for `toCondition` and is still accepted as an alias.
684
677
 
685
678
  ### Multifilter props
package/dist/index.cjs CHANGED
@@ -1019,6 +1019,20 @@ function MultifilterField({
1019
1019
  return null;
1020
1020
  }
1021
1021
  }
1022
+
1023
+ // lib/escapeRegex.ts
1024
+ function escapeRegex(value) {
1025
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
1026
+ }
1027
+
1028
+ // multifilter/hooks/useMultifilterQuery.ts
1029
+ function textCondition(def, value) {
1030
+ const str = String(value).trim();
1031
+ if (!str) return void 0;
1032
+ const like = { $regex: `.*${escapeRegex(str)}.*`, $options: "i" };
1033
+ if (def.fields?.length) return { $or: def.fields.map((f) => ({ [f]: like })) };
1034
+ return def.field ? { [def.field]: like } : void 0;
1035
+ }
1022
1036
  function buildCondition(def, value) {
1023
1037
  if (value === void 0 || value === null || value === "") return void 0;
1024
1038
  const mapper = def.toCondition ?? def.transform;
@@ -1031,13 +1045,9 @@ function buildCondition(def, value) {
1031
1045
  if (def.field) return { [def.field]: mapped };
1032
1046
  return void 0;
1033
1047
  }
1048
+ if (def.type === "text") return textCondition(def, value);
1034
1049
  if (!def.field) return void 0;
1035
1050
  switch (def.type) {
1036
- case "text": {
1037
- const str = String(value).trim();
1038
- if (!str) return void 0;
1039
- return { [def.field]: { $regex: `.*${str}.*`, $options: "i" } };
1040
- }
1041
1051
  case "selector": {
1042
1052
  return { [def.field]: value };
1043
1053
  }
@@ -1377,6 +1387,7 @@ var EasyVisionMultifilter = React9.forwardRef(function EasyVisionMultifilter2(pr
1377
1387
  },
1378
1388
  [activeFields, values, patch]
1379
1389
  );
1390
+ const [clearTick, setClearTick] = React9.useState(0);
1380
1391
  const clearAll = React9.useCallback(() => {
1381
1392
  const seed = {};
1382
1393
  if (config.searchField?.defaultValue !== void 0) {
@@ -1390,7 +1401,13 @@ var EasyVisionMultifilter = React9.forwardRef(function EasyVisionMultifilter2(pr
1390
1401
  }).concat(config.searchField ? [config.searchField.id] : []),
1391
1402
  lastConfirmedSnapshotJSON: null
1392
1403
  });
1393
- }, [config, patch, initialActive]);
1404
+ if (lastConfirmedSnapshotJSON !== null && resolvedPerformMode !== "live") {
1405
+ setClearTick((n) => n + 1);
1406
+ }
1407
+ }, [config, patch, initialActive, lastConfirmedSnapshotJSON, resolvedPerformMode]);
1408
+ React9.useEffect(() => {
1409
+ if (clearTick > 0) performAction();
1410
+ }, [clearTick]);
1394
1411
  const visibleConfigFields = React9.useMemo(
1395
1412
  () => config.fields.filter((f) => isFieldVisible(f, composedValues)),
1396
1413
  [config.fields, composedValues]
@@ -1586,13 +1603,12 @@ function buildChildQueryDirect(field, values) {
1586
1603
  if (def.type === "multifilter") continue;
1587
1604
  const v = values[def.id];
1588
1605
  if (v === void 0 || v === null || v === "") continue;
1606
+ if (def.type === "text") {
1607
+ Object.assign(where, textCondition(def, v));
1608
+ continue;
1609
+ }
1589
1610
  if (!def.field) continue;
1590
1611
  switch (def.type) {
1591
- case "text": {
1592
- const str = String(v).trim();
1593
- if (str) where[def.field] = { $regex: `.*${str}.*`, $options: "i" };
1594
- break;
1595
- }
1596
1612
  case "selector":
1597
1613
  where[def.field] = v;
1598
1614
  break;
@@ -1625,9 +1641,7 @@ function buildChildQueryDirect(field, values) {
1625
1641
  }
1626
1642
  if (field.config.searchField) {
1627
1643
  const sv = values[field.config.searchField.id];
1628
- if (typeof sv === "string" && sv.trim() && field.config.searchField.field) {
1629
- where[field.config.searchField.field] = { $regex: `.*${sv.trim()}.*`, $options: "i" };
1630
- }
1644
+ if (typeof sv === "string") Object.assign(where, textCondition(field.config.searchField, sv));
1631
1645
  }
1632
1646
  return Object.keys(where).length > 0 ? { where } : {};
1633
1647
  }