cx 23.9.1 → 23.11.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.
@@ -1,171 +1,174 @@
1
- import { Instance } from "./../../ui/Instance";
2
- import * as Cx from "../../core";
3
- import { FieldProps } from "./Field";
4
-
5
- export interface LookupBinding {
6
- local: string;
7
- remote: string;
8
- key?: boolean;
9
- }
10
-
11
- interface LookupFieldProps extends FieldProps {
12
- /** Defaults to `false`. Set to `true` to enable multiple selection. */
13
- multiple?: Cx.BooleanProp;
14
-
15
- /** Selected value. Used only if `multiple` is set to `false`. */
16
- value?: Cx.Prop<number | string>;
17
-
18
- /** A list of selected ids. Used only if `multiple` is set to `true`. */
19
- values?: Cx.Prop<any[]>;
20
-
21
- /** A list of selected records. Used only if `multiple` is set to `true`. */
22
- records?: Cx.RecordsProp;
23
-
24
- /** Text associated with the selection. Used only if `multiple` is set to `false`. */
25
- text?: Cx.StringProp;
26
-
27
- /** The opposite of `disabled`. */
28
- enabled?: Cx.BooleanProp;
29
-
30
- /** Default text displayed when the field is empty. */
31
- placeholder?: Cx.StringProp;
32
-
33
- /** A list of available options. */
34
- options?: Cx.RecordsProp;
35
-
36
- /**
37
- * Set to `true` to hide the clear button. It can be used interchangeably with the `showClear` property.
38
- * No effect if `multiple` is used. Default value is `false`.
39
- */
40
- hideClear?: boolean;
41
-
42
- /**
43
- * Set to `false` to hide the clear button. It can be used interchangeably with the `hideClear` property.
44
- * No effect if `multiple` is used. Default value is `true`.
45
- */
46
- showClear?: boolean;
47
-
48
- /**
49
- * Set to `true` to display the clear button even if `required` is set. Default is `false`.
50
- */
51
- alwaysShowClear?: boolean;
52
-
53
- /** Base CSS class to be applied to the field. Defaults to `lookupfield`. */
54
- baseClass?: string;
55
-
56
- /* TODO: Check type */
57
-
58
- /** Additional config to be applied to all items */
59
- itemsConfig?: any;
60
-
61
- /**
62
- * An array of objects describing the mapping of option data to store data.
63
- * Each entry must define `local`, `remote` bindings. `key: true` is used to indicate fields that are used in the primary key.
64
- */
65
- bindings?: LookupBinding[];
66
-
67
- /** A delay in milliseconds between the moment the user stops typing and when tha query is made. Default value is `150`. */
68
- queryDelay?: number;
69
-
70
- /** Minimal number of characters required before query is made. */
71
- minQueryLength?: number;
72
-
73
- /** Set to `true` to hide the search field. */
74
- hideSearchField?: boolean;
75
-
76
- /**
77
- * Number of options required to show the search field.
78
- * If there are only a few options, there is no need for search. Defaults to `7`.
79
- */
80
- minOptionsForSearchField?: number;
81
-
82
- /** Text to display while data is being loaded. */
83
- loadingText?: string;
84
-
85
- /** Error message displayed to the user if server query throws an exception. */
86
- queryErrorText?: string;
87
-
88
- /** Message to be displayed if no entries match the user query. */
89
- noResultsText?: string;
90
-
91
- /** Name of the field which holds the id of the option. Default value is `id`. */
92
- optionIdField?: string;
93
-
94
- /** Name of the field which holds the display text of the option. Default value is `text`. */
95
- optionTextField?: string;
96
-
97
- /**
98
- * Available only in `multiple` selection mode and without custom `bindings`.
99
- * Name of the field to store id of the selected value. Default value is `id`.
100
- */
101
- valueIdField?: string;
102
-
103
- /**
104
- * Available only in `multiple` selection mode.
105
- * Name of the field to store display text of the selected value. Default value is `text`.
106
- */
107
- valueTextField?: string;
108
-
109
- /**
110
- * If `true` `onQuery` will be called only once to fetch all options.
111
- * After that options are filtered client-side.
112
- */
113
- fetchAll?: boolean;
114
-
115
- /**
116
- * If this flag is set along with `fetchAll`, fetched options are cached for the lifetime of the widget.
117
- * Otherwise, data is fetched whenever the dropdown is shown.
118
- */
119
- cacheAll?: boolean;
120
-
121
- /** Close the dropdown after selection. Default is `true`. */
122
- closeOnSelect?: boolean;
123
-
124
- /** Mesasge to be displayed to the user if the entered search query is too short. */
125
- minQueryLengthMessageText?: string;
126
-
127
- /** Name of the icon to be put on the left side of the input. */
128
- icon?: Cx.StringProp;
129
-
130
- /** Query function. */
131
- onQuery?: (
132
- query: string | { query: string; page: number; pageSize: number },
133
- instance: Instance
134
- ) => Cx.Record[] | Promise<Cx.Record>;
135
-
136
- /** Set to true to sort dropdown options. */
137
- sort?: boolean;
138
-
139
- /** Additional list options, such as grouping configuration, custom sorting, etc. */
140
- listOptions?: Cx.Config;
141
-
142
- /** Set to true to show the dropdown immediately after the component has mounted.
143
- * This is commonly used for cell editing in grids. */
144
- autoOpen?: Cx.BooleanProp;
145
-
146
- /** Set to true to allow enter key events to be propagated. This is useful for submitting forms or closing grid cell editors. */
147
- submitOnEnterKey?: Cx.BooleanProp;
148
-
149
- /** Set to true to allow dropdown enter key events to be propagated. This is useful for submitting forms on dropdown enter key selection. */
150
- submitOnDropdownEnterKey?: Cx.BooleanProp;
151
-
152
- /** Defaults to `false`. Used to make the field read-only. */
153
- readOnly?: Cx.BooleanProp;
154
-
155
- /** Set to `true` to enable loading of additional lookup options when the scroll is reaching the end. */
156
- infinite?: boolean;
157
-
158
- /** Number of additional items to be loaded in `infinite` mode. Default is 100. */
159
- pageSize?: number;
160
-
161
- /** Set to `true` to allow quick selection of all displayed lookup items on `ctrl + a` keys combination. */
162
- quickSelectAll?: boolean;
163
-
164
- /** Parameters that affect filtering. */
165
- filterParams?: Cx.StructuredProp;
166
-
167
- /** Callback to create a filter function for given filter params. */
168
- onCreateVisibleOptionsFilter?: (filterParams: any, instance?: Instance) => (record: Record) => boolean;
169
- }
170
-
171
- export class LookupField extends Cx.Widget<LookupFieldProps> {}
1
+ import { Instance } from "./../../ui/Instance";
2
+ import * as Cx from "../../core";
3
+ import { FieldProps } from "./Field";
4
+
5
+ export interface LookupBinding {
6
+ local: string;
7
+ remote: string;
8
+ key?: boolean;
9
+ }
10
+
11
+ interface LookupFieldProps extends FieldProps {
12
+ /** Defaults to `false`. Set to `true` to enable multiple selection. */
13
+ multiple?: Cx.BooleanProp;
14
+
15
+ /** Selected value. Used only if `multiple` is set to `false`. */
16
+ value?: Cx.Prop<number | string>;
17
+
18
+ /** A list of selected ids. Used only if `multiple` is set to `true`. */
19
+ values?: Cx.Prop<any[]>;
20
+
21
+ /** A list of selected records. Used only if `multiple` is set to `true`. */
22
+ records?: Cx.RecordsProp;
23
+
24
+ /** Text associated with the selection. Used only if `multiple` is set to `false`. */
25
+ text?: Cx.StringProp;
26
+
27
+ /** The opposite of `disabled`. */
28
+ enabled?: Cx.BooleanProp;
29
+
30
+ /** Default text displayed when the field is empty. */
31
+ placeholder?: Cx.StringProp;
32
+
33
+ /** A list of available options. */
34
+ options?: Cx.RecordsProp;
35
+
36
+ /**
37
+ * Set to `true` to hide the clear button. It can be used interchangeably with the `showClear` property.
38
+ * No effect if `multiple` is used. Default value is `false`.
39
+ */
40
+ hideClear?: boolean;
41
+
42
+ /**
43
+ * Set to `false` to hide the clear button. It can be used interchangeably with the `hideClear` property.
44
+ * No effect if `multiple` is used. Default value is `true`.
45
+ */
46
+ showClear?: boolean;
47
+
48
+ /**
49
+ * Set to `true` to display the clear button even if `required` is set. Default is `false`.
50
+ */
51
+ alwaysShowClear?: boolean;
52
+
53
+ /** Base CSS class to be applied to the field. Defaults to `lookupfield`. */
54
+ baseClass?: string;
55
+
56
+ /* TODO: Check type */
57
+
58
+ /** Additional config to be applied to all items */
59
+ itemsConfig?: any;
60
+
61
+ /**
62
+ * An array of objects describing the mapping of option data to store data.
63
+ * Each entry must define `local`, `remote` bindings. `key: true` is used to indicate fields that are used in the primary key.
64
+ */
65
+ bindings?: LookupBinding[];
66
+
67
+ /** A delay in milliseconds between the moment the user stops typing and when tha query is made. Default value is `150`. */
68
+ queryDelay?: number;
69
+
70
+ /** Minimal number of characters required before query is made. */
71
+ minQueryLength?: number;
72
+
73
+ /** Set to `true` to hide the search field. */
74
+ hideSearchField?: boolean;
75
+
76
+ /**
77
+ * Number of options required to show the search field.
78
+ * If there are only a few options, there is no need for search. Defaults to `7`.
79
+ */
80
+ minOptionsForSearchField?: number;
81
+
82
+ /** Text to display while data is being loaded. */
83
+ loadingText?: string;
84
+
85
+ /** Error message displayed to the user if server query throws an exception. */
86
+ queryErrorText?: string;
87
+
88
+ /** Message to be displayed if no entries match the user query. */
89
+ noResultsText?: string;
90
+
91
+ /** Name of the field which holds the id of the option. Default value is `id`. */
92
+ optionIdField?: string;
93
+
94
+ /** Name of the field which holds the display text of the option. Default value is `text`. */
95
+ optionTextField?: string;
96
+
97
+ /**
98
+ * Available only in `multiple` selection mode and without custom `bindings`.
99
+ * Name of the field to store id of the selected value. Default value is `id`.
100
+ */
101
+ valueIdField?: string;
102
+
103
+ /**
104
+ * Available only in `multiple` selection mode.
105
+ * Name of the field to store display text of the selected value. Default value is `text`.
106
+ */
107
+ valueTextField?: string;
108
+
109
+ /**
110
+ * If `true` `onQuery` will be called only once to fetch all options.
111
+ * After that options are filtered client-side.
112
+ */
113
+ fetchAll?: boolean;
114
+
115
+ /**
116
+ * If this flag is set along with `fetchAll`, fetched options are cached for the lifetime of the widget.
117
+ * Otherwise, data is fetched whenever the dropdown is shown.
118
+ */
119
+ cacheAll?: boolean;
120
+
121
+ /** Close the dropdown after selection. Default is `true`. */
122
+ closeOnSelect?: boolean;
123
+
124
+ /** Mesasge to be displayed to the user if the entered search query is too short. */
125
+ minQueryLengthMessageText?: string;
126
+
127
+ /** Name of the icon to be put on the left side of the input. */
128
+ icon?: Cx.StringProp;
129
+
130
+ /** Query function. */
131
+ onQuery?: (
132
+ query: string | { query: string; page: number; pageSize: number },
133
+ instance: Instance
134
+ ) => Cx.Record[] | Promise<Cx.Record>;
135
+
136
+ /** Set to true to sort dropdown options. */
137
+ sort?: boolean;
138
+
139
+ /** Additional list options, such as grouping configuration, custom sorting, etc. */
140
+ listOptions?: Cx.Config;
141
+
142
+ /** Set to true to show the dropdown immediately after the component has mounted.
143
+ * This is commonly used for cell editing in grids. */
144
+ autoOpen?: Cx.BooleanProp;
145
+
146
+ /** Set to true to allow enter key events to be propagated. This is useful for submitting forms or closing grid cell editors. */
147
+ submitOnEnterKey?: Cx.BooleanProp;
148
+
149
+ /** Set to true to allow dropdown enter key events to be propagated. This is useful for submitting forms on dropdown enter key selection. */
150
+ submitOnDropdownEnterKey?: Cx.BooleanProp;
151
+
152
+ /** Defaults to `false`. Used to make the field read-only. */
153
+ readOnly?: Cx.BooleanProp;
154
+
155
+ /** Set to `true` to enable loading of additional lookup options when the scroll is reaching the end. */
156
+ infinite?: boolean;
157
+
158
+ /** Number of additional items to be loaded in `infinite` mode. Default is 100. */
159
+ pageSize?: number;
160
+
161
+ /** Set to `true` to allow quick selection of all displayed lookup items on `ctrl + a` keys combination. */
162
+ quickSelectAll?: boolean;
163
+
164
+ /** Parameters that affect filtering. */
165
+ filterParams?: Cx.StructuredProp;
166
+
167
+ /** Callback to create a filter function for given filter params. */
168
+ onCreateVisibleOptionsFilter?: (filterParams: any, instance?: Instance) => (record: Record) => boolean;
169
+
170
+ /** Used in multiple selection lookups in combination with records, to construct the display text out of multiple fields or when additional formatting is needed. */
171
+ onGetRecordDisplayText?: (record: any, instance?: Instance) => string;
172
+ }
173
+
174
+ export class LookupField extends Cx.Widget<LookupFieldProps> {}
@@ -204,8 +204,11 @@ export class LookupField extends Field {
204
204
  if (!this.multiple) return super.formatValue(context, instance);
205
205
 
206
206
  let { records, values, options } = instance.data;
207
- if (isArray(records))
208
- return records.map((record) => record[this.valueTextField] || record[this.valueIdField]).join(", ");
207
+ if (isArray(records)) {
208
+ let valueTextFormatter =
209
+ this.onGetRecordDisplayText ?? ((record) => record[this.valueTextField] || record[this.valueIdField]);
210
+ return records.map((record) => valueTextFormatter(record, instance));
211
+ }
209
212
 
210
213
  if (isArray(values)) {
211
214
  if (isArray(options))
@@ -254,6 +257,7 @@ LookupField.prototype.submitOnDropdownEnterKey = false;
254
257
  LookupField.prototype.pageSize = 100;
255
258
  LookupField.prototype.infinite = false;
256
259
  LookupField.prototype.quickSelectAll = false;
260
+ LookupField.prototype.onGetRecordDisplayText = null;
257
261
 
258
262
  Localization.registerPrototype("cx/widgets/LookupField", LookupField);
259
263
 
@@ -586,6 +590,7 @@ class LookupComponent extends VDOM.Component {
586
590
  if (this.props.multiple) {
587
591
  let readOnly = data.disabled || data.readOnly;
588
592
  if (isNonEmptyArray(data.records)) {
593
+ let valueTextFormatter = this.onGetRecordDisplayText ?? ((record) => record[this.valueTextField]);
589
594
  text = data.records.map((v, i) => (
590
595
  <div
591
596
  key={i}
@@ -593,7 +598,7 @@ class LookupComponent extends VDOM.Component {
593
598
  readonly: readOnly,
594
599
  })}
595
600
  >
596
- <span className={CSS.element(baseClass, "tag-value")}>{v[widget.valueTextField]}</span>
601
+ <span className={CSS.element(baseClass, "tag-value")}>{valueTextFormatter(v, instance)}</span>
597
602
  {!readOnly && (
598
603
  <div
599
604
  className={CSS.element(baseClass, "tag-clear")}
@@ -1,34 +1,34 @@
1
- import * as Cx from "../../core";
2
- import { FieldProps } from "./Field";
3
-
4
- interface UploadButtonProps extends FieldProps {
5
- /** Text description. */
6
- text?: Cx.StringProp;
7
-
8
- url?: Cx.StringProp;
9
-
10
- /** Base CSS class to be applied to the element. Default is 'uploadbutton'. */
11
- baseClass?: string;
12
-
13
- /** Defaults to `false`. Set to `true` to enable multiple selection. */
14
- multiple?: boolean;
15
-
16
- method?: string;
17
- uploadInProgressText?: string;
18
-
19
- /** Defaults to `false`. Set to `true` to abort uploads if the button is destroyed (unmounted). */
20
- abortOnDestroy: boolean;
21
-
22
- /** Defines file types that are accepted for upload. */
23
- accept?: Cx.StringProp;
24
-
25
- /** Name of the icon to be put on the left side of the button. */
26
- icon?: Cx.StringProp;
27
-
28
- onUploadStarting?: ((xhr: XMLHttpRequest, instance: any, file: File, formData: FormData) => boolean) | string;
29
- onUploadComplete?: ((xhr: XMLHttpRequest, instance: any, file: File, formData: FormData) => void) | string;
30
- onUploadProgress?: ((event: ProgressEvent, instance: any, file: File, formData: FormData) => void) | string;
31
- onUploadError?: ((event: ProgressEvent, instance: any, file: File, formData: FormData) => void) | string;
32
- }
33
-
34
- export class UploadButton extends Cx.Widget<UploadButtonProps> {}
1
+ import * as Cx from "../../core";
2
+ import { FieldProps } from "./Field";
3
+
4
+ interface UploadButtonProps extends FieldProps {
5
+ /** Text description. */
6
+ text?: Cx.StringProp;
7
+
8
+ url?: Cx.StringProp;
9
+
10
+ /** Base CSS class to be applied to the element. Default is 'uploadbutton'. */
11
+ baseClass?: string;
12
+
13
+ /** Defaults to `false`. Set to `true` to enable multiple selection. */
14
+ multiple?: boolean;
15
+
16
+ method?: string;
17
+ uploadInProgressText?: string;
18
+
19
+ /** Defaults to `false`. Set to `true` to abort uploads if the button is destroyed (unmounted). */
20
+ abortOnDestroy?: boolean;
21
+
22
+ /** Defines file types that are accepted for upload. */
23
+ accept?: Cx.StringProp;
24
+
25
+ /** Name of the icon to be put on the left side of the button. */
26
+ icon?: Cx.StringProp;
27
+
28
+ onUploadStarting?: ((xhr: XMLHttpRequest, instance: any, file: File, formData: FormData) => boolean) | string;
29
+ onUploadComplete?: ((xhr: XMLHttpRequest, instance: any, file: File, formData: FormData) => void) | string;
30
+ onUploadProgress?: ((event: ProgressEvent, instance: any, file: File, formData: FormData) => void) | string;
31
+ onUploadError?: ((event: ProgressEvent, instance: any, file: File, formData: FormData) => void) | string;
32
+ }
33
+
34
+ export class UploadButton extends Cx.Widget<UploadButtonProps> {}
@@ -155,9 +155,9 @@ interface GridRowConfig {
155
155
  mod?: StringProp | Prop<string[]> | StructuredProp;
156
156
  }
157
157
 
158
- interface GridProps extends StyledContainerProps {
158
+ interface GridProps<T = unknown> extends StyledContainerProps {
159
159
  /** An array of records to be displayed in the grid. */
160
- records?: Prop<Record[]>;
160
+ records?: Prop<T[]>;
161
161
 
162
162
  /** Set to true to add a vertical scroll and a fixed header to the grid. */
163
163
  scrollable?: boolean;
@@ -298,7 +298,7 @@ interface GridProps extends StyledContainerProps {
298
298
  filterParams?: StructuredProp;
299
299
 
300
300
  /** Callback to create a filter function for given filter params. */
301
- onCreateFilter?: (filterParams: any, instance?: Instance) => (record: Record) => boolean;
301
+ onCreateFilter?: (filterParams: any, instance?: Instance) => (record: T) => boolean;
302
302
 
303
303
  /** Enable infinite scrolling */
304
304
  infinite?: boolean;
@@ -337,7 +337,7 @@ interface GridProps extends StyledContainerProps {
337
337
  onBeforeCellEdit?: string | ((change: GridCellBeforeEditInfo, record: DataAdapterRecord) => any);
338
338
 
339
339
  /** A callback function which is executed after a cell has been successfully edited. */
340
- onCellEdited?: string | ((change: GridCellEditInfo, record: DataAdapterRecord) => void);
340
+ onCellEdited?: string | ((change: GridCellEditInfo<T>, record: DataAdapterRecord) => void);
341
341
 
342
342
  /** A callback function which is executed after a column has been resized. */
343
343
  onColumnResize?: (data: { width: number; column: Record }, instance: Instance) => void;
@@ -349,7 +349,7 @@ interface GridProps extends StyledContainerProps {
349
349
  onCreateIsRecordSelectable?: (
350
350
  params: any,
351
351
  instance: Instance
352
- ) => (record: Record, options?: { range?: boolean; toggle?: boolean }) => boolean;
352
+ ) => (record: T, options?: { range?: boolean; toggle?: boolean }) => boolean;
353
353
 
354
354
  /** Parameters whose change will cause scroll to be reset. */
355
355
  scrollResetParams?: StructuredProp;
@@ -380,10 +380,10 @@ interface GridProps extends StyledContainerProps {
380
380
  * Accepts new records as a first argument.
381
381
  * If onCreateFilter callback is defined, filtered records can be retrieved using this callback.
382
382
  */
383
- onTrackMappedRecords?: string | ((records: Record[], instance: Instance) => void);
383
+ onTrackMappedRecords?: string | ((records: T[], instance: Instance) => void);
384
384
 
385
385
  /** Callback to create a function that can be used to check whether a record is draggable. */
386
- onCreateIsRecordDraggable?: (params: any, instance: Instance) => (record: Record) => boolean;
386
+ onCreateIsRecordDraggable?: (params: any, instance: Instance) => (record: T) => boolean;
387
387
  }
388
388
 
389
389
  interface GridCellInfo {
@@ -395,9 +395,9 @@ interface GridCellBeforeEditInfo extends GridCellInfo {
395
395
  data: any;
396
396
  }
397
397
 
398
- interface GridCellEditInfo extends GridCellInfo {
399
- oldData: any;
400
- newData: any;
398
+ interface GridCellEditInfo<T> extends GridCellInfo {
399
+ oldData: T;
400
+ newData: T;
401
401
  }
402
402
 
403
- export class Grid extends Widget<GridProps> {}
403
+ export class Grid<T = unknown> extends Widget<GridProps<T>> {}
@@ -0,0 +1,17 @@
1
+ import { VDOM } from "../../ui/Widget";
2
+ import { registerIcon } from "./registry";
3
+
4
+ export default registerIcon(
5
+ "pixel-picker",
6
+ (props) => {
7
+ return (
8
+ <svg {...props} viewBox="0 0 30 30">
9
+ <path
10
+ d="M27.7,3.3c-1.5-1.5-3.9-1.5-5.4,0L17,8.6l-1.3-1.3c-0.4-0.4-1-0.4-1.4,0s-0.4,1,0,1.4l1.3,1.3L5,20.6 c-0.6,0.6-1,1.4-1.1,2.3C3.3,23.4,3,24.2,3,25c0,1.7,1.3,3,3,3c0.8,0,1.6-0.3,2.2-0.9C9,27,9.8,26.6,10.4,26L21,15.4l1.3,1.3 c0.2,0.2,0.5,0.3,0.7,0.3s0.5-0.1,0.7-0.3c0.4-0.4,0.4-1,0-1.4L22.4,14l5.3-5.3C29.2,7.2,29.2,4.8,27.7,3.3z M9,24.6 c-0.4,0.4-0.8,0.6-1.3,0.5c-0.4,0-0.7,0.2-0.9,0.5C6.7,25.8,6.3,26,6,26c-0.6,0-1-0.4-1-1c0-0.3,0.2-0.7,0.5-0.8 c0.3-0.2,0.5-0.5,0.5-0.9c0-0.5,0.2-1,0.5-1.3L17,11.4l2.6,2.6L9,24.6z"
11
+ fill="currentColor"
12
+ />
13
+ </svg>
14
+ );
15
+ },
16
+ true
17
+ );
@@ -1,7 +1,7 @@
1
1
  import * as Cx from '../../core';
2
2
  import { DropdownProps } from './Dropdown';
3
3
 
4
- interface TooltipProps extends DropdownProps {
4
+ export interface TooltipProps extends DropdownProps {
5
5
 
6
6
  /** Text to be displayed inside the tooltip. */
7
7
  text?: Cx.StringProp,