@xh/hoist 80.0.0-SNAPSHOT.1768517142984 → 80.0.0-SNAPSHOT.1768600489622

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,7 +1,7 @@
1
1
  import { AgGridModel } from '@xh/hoist/cmp/ag-grid';
2
2
  import { Column, ColumnGroup, ColumnOrGroup, ColumnOrGroupSpec, ColumnSpec, GridAutosizeMode, GridFilterModelConfig, GridGroupSortFn, TreeStyle } from '@xh/hoist/cmp/grid';
3
3
  import { GridFilterModel } from '@xh/hoist/cmp/grid/filter/GridFilterModel';
4
- import { Awaitable, HoistModel, HSide, PlainObject, SizingMode, Some, TaskObserver, Thunkable, VSide } from '@xh/hoist/core';
4
+ import { Awaitable, HoistModel, HSide, LoadSpec, PlainObject, SizingMode, Some, TaskObserver, Thunkable, VSide } from '@xh/hoist/core';
5
5
  import { Store, StoreConfig, StoreRecord, StoreRecordId, StoreRecordOrId, StoreSelectionConfig, StoreSelectionModel, StoreTransaction } from '@xh/hoist/data';
6
6
  import { AgColumnState, CellClickedEvent, CellContextMenuEvent, CellDoubleClickedEvent, CellEditingStartedEvent, CellEditingStoppedEvent, RowClickedEvent, RowDoubleClickedEvent } from '@xh/hoist/kit/ag-grid';
7
7
  import { ExportOptions } from '@xh/hoist/svc/GridExportService';
@@ -471,7 +471,7 @@ export declare class GridModel extends HoistModel {
471
471
  * This method is a no-op if provided any sorters without a corresponding column.
472
472
  */
473
473
  setSortBy(sorters: Some<GridSorterLike>): void;
474
- doLoadAsync(loadSpec: any): Promise<any>;
474
+ doLoadAsync(loadSpec: LoadSpec): Promise<any>;
475
475
  /** Load the underlying store. */
476
476
  loadData(rawData: any[], rawSummaryData?: Some<PlainObject>): void;
477
477
  /** Update the underlying store. */
@@ -601,8 +601,6 @@ export declare class GridModel extends HoistModel {
601
601
  private collectIds;
602
602
  private formatValuesForExport;
603
603
  private parseAndSetColumnsAndStore;
604
- private validateStoreConfig;
605
- private validateColConfigs;
606
604
  private validateColumns;
607
605
  private cleanColumnState;
608
606
  private enhanceColConfigsFromStore;
@@ -76,7 +76,12 @@ export interface GridFilterModelConfig {
76
76
  /** Default properties to be assigned to all fieldSpecs created by this model. */
77
77
  fieldSpecDefaults?: Omit<GridFilterFieldSpecConfig, 'field'>;
78
78
  }
79
- export type GridFilterBindTarget = FilterBindTarget & FilterValueSource;
79
+ /**
80
+ * {@link GridFilterModel} currently accepts a single `bind` target that also provides available
81
+ * values. Note that both `Store` and `View` satisfy this intersection.
82
+ */
83
+ export interface GridFilterBindTarget extends FilterBindTarget, FilterValueSource {
84
+ }
80
85
  /**
81
86
  * Renderer for a group row
82
87
  * @param context - The group renderer params from ag-Grid
@@ -80,3 +80,5 @@ export type FieldType = (typeof FieldType)[keyof typeof FieldType];
80
80
  * @returns fieldName transformed into user-facing / longer name for display.
81
81
  */
82
82
  export declare function genDisplayName(fieldName: string): string;
83
+ /** Convenience function to return the name of a field from one of several common inputs. */
84
+ export declare function getFieldName(field: string | Field | FieldSpec): string;
@@ -25,6 +25,7 @@ import {
25
25
  Awaitable,
26
26
  HoistModel,
27
27
  HSide,
28
+ LoadSpec,
28
29
  managed,
29
30
  PlainObject,
30
31
  SizingMode,
@@ -37,6 +38,7 @@ import {
37
38
  import {
38
39
  Field,
39
40
  FieldSpec,
41
+ getFieldName,
40
42
  Store,
41
43
  StoreConfig,
42
44
  StoreRecord,
@@ -91,7 +93,6 @@ import {
91
93
  isEmpty,
92
94
  isFunction,
93
95
  isNil,
94
- isPlainObject,
95
96
  isString,
96
97
  isUndefined,
97
98
  keysIn,
@@ -1150,7 +1151,7 @@ export class GridModel extends HoistModel {
1150
1151
  this.sortBy = newSorters;
1151
1152
  }
1152
1153
 
1153
- override async doLoadAsync(loadSpec) {
1154
+ override async doLoadAsync(loadSpec: LoadSpec) {
1154
1155
  // Delegate to any store that has load support
1155
1156
  return (this.store as any).loadSupport?.loadAsync(loadSpec);
1156
1157
  }
@@ -1172,7 +1173,6 @@ export class GridModel extends HoistModel {
1172
1173
 
1173
1174
  @action
1174
1175
  setColumns(colConfigs: ColumnOrGroupSpec[]) {
1175
- this.validateColConfigs(colConfigs);
1176
1176
  colConfigs = this.enhanceColConfigsFromStore(colConfigs);
1177
1177
 
1178
1178
  const columns = compact(colConfigs.map(c => this.buildColumn(c)));
@@ -1614,9 +1614,7 @@ export class GridModel extends HoistModel {
1614
1614
  if (this.isGroupSpec(config)) {
1615
1615
  if (config.borders !== false) borderedGroup = config;
1616
1616
  const children = compact(config.children.map(c => this.buildColumn(c, borderedGroup)));
1617
- return !isEmpty(children)
1618
- ? new ColumnGroup(config as ColumnGroupSpec, this, children)
1619
- : null;
1617
+ return !isEmpty(children) ? new ColumnGroup(config, this, children) : null;
1620
1618
  }
1621
1619
 
1622
1620
  if (borderedGroup) {
@@ -1694,45 +1692,26 @@ export class GridModel extends HoistModel {
1694
1692
  // in this case GridModel should work out the required Store fields from column definitions.
1695
1693
  private parseAndSetColumnsAndStore(
1696
1694
  colConfigs: ColumnOrGroupSpec[],
1697
- store: Store | StoreConfig = {}
1695
+ storeOrConfig: Store | StoreConfig = {}
1698
1696
  ) {
1699
- // 1) Validate configs.
1700
- this.validateStoreConfig(store);
1701
- this.validateColConfigs(colConfigs);
1697
+ // Enhance colConfigs with field-level metadata provided by store, if any.
1698
+ colConfigs = this.enhanceColConfigsFromStore(colConfigs, storeOrConfig);
1702
1699
 
1703
- // 2) Enhance colConfigs with field-level metadata provided by store, if any.
1704
- colConfigs = this.enhanceColConfigsFromStore(colConfigs, store);
1705
-
1706
- // 3) Create and set columns with (possibly) enhanced configs.
1700
+ // Create and set columns with (possibly) enhanced configs.
1707
1701
  this.setColumns(colConfigs);
1708
1702
 
1709
- let newStore: Store;
1710
- // 4) Create store if needed
1711
- if (isPlainObject(store)) {
1712
- store = this.enhanceStoreConfigFromColumns(store);
1713
- newStore = new Store({loadTreeData: this.treeMode, ...store});
1714
- newStore.xhImpl = this.xhImpl;
1715
- this.markManaged(newStore);
1703
+ // Set or create Store as needed.
1704
+ let store: Store;
1705
+ if (storeOrConfig instanceof Store) {
1706
+ store = storeOrConfig;
1716
1707
  } else {
1717
- newStore = store as Store;
1708
+ storeOrConfig = this.enhanceStoreConfigFromColumns(storeOrConfig);
1709
+ store = new Store({loadTreeData: this.treeMode, ...storeOrConfig});
1710
+ store.xhImpl = this.xhImpl;
1711
+ this.markManaged(store);
1718
1712
  }
1719
1713
 
1720
- this.store = newStore;
1721
- }
1722
-
1723
- private validateStoreConfig(store: Store | StoreConfig) {
1724
- throwIf(
1725
- !(store instanceof Store || isPlainObject(store)),
1726
- 'GridModel.store config must be either an instance of a Store or a config to create one.'
1727
- );
1728
- }
1729
-
1730
- private validateColConfigs(colConfigs: ColumnOrGroupSpec[]) {
1731
- throwIf(!isArray(colConfigs), 'GridModel.columns config must be an array.');
1732
- throwIf(
1733
- colConfigs.some(c => !isPlainObject(c)),
1734
- 'GridModel.columns config only accepts plain objects for Column or ColumnGroup configs.'
1735
- );
1714
+ this.store = store;
1736
1715
  }
1737
1716
 
1738
1717
  private validateColumns(cols: ColumnOrGroup[]) {
@@ -1833,7 +1812,7 @@ export class GridModel extends HoistModel {
1833
1812
  };
1834
1813
  }
1835
1814
 
1836
- const colFieldName = isString(col.field) ? col.field : col.field?.name,
1815
+ const colFieldName = getFieldName(col.field),
1837
1816
  field = fieldsByName[colFieldName];
1838
1817
 
1839
1818
  if (!field) return col;
@@ -1863,7 +1842,7 @@ export class GridModel extends HoistModel {
1863
1842
  // config object, not an instance.
1864
1843
  private enhanceStoreConfigFromColumns(storeConfig: StoreConfig) {
1865
1844
  const fields = storeConfig.fields ?? [],
1866
- storeFieldNames = fields.map(it => (isString(it) ? it : it.name)),
1845
+ storeFieldNames = fields.map(it => getFieldName(it)),
1867
1846
  leafColsByFieldName = this.leafColsByFieldName();
1868
1847
 
1869
1848
  const newFields: FieldSpec[] = [];
package/cmp/grid/Types.ts CHANGED
@@ -110,7 +110,11 @@ export interface GridFilterModelConfig {
110
110
  fieldSpecDefaults?: Omit<GridFilterFieldSpecConfig, 'field'>;
111
111
  }
112
112
 
113
- export type GridFilterBindTarget = FilterBindTarget & FilterValueSource;
113
+ /**
114
+ * {@link GridFilterModel} currently accepts a single `bind` target that also provides available
115
+ * values. Note that both `Store` and `View` satisfy this intersection.
116
+ */
117
+ export interface GridFilterBindTarget extends FilterBindTarget, FilterValueSource {}
114
118
 
115
119
  /**
116
120
  * Renderer for a group row
@@ -149,7 +153,7 @@ export type ColumnOrGroup = Column | ColumnGroup;
149
153
  export type ColumnOrGroupSpec = ColumnSpec | ColumnGroupSpec;
150
154
 
151
155
  export function isColumnSpec(spec: ColumnOrGroupSpec): spec is ColumnSpec {
152
- return !(spec as ColumnGroupSpec).children;
156
+ return !('children' in spec);
153
157
  }
154
158
 
155
159
  /**
package/data/Field.ts CHANGED
@@ -181,3 +181,8 @@ export function genDisplayName(fieldName: string): string {
181
181
  // Handle common cases of "id" -> "ID" and "foo_id" -> "Foo ID" (vs "Foo Id")
182
182
  return startCase(fieldName).replace(/(^| )Id\b/g, '$1ID');
183
183
  }
184
+
185
+ /** Convenience function to return the name of a field from one of several common inputs. */
186
+ export function getFieldName(field: string | Field | FieldSpec): string {
187
+ return field ? (isString(field) ? field : field.name) : null;
188
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xh/hoist",
3
- "version": "80.0.0-SNAPSHOT.1768517142984",
3
+ "version": "80.0.0-SNAPSHOT.1768600489622",
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",