@xh/hoist 59.3.1 → 59.4.0

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.
Files changed (54) hide show
  1. package/CHANGELOG.md +30 -2
  2. package/admin/differ/DifferModel.ts +5 -7
  3. package/appcontainer/AppContainerModel.ts +8 -10
  4. package/appcontainer/AppStateModel.ts +3 -2
  5. package/appcontainer/PageStateModel.ts +1 -2
  6. package/appcontainer/SizingModeModel.ts +2 -2
  7. package/cmp/ag-grid/AgGrid.ts +4 -3
  8. package/cmp/ag-grid/AgGridModel.ts +8 -9
  9. package/cmp/chart/Chart.ts +4 -3
  10. package/cmp/dataview/DataViewModel.ts +2 -2
  11. package/cmp/filter/FilterChooserModel.ts +5 -5
  12. package/cmp/grid/Grid.ts +2 -2
  13. package/cmp/grid/GridContextMenu.ts +2 -2
  14. package/cmp/grid/GridModel.ts +13 -21
  15. package/cmp/grid/Types.ts +6 -5
  16. package/cmp/grid/columns/Column.ts +12 -12
  17. package/cmp/grid/columns/ColumnGroup.ts +17 -6
  18. package/cmp/grid/helpers/GridCountLabel.ts +5 -4
  19. package/cmp/grid/impl/ColumnWidthCalculator.ts +3 -3
  20. package/cmp/grid/impl/GridPersistenceModel.ts +11 -4
  21. package/cmp/grid/renderers/MultiFieldRenderer.ts +28 -22
  22. package/cmp/grouping/GroupingChooserModel.ts +2 -2
  23. package/cmp/tab/TabContainerModel.ts +2 -2
  24. package/cmp/zoneGrid/ZoneGridModel.ts +52 -36
  25. package/cmp/zoneGrid/impl/ZoneGridPersistenceModel.ts +10 -4
  26. package/core/HoistBase.ts +44 -5
  27. package/core/XH.ts +3 -3
  28. package/core/elem.ts +2 -2
  29. package/core/impl/InstallServices.ts +2 -8
  30. package/core/load/LoadSupport.ts +3 -3
  31. package/core/model/HoistModel.ts +1 -1
  32. package/data/Store.ts +1 -1
  33. package/data/UrlStore.ts +3 -3
  34. package/data/filter/CompoundFilter.ts +5 -3
  35. package/data/filter/FieldFilter.ts +4 -3
  36. package/data/filter/Filter.ts +2 -3
  37. package/data/filter/FunctionFilter.ts +2 -1
  38. package/data/impl/RecordSet.ts +5 -5
  39. package/desktop/appcontainer/ToastSource.ts +1 -1
  40. package/desktop/cmp/rest/Actions.ts +15 -9
  41. package/desktop/cmp/treemap/TreeMap.ts +4 -8
  42. package/package.json +1 -1
  43. package/svc/AutoRefreshService.ts +3 -3
  44. package/svc/EnvironmentService.ts +1 -1
  45. package/svc/FetchService.ts +5 -5
  46. package/svc/GridAutosizeService.ts +4 -7
  47. package/svc/TrackService.ts +6 -6
  48. package/svc/WebSocketService.ts +14 -15
  49. package/utils/async/AsyncUtils.ts +3 -2
  50. package/utils/async/Timer.ts +32 -19
  51. package/utils/js/BrowserUtils.ts +8 -8
  52. package/utils/js/LangUtils.ts +10 -9
  53. package/utils/js/LogUtils.ts +66 -26
  54. package/utils/react/LayoutPropUtils.ts +3 -3
@@ -4,10 +4,14 @@
4
4
  *
5
5
  * Copyright © 2023 Extremely Heavy Industries Inc.
6
6
  */
7
+ import {Some} from '@xh/hoist/core';
7
8
  import {castArray, isString} from 'lodash';
9
+ import {intersperse} from './LangUtils';
10
+
11
+ export type LogSource = string | {displayName: string} | {constructor: {name: string}};
8
12
 
9
13
  /**
10
- * Track a function execution with console.log.
14
+ * Time and log execution of a function to `console.info()`.
11
15
  *
12
16
  * This method will log the provided message(s) with timing information in a single message *after*
13
17
  * the tracked function returns.
@@ -20,61 +24,78 @@ import {castArray, isString} from 'lodash';
20
24
  * @param fn - function to execute
21
25
  * @param source - class, function or string to label the source of the message
22
26
  */
23
- export function withInfo<T>(msgs: string[] | string, fn: () => T, source?: any): T {
27
+ export function withInfo<T>(msgs: Some<unknown>, fn: () => T, source?: LogSource): T {
24
28
  return loggedDo(msgs, fn, source, 'info');
25
29
  }
26
30
 
27
31
  /**
28
- * Track a function execution with console.debug.
32
+ * Time and log execution of a function to `console.debug()`.
29
33
  * @see withInfo
30
34
  */
31
- export function withDebug<T>(msgs: string[] | string, fn: () => T, source?: any): T {
35
+ export function withDebug<T>(msgs: Some<unknown>, fn: () => T, source?: LogSource): T {
32
36
  return loggedDo(msgs, fn, source, 'debug');
33
37
  }
34
38
 
35
39
  /**
36
- * Log a message with console.log.
37
- *
40
+ * Write to `console.log()` with standardized formatting and source info.
38
41
  * @param msgs - message(s) to output
39
42
  * @param source - class, function or string to label the source of the message
40
43
  */
41
- export function logInfo(msgs: string[] | string, source?: any) {
44
+ export function logInfo(msgs: Some<unknown>, source?: LogSource) {
42
45
  return loggedDo(msgs, null, source, 'info');
43
46
  }
44
47
 
45
48
  /**
46
- * Log a message with console.debug.
47
- * @see logInfo
49
+ * Write to `console.debug()` with standardized formatting and source info.
50
+ * @param msgs - message(s) to output
51
+ * @param source - class, function or string to label the source of the message
48
52
  */
49
- export function logDebug(msgs: string[] | string, source?: any) {
53
+ export function logDebug(msgs: Some<unknown>, source?: LogSource) {
50
54
  return loggedDo(msgs, null, source, 'debug');
51
55
  }
52
56
 
57
+ /**
58
+ * Write to `console.error()` with standardized formatting and source info.
59
+ * @param msgs - message(s) to output
60
+ * @param source - class, function or string to label the source of the message
61
+ */
62
+ export function logError(msgs: Some<unknown>, source?: LogSource) {
63
+ return loggedDo(msgs, null, source, 'error');
64
+ }
65
+
66
+ /**
67
+ * Write to `console.warn()` with standardized formatting and source info.
68
+ * @param msgs - message(s) to output
69
+ * @param source - class, function or string to label the source of the message
70
+ */
71
+ export function logWarn(msgs: Some<unknown>, source?: LogSource) {
72
+ return loggedDo(msgs, null, source, 'warn');
73
+ }
74
+
53
75
  //----------------------------------
54
76
  // Implementation
55
77
  //----------------------------------
56
- function loggedDo(msgs, fn, source, level) {
57
- source = parseSource(source);
58
- msgs = castArray(msgs);
59
- const msg = msgs.join(' | ');
78
+ function loggedDo<T>(messages: Some<unknown>, fn: () => T, source: LogSource, level: LogLevel) {
79
+ let src = parseSource(source);
80
+ let msgs = castArray(messages);
60
81
 
61
82
  // Support simple message only.
62
83
  if (!fn) {
63
- writeLog(msg, source, level);
84
+ writeLog(msgs, src, level);
64
85
  return;
65
86
  }
66
87
 
67
88
  // Otherwise, wrap the call to the provided fn.
68
- let start, ret;
89
+ let start: number, ret: T;
69
90
  const logCompletion = () => {
70
91
  const elapsed = Date.now() - start;
71
- writeLog(`${msg} | ${elapsed}ms`, source, level);
92
+ writeLog([...msgs, `${elapsed}ms`], src, level);
72
93
  },
73
94
  logException = e => {
74
95
  const elapsed = Date.now() - start;
75
96
  writeLog(
76
- `${msg} | failed - ${e.message ?? e.name ?? 'Unknown error'} | ${elapsed}ms`,
77
- source,
97
+ [...msgs, `failed - ${e.message ?? e.name ?? 'Unknown error'}`, `${elapsed}ms`, e],
98
+ src,
78
99
  level
79
100
  );
80
101
  };
@@ -96,14 +117,33 @@ function loggedDo(msgs, fn, source, level) {
96
117
  return ret;
97
118
  }
98
119
 
99
- function parseSource(source) {
120
+ function parseSource(source: LogSource): string {
121
+ if (!source) return null;
100
122
  if (isString(source)) return source;
101
- if (source?.displayName) return source.displayName;
102
- if (source?.constructor) return source.constructor.name;
103
- return '';
123
+ if (source['displayName']) return source['displayName'];
124
+ if (source.constructor) return source.constructor.name;
125
+ return null;
104
126
  }
105
127
 
106
- function writeLog(msg, source, level) {
107
- if (source) msg = `[${source}] ${msg}`;
108
- level === 'info' ? console.log(msg) : console.debug(msg);
128
+ function writeLog(msgs: unknown[], src: string, level: LogLevel) {
129
+ if (src) msgs = [`[${src}]`, ...msgs];
130
+
131
+ msgs = intersperse(msgs, '|');
132
+
133
+ switch (level) {
134
+ case 'error':
135
+ console.error(...msgs);
136
+ break;
137
+ case 'warn':
138
+ console.warn(...msgs);
139
+ break;
140
+ case 'debug':
141
+ console.debug(...msgs);
142
+ break;
143
+ case 'info':
144
+ console.log(...msgs);
145
+ break;
146
+ }
109
147
  }
148
+
149
+ type LogLevel = 'error' | 'warn' | 'info' | 'debug';
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Copyright © 2023 Extremely Heavy Industries Inc.
6
6
  */
7
- import {HoistProps, LayoutProps, PlainObject} from '@xh/hoist/core';
7
+ import {HoistProps, LayoutProps} from '@xh/hoist/core';
8
8
  import {forOwn, isEmpty, isNumber, isString, isNil, omit, pick} from 'lodash';
9
9
 
10
10
  /**
@@ -40,9 +40,9 @@ import {forOwn, isEmpty, isNumber, isString, isNil, omit, pick} from 'lodash';
40
40
  * that afforded by the underlying flexbox styles. In particular, it accepts flex and sizing props
41
41
  * as raw numbers rather than strings.
42
42
  */
43
- export function getLayoutProps(props: PlainObject): LayoutProps {
43
+ export function getLayoutProps(props: HoistProps): LayoutProps {
44
44
  // Harvest all keys of interest
45
- const ret: LayoutProps = pick(props, allKeys);
45
+ const ret: LayoutProps = pick(props, allKeys) as LayoutProps;
46
46
 
47
47
  // flexXXX: convert raw number to string
48
48
  const flexConfig = pick(ret, flexKeys);