@acorex/components 22.2.3 → 22.2.5

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.
@@ -183,7 +183,7 @@ async function loadTreeTableRows(source, options, query, isCallback) {
183
183
  : await loadRoots(source, isCallback);
184
184
  const roots = mapTreeNodes(rootNodes, options);
185
185
  const items = textFilter
186
- ? prepareFilteredTreeTableRows(filterTreeNodes(roots, options.textField, String(textFilter.value ?? '')))
186
+ ? prepareFilteredTreeTableRows(filterTreeNodes(roots, options.searchFields?.length ? options.searchFields : options.textField, String(textFilter.value ?? '')))
187
187
  : roots;
188
188
  return { items, total: items.length };
189
189
  }
@@ -221,16 +221,39 @@ function mapTreeNode(node, options) {
221
221
  * all children. Every kept ancestor is a new object with `expanded: true` so
222
222
  * nested hits are visible without mutating the original tree.
223
223
  */
224
+ /** Reads a possibly dotted field path off a node. */
225
+ function readNodeField(node, field) {
226
+ if (!field.includes('.')) {
227
+ return node[field];
228
+ }
229
+ return field.split('.').reduce((current, segment) => {
230
+ if (current == null || typeof current !== 'object') {
231
+ return undefined;
232
+ }
233
+ return current[segment];
234
+ }, node);
235
+ }
236
+ /** Whether any of `fields` on the node matches the query. */
237
+ function matchesLookupNode(node, fields, needle, translateText) {
238
+ return fields.some((field) => {
239
+ const value = readNodeField(node, field);
240
+ if (value == null) {
241
+ return false;
242
+ }
243
+ return matchesLookupText(String(value), needle, translateText);
244
+ });
245
+ }
224
246
  function filterTreeNodes(nodes, textField, query, translateText) {
225
247
  const needle = query.trim().toLowerCase();
226
248
  if (!needle) {
227
249
  return nodes;
228
250
  }
251
+ const fields = (Array.isArray(textField) ? textField : [textField]).filter((field) => !!field);
229
252
  const result = [];
230
253
  for (const node of nodes) {
231
254
  const rawChildren = node['children'];
232
255
  const nested = Array.isArray(rawChildren) ? rawChildren : undefined;
233
- const selfMatch = matchesLookupText(String(node[textField] ?? ''), needle, translateText);
256
+ const selfMatch = matchesLookupNode(node, fields, needle, translateText);
234
257
  if (selfMatch) {
235
258
  result.push({
236
259
  ...node,
@@ -238,7 +261,7 @@ function filterTreeNodes(nodes, textField, query, translateText) {
238
261
  });
239
262
  continue;
240
263
  }
241
- const children = nested ? filterTreeNodes(nested, textField, needle, translateText) : undefined;
264
+ const children = nested ? filterTreeNodes(nested, fields, needle, translateText) : undefined;
242
265
  if (children && children.length > 0) {
243
266
  result.push({
244
267
  ...node,