@xh/hoist 80.0.0-SNAPSHOT.1769000829579 → 80.0.0-SNAPSHOT.1769042130982

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.
@@ -32,14 +32,14 @@ export const colChooser = hoistCmp.factory<ColChooserProps>({
32
32
  className: 'xh-col-chooser',
33
33
 
34
34
  render({model, className}) {
35
- const {commitOnChange, showRestoreDefaults, width, height} = model;
35
+ const {commitOnChange, showRestoreDefaults, width, height, filterMatchMode} = model;
36
36
 
37
37
  return panel({
38
38
  className,
39
39
  items: [
40
40
  leftRightChooser({width, height}),
41
41
  toolbar(
42
- leftRightChooserFilter(),
42
+ leftRightChooserFilter({matchMode: filterMatchMode}),
43
43
  filler(),
44
44
  button({
45
45
  omit: !showRestoreDefaults,
@@ -4,8 +4,9 @@
4
4
  *
5
5
  * Copyright © 2026 Extremely Heavy Industries Inc.
6
6
  */
7
- import {GridModel} from '@xh/hoist/cmp/grid';
7
+ import {ColChooserConfig, GridModel} from '@xh/hoist/cmp/grid';
8
8
  import {HoistModel, managed} from '@xh/hoist/core';
9
+ import type {FilterMatchMode} from '@xh/hoist/data';
9
10
  import {LeftRightChooserModel} from '@xh/hoist/desktop/cmp/leftrightchooser';
10
11
  import {action, makeObservable, observable} from '@xh/hoist/mobx';
11
12
  import {sortBy} from 'lodash';
@@ -29,8 +30,9 @@ export class ColChooserModel extends HoistModel {
29
30
  commitOnChange: boolean;
30
31
  showRestoreDefaults: boolean;
31
32
  autosizeOnCommit: boolean;
32
- width: number;
33
- height: number;
33
+ width: string | number;
34
+ height: string | number;
35
+ filterMatchMode: FilterMatchMode;
34
36
 
35
37
  constructor({
36
38
  gridModel,
@@ -38,8 +40,9 @@ export class ColChooserModel extends HoistModel {
38
40
  showRestoreDefaults = true,
39
41
  autosizeOnCommit = false,
40
42
  width = !commitOnChange && showRestoreDefaults ? 600 : 520,
41
- height = 300
42
- }) {
43
+ height = 300,
44
+ filterMatchMode = 'startWord'
45
+ }: ColChooserConfig) {
43
46
  super();
44
47
  makeObservable(this);
45
48
 
@@ -49,6 +52,7 @@ export class ColChooserModel extends HoistModel {
49
52
  this.autosizeOnCommit = autosizeOnCommit;
50
53
  this.width = width;
51
54
  this.height = height;
55
+ this.filterMatchMode = filterMatchMode;
52
56
 
53
57
  this.lrModel = new LeftRightChooserModel({
54
58
  leftTitle: 'Available Columns',
@@ -4,7 +4,8 @@
4
4
  *
5
5
  * Copyright © 2026 Extremely Heavy Industries Inc.
6
6
  */
7
- import {hoistCmp, HoistModel, HoistProps, lookup, useLocalModel, uses} from '@xh/hoist/core';
7
+ import {hoistCmp, HoistModel, HoistProps, lookup, useLocalModel, uses, XH} from '@xh/hoist/core';
8
+ import type {FilterMatchMode} from '@xh/hoist/data';
8
9
  import {textInput} from '@xh/hoist/desktop/cmp/input';
9
10
  import '@xh/hoist/desktop/register';
10
11
  import {Icon} from '@xh/hoist/icon';
@@ -16,8 +17,8 @@ export interface LeftRightChooserFilterProps extends HoistProps<LeftRightChooser
16
17
  /** Names of fields in chooser on which to filter. Defaults to ['text', 'group'] */
17
18
  fields?: string[];
18
19
 
19
- /** True to prevent regex start line anchor from being added. */
20
- anyMatch?: boolean;
20
+ /** Mode to use when filtering (default 'startWord'). */
21
+ matchMode?: FilterMatchMode;
21
22
  }
22
23
 
23
24
  /**
@@ -51,34 +52,48 @@ class LeftRightChooserFilterLocalModel extends HoistModel {
51
52
  @bindable
52
53
  value = null;
53
54
 
55
+ get matchMode(): FilterMatchMode {
56
+ return this.componentProps.matchMode ?? 'startWord';
57
+ }
58
+
54
59
  constructor() {
55
60
  super();
56
61
  makeObservable(this);
57
62
  this.addReaction({
58
- track: () => this.value,
63
+ track: () => [this.value, this.matchMode],
59
64
  run: () => this.runFilter()
60
65
  });
61
66
  }
62
67
 
63
68
  private runFilter() {
64
- const {fields = ['text', 'group'], anyMatch = false} = this.componentProps;
65
- let searchTerm = escapeRegExp(this.value);
66
-
67
- if (!anyMatch) {
68
- searchTerm = `(^|\\W)${searchTerm}`;
69
- }
69
+ const {fields = ['text', 'group']} = this.componentProps,
70
+ searchTerm = this.value,
71
+ regex = this.getRegex(searchTerm);
70
72
 
71
73
  const filter = raw => {
72
74
  return fields.some(f => {
73
75
  if (!searchTerm) return true;
74
76
  const fieldVal = raw.data[f];
75
- return fieldVal && new RegExp(searchTerm, 'ig').test(fieldVal);
77
+ return fieldVal && regex.test(fieldVal);
76
78
  });
77
79
  };
78
80
 
79
81
  this.model.setDisplayFilter(filter);
80
82
  }
81
83
 
84
+ private getRegex(searchTerm: string): RegExp {
85
+ searchTerm = escapeRegExp(searchTerm);
86
+ switch (this.matchMode) {
87
+ case 'any':
88
+ return new RegExp(searchTerm, 'i');
89
+ case 'start':
90
+ return new RegExp(`^${searchTerm}`, 'i');
91
+ case 'startWord':
92
+ return new RegExp(`(^|\\W)${searchTerm}`, 'i');
93
+ }
94
+ throw XH.exception('Unknown matchMode in StoreFilterField');
95
+ }
96
+
82
97
  override destroy() {
83
98
  // This unusual bit of code is extremely important -- the model we are linking to might
84
99
  // survive the display of this component and should be restored. (This happens with GridColumnChooser)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "80.0.0-SNAPSHOT.1769000829579",
3
+ "version": "80.0.0-SNAPSHOT.1769042130982",
4
4
  "description": "Hoist add-on for building and deploying React Applications.",
5
5
  "repository": "github:xh/hoist-react",
6
6
  "homepage": "https://xh.io",