@xh/hoist 89.0.1 → 89.2.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.
- package/CHANGELOG.md +75 -0
- package/build/types/cmp/grid/GridModel.d.ts +6 -0
- package/build/types/cmp/input/impl/LiveCommas.d.ts +21 -0
- package/build/types/cmp/viewmanager/ViewManagerModel.d.ts +4 -2
- package/build/types/core/XH.d.ts +2 -1
- package/build/types/core/model/HoistModel.d.ts +1 -0
- package/build/types/core/model/ManagedRefreshContextModel.d.ts +1 -0
- package/build/types/core/persist/PersistenceProvider.d.ts +3 -0
- package/build/types/data/cube/View.d.ts +0 -2
- package/build/types/data/cube/impl/RowCache.d.ts +1 -1
- package/build/types/data/cube/row/BaseRow.d.ts +5 -0
- package/build/types/desktop/cmp/dash/DashViewSpec.d.ts +2 -1
- package/build/types/desktop/cmp/dash/canvas/impl/DashCanvasContextMenu.d.ts +1 -1
- package/build/types/desktop/cmp/dash/canvas/widgetchooser/DashCanvasWidgetChooser.d.ts +3 -2
- package/build/types/desktop/cmp/dash/container/impl/DashContainerContextMenu.d.ts +1 -1
- package/build/types/desktop/cmp/dash/impl/DashUtils.d.ts +35 -0
- package/build/types/desktop/cmp/grid/editors/impl/InlineEditorModel.d.ts +6 -1
- package/build/types/desktop/cmp/input/NumberInput.d.ts +5 -2
- package/build/types/desktop/cmp/tab/dynamic/DynamicTabSwitcherModel.d.ts +1 -2
- package/build/types/mobile/cmp/input/NumberInput.d.ts +5 -2
- package/build/types/svc/FetchService.d.ts +19 -0
- package/build/types/test-support/agGrid.d.ts +2 -0
- package/build/types/test-support/hoistCore.d.ts +7 -1
- package/build/types/test-support/index.d.ts +1 -0
- package/build/types/test-support/jsonBlobs.d.ts +130 -0
- package/build/types/test-support/testApp.d.ts +5 -2
- package/cmp/grid/Grid.ts +2 -2
- package/cmp/grid/GridModel.ts +14 -1
- package/cmp/grid/columns/Column.ts +3 -2
- package/cmp/input/impl/LiveCommas.ts +59 -0
- package/cmp/viewmanager/ViewManagerModel.ts +25 -7
- package/core/XH.ts +8 -3
- package/core/model/HoistModel.ts +4 -2
- package/core/model/Hooks.ts +1 -0
- package/core/model/ManagedRefreshContextModel.ts +5 -1
- package/core/persist/PersistenceProvider.ts +15 -1
- package/data/cube/View.ts +3 -9
- package/data/cube/impl/RowCache.ts +2 -2
- package/data/cube/row/BaseRow.ts +14 -1
- package/data/cube/row/ParentRow.ts +1 -1
- package/desktop/cmp/dash/DashViewSpec.ts +2 -1
- package/desktop/cmp/dash/README.md +6 -5
- package/desktop/cmp/dash/canvas/impl/DashCanvasContextMenu.ts +1 -1
- package/desktop/cmp/dash/canvas/impl/utils.ts +16 -51
- package/desktop/cmp/dash/canvas/widgetchooser/DashCanvasWidgetChooser.ts +37 -54
- package/desktop/cmp/dash/container/impl/DashContainerContextMenu.ts +8 -39
- package/desktop/cmp/dash/impl/DashUtils.ts +90 -0
- package/desktop/cmp/grid/editors/BooleanEditor.ts +2 -1
- package/desktop/cmp/grid/editors/DateEditor.ts +4 -1
- package/desktop/cmp/grid/editors/SelectEditor.ts +4 -1
- package/desktop/cmp/grid/editors/impl/InlineEditorModel.ts +17 -5
- package/desktop/cmp/input/NumberInput.ts +51 -12
- package/desktop/cmp/input/Select.ts +25 -7
- package/desktop/cmp/tab/TabSwitcher.ts +4 -6
- package/desktop/cmp/tab/dynamic/DynamicTabSwitcher.ts +4 -5
- package/desktop/cmp/tab/dynamic/DynamicTabSwitcherModel.ts +2 -7
- package/docs/README.md +2 -0
- package/docs/build-and-publish.md +21 -11
- package/docs/companion-library-docs.md +205 -0
- package/docs/doc-registry.json +9 -1
- package/docs/lifecycle-app.md +17 -0
- package/docs/lifecycle-models-and-services.md +2 -1
- package/docs/persistence.md +2 -0
- package/docs/telemetry.md +29 -0
- package/docs/unit-testing.md +54 -3
- package/docs/upgrade-notes/v89-upgrade-notes.md +7 -1
- package/docs/version-compatibility.md +2 -1
- package/icon/README.md +4 -1
- package/mcp/README.md +79 -4
- package/mcp/cli/docs.ts +75 -30
- package/mcp/data/doc-id-resolver.ts +50 -9
- package/mcp/data/doc-registry.ts +462 -44
- package/mcp/data/doc-search.ts +25 -6
- package/mcp/formatters/docs.ts +136 -36
- package/mcp/instructions.ts +69 -0
- package/mcp/resources/docs.ts +10 -8
- package/mcp/server.ts +7 -13
- package/mcp/tools/docs.ts +64 -18
- package/mcp/util/paths.ts +85 -2
- package/mobile/cmp/input/NumberInput.ts +42 -4
- package/package.json +19 -19
- package/public/msal-redirect-bridge.min.js +1 -1
- package/svc/FetchService.ts +38 -2
- package/svc/JsonBlobService.ts +7 -4
- package/svc/README.md +7 -3
- package/test-support/agGrid.ts +12 -2
- package/test-support/hoistCore.ts +32 -5
- package/test-support/index.ts +1 -0
- package/test-support/jsonBlobs.ts +543 -0
- package/test-support/setup.ts +8 -6
- package/test-support/testApp.ts +36 -7
- package/build/types/desktop/cmp/tab/impl/TabContextMenuItems.d.ts +0 -4
- package/desktop/cmp/tab/impl/TabContextMenuItems.ts +0 -23
package/cmp/grid/GridModel.ts
CHANGED
|
@@ -1439,7 +1439,7 @@ export class GridModel extends HoistModel {
|
|
|
1439
1439
|
return {
|
|
1440
1440
|
colId,
|
|
1441
1441
|
pinned: isBoolean(pinned) ? (pinned ? 'left' : null) : pinned,
|
|
1442
|
-
hidden: !!hide,
|
|
1442
|
+
hidden: this.isColumnHiddenByGrouping(colId) ? null : !!hide,
|
|
1443
1443
|
width: col.flex ? undefined : width
|
|
1444
1444
|
};
|
|
1445
1445
|
}
|
|
@@ -1590,6 +1590,19 @@ export class GridModel extends HoistModel {
|
|
|
1590
1590
|
return state ? !state.hidden : false;
|
|
1591
1591
|
}
|
|
1592
1592
|
|
|
1593
|
+
/**
|
|
1594
|
+
* True if ag-Grid is hiding this column because the grid is grouped by it. Hoist leaves the
|
|
1595
|
+
* visibility of such a column to ag-Grid, keeping its own `hidden` state for after ungrouping.
|
|
1596
|
+
* @internal
|
|
1597
|
+
*/
|
|
1598
|
+
isColumnHiddenByGrouping(colId: string): boolean {
|
|
1599
|
+
const {agApi} = this;
|
|
1600
|
+
if (!agApi || !this.groupBy.includes(colId)) return false;
|
|
1601
|
+
|
|
1602
|
+
const suppress = agApi.getGridOption('suppressGroupChangesColumnVisibility');
|
|
1603
|
+
return suppress !== true && suppress !== 'suppressHideOnGroup';
|
|
1604
|
+
}
|
|
1605
|
+
|
|
1593
1606
|
setColumnVisible(colId: string, visible: boolean) {
|
|
1594
1607
|
this.updateColumnState([{colId, hidden: !visible}]);
|
|
1595
1608
|
}
|
|
@@ -473,7 +473,7 @@ export interface ColumnSpec {
|
|
|
473
473
|
* @mcpHint column configuration for grids
|
|
474
474
|
*/
|
|
475
475
|
export class Column {
|
|
476
|
-
static DEFAULT_WIDTH =
|
|
476
|
+
static DEFAULT_WIDTH = 100;
|
|
477
477
|
static FLEX_COL_MIN_WIDTH = 30;
|
|
478
478
|
|
|
479
479
|
/**
|
|
@@ -807,7 +807,8 @@ export class Column {
|
|
|
807
807
|
},
|
|
808
808
|
headerClass: getAgHeaderClassFn(this),
|
|
809
809
|
headerTooltip: this.headerTooltip,
|
|
810
|
-
|
|
810
|
+
// Undefined keeps ag-Grid's current visibility on update.
|
|
811
|
+
hide: gridModel.isColumnHiddenByGrouping(this.colId) ? undefined : this.hidden,
|
|
811
812
|
columnGroupShow: toAgColumnGroupShow(this.groupShowMode),
|
|
812
813
|
minWidth: this.minWidth,
|
|
813
814
|
maxWidth: this.maxWidth,
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This file belongs to Hoist, an application development toolkit
|
|
3
|
+
* developed by Extremely Heavy Industries (www.xh.io | info@xh.io)
|
|
4
|
+
*
|
|
5
|
+
* Copyright © 2026 Extremely Heavy Industries Inc.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Helpers for NumberInput's `displayWithCommas: 'always'` mode, which groups digits while the user
|
|
10
|
+
* types. Commas are the only characters a reformat adds or removes, so the caret is tracked as a
|
|
11
|
+
* count of the non-comma characters before it.
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Group the leading integer digits of a partially typed number with commas. Everything after them
|
|
17
|
+
* (decimals, exponent, shorthand unit) is kept as typed.
|
|
18
|
+
*/
|
|
19
|
+
export function addCommasWhileEditing(value: string): string {
|
|
20
|
+
return value
|
|
21
|
+
.replace(/,/g, '')
|
|
22
|
+
.replace(
|
|
23
|
+
/^(\s*[-+]?)(\d+)/,
|
|
24
|
+
(_, sign, digits) => sign + digits.replace(/\B(?=(\d{3})+$)/g, ',')
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Count of non-comma characters before the caret, or null if the input has no caret. */
|
|
29
|
+
export function getCaretSkippingCommas(input: HTMLInputElement): number {
|
|
30
|
+
const {selectionStart, value} = input;
|
|
31
|
+
return selectionStart == null ? null : value.slice(0, selectionStart).replace(/,/g, '').length;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Place the caret after the given count of non-comma characters. */
|
|
35
|
+
export function setCaretSkippingCommas(input: HTMLInputElement, count: number) {
|
|
36
|
+
const {value} = input;
|
|
37
|
+
let idx = 0;
|
|
38
|
+
for (; idx < value.length && count > 0; idx++) {
|
|
39
|
+
if (value[idx] !== ',') count--;
|
|
40
|
+
}
|
|
41
|
+
input.setSelectionRange(idx, idx);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* `beforeinput` listener that steps the caret over an adjacent comma before Backspace or Delete, so
|
|
46
|
+
* the key removes the digit beyond it. Otherwise the reformat would restore the deleted comma.
|
|
47
|
+
* Listens for the native event, which (unlike `keydown`) reports deletes from mobile soft keyboards.
|
|
48
|
+
*/
|
|
49
|
+
export function skipCommaOnDelete(ev: InputEvent) {
|
|
50
|
+
const input = ev.target as HTMLInputElement,
|
|
51
|
+
{selectionStart: start, selectionEnd: end, value} = input;
|
|
52
|
+
if (start == null || start !== end) return;
|
|
53
|
+
|
|
54
|
+
if (ev.inputType === 'deleteContentBackward' && value[start - 1] === ',') {
|
|
55
|
+
input.setSelectionRange(start - 1, start - 1);
|
|
56
|
+
} else if (ev.inputType === 'deleteContentForward' && value[start] === ',') {
|
|
57
|
+
input.setSelectionRange(start + 1, start + 1);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -268,6 +268,9 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
268
268
|
*/
|
|
269
269
|
private providers: ViewManagerProvider<any>[] = [];
|
|
270
270
|
|
|
271
|
+
/** Count of calls to {@link loadViewAsync}, used to identify the latest. */
|
|
272
|
+
private viewLoadCount = 0;
|
|
273
|
+
|
|
271
274
|
/** Data access for persisting views. */
|
|
272
275
|
private dataAccess: DataAccess<T>;
|
|
273
276
|
|
|
@@ -386,7 +389,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
386
389
|
}
|
|
387
390
|
|
|
388
391
|
override async doLoadAsync(loadSpec: LoadSpec) {
|
|
389
|
-
const {dataAccess
|
|
392
|
+
const {dataAccess} = this;
|
|
390
393
|
await this.runner({loadSpec})
|
|
391
394
|
.span('refresh')
|
|
392
395
|
.run(async ctx => {
|
|
@@ -400,8 +403,10 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
400
403
|
this.serverManageGlobal = manageGlobal ?? null;
|
|
401
404
|
});
|
|
402
405
|
|
|
403
|
-
//
|
|
404
|
-
|
|
406
|
+
// Fast-forward the current view if it was updated elsewhere.
|
|
407
|
+
// Skip while an explicit view load is pending - this is subordinate background work
|
|
408
|
+
const {view} = this;
|
|
409
|
+
if (!view.isDefault && !this.selectTask.isPending) {
|
|
405
410
|
const latestInfo = find(views, {token: view.token});
|
|
406
411
|
if (latestInfo && latestInfo.lastUpdated > view.lastUpdated) {
|
|
407
412
|
this.loadViewAsync(view.token, this.pendingValue, ctx);
|
|
@@ -470,7 +475,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
470
475
|
.updateViewValueAsync(view, pendingValue.value, ctx)
|
|
471
476
|
.linkTo(this.saveTask);
|
|
472
477
|
|
|
473
|
-
this.
|
|
478
|
+
this.applySavedView(updated, pendingValue);
|
|
474
479
|
this.noteSuccess(`Saved ${view.typedName}`);
|
|
475
480
|
|
|
476
481
|
this.refreshAsync();
|
|
@@ -719,12 +724,19 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
719
724
|
pendingValue: PendingValue<T> = null,
|
|
720
725
|
ctx: CallContext
|
|
721
726
|
): Promise<void> {
|
|
727
|
+
const loadNum = ++this.viewLoadCount,
|
|
728
|
+
isStale = () => loadNum !== this.viewLoadCount;
|
|
729
|
+
|
|
722
730
|
return this.dataAccess
|
|
723
731
|
.fetchViewAsync(token, ctx)
|
|
724
732
|
.thenAction(latest => {
|
|
733
|
+
if (isStale()) return;
|
|
725
734
|
this.setAsView(latest, pendingValue?.token == token ? pendingValue : null);
|
|
726
735
|
this.providers.forEach(it => it.pushStateToTarget());
|
|
727
736
|
})
|
|
737
|
+
.catch(e => {
|
|
738
|
+
if (!isStale()) throw e;
|
|
739
|
+
})
|
|
728
740
|
.linkTo(this.selectTask);
|
|
729
741
|
}
|
|
730
742
|
|
|
@@ -740,7 +752,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
740
752
|
.updateViewValueAsync(view, pendingValue.value, ctx)
|
|
741
753
|
.linkTo(this.saveTask);
|
|
742
754
|
|
|
743
|
-
this.
|
|
755
|
+
this.applySavedView(updated, pendingValue);
|
|
744
756
|
} catch (e) {
|
|
745
757
|
// TODO: How to alert but avoid for flaky or spam when user editing a deleted view
|
|
746
758
|
// Keep count and alert server and user once at count n?
|
|
@@ -753,9 +765,15 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
753
765
|
});
|
|
754
766
|
}
|
|
755
767
|
|
|
756
|
-
/**
|
|
768
|
+
/** Apply a completed save, installing the saved view only if it is still current. */
|
|
757
769
|
@action
|
|
758
|
-
private
|
|
770
|
+
private applySavedView(saved: View<T>, sent: PendingValue<T>) {
|
|
771
|
+
// User has moved on - just update the list entry (map, so a deleted view stays out).
|
|
772
|
+
if (saved.token !== this.view.token) {
|
|
773
|
+
this.views = this.views.map(it => (it.token === saved.token ? saved.info : it));
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
|
|
759
777
|
const value = this.getValue(),
|
|
760
778
|
pendingValue = isEqual(value, sent.value)
|
|
761
779
|
? null
|
package/core/XH.ts
CHANGED
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
TraceService,
|
|
36
36
|
WebSocketService
|
|
37
37
|
} from '@xh/hoist/svc';
|
|
38
|
-
import {getLogLevel, LogLevel, setLogLevel} from '@xh/hoist/utils/js';
|
|
38
|
+
import {getLogLevel, logError, LogLevel, setLogLevel} from '@xh/hoist/utils/js';
|
|
39
39
|
import {camelCase, flatten, isString, uniqueId} from 'lodash';
|
|
40
40
|
import {Router, State} from 'router5';
|
|
41
41
|
import {CancelFn} from 'router5/types/types/base';
|
|
@@ -915,7 +915,8 @@ export class XHApi {
|
|
|
915
915
|
|
|
916
916
|
/**
|
|
917
917
|
* Helper method to destroy resources safely (e.g. child HoistModels). Will quietly skip args
|
|
918
|
-
* that are null / undefined or that do not implement destroy().
|
|
918
|
+
* that are null / undefined or that do not implement destroy(). Logs, rather than throws, an
|
|
919
|
+
* error from any destroy(), so the remaining args are still destroyed.
|
|
919
920
|
*
|
|
920
921
|
* @param args - objects to be destroyed. If any argument is an array, each top-level element
|
|
921
922
|
* in the array will be destroyed. (Note this is *not* done recursively.)
|
|
@@ -924,7 +925,11 @@ export class XHApi {
|
|
|
924
925
|
if (args) {
|
|
925
926
|
args = flatten(args);
|
|
926
927
|
args.forEach(it => {
|
|
927
|
-
|
|
928
|
+
try {
|
|
929
|
+
it?.destroy?.();
|
|
930
|
+
} catch (e) {
|
|
931
|
+
logError(['Error destroying object', e], it);
|
|
932
|
+
}
|
|
928
933
|
});
|
|
929
934
|
}
|
|
930
935
|
}
|
package/core/model/HoistModel.ts
CHANGED
|
@@ -136,9 +136,11 @@ export abstract class HoistModel extends HoistBase implements Loadable {
|
|
|
136
136
|
|
|
137
137
|
// Internal State
|
|
138
138
|
// - `_componentProps` is only set for linked models and mirrors the current React props.
|
|
139
|
-
// - `
|
|
139
|
+
// - `_linked` is set by Hoist when this model is linked into a component hierarchy.
|
|
140
|
+
// - `_modelLookup` is injected on link, and is null for a model linked at the root.
|
|
140
141
|
// - `_created` is basic lifecycle metadata (useful for diagnostics/ordering).
|
|
141
142
|
@observableRef accessor _componentProps: DefaultHoistProps | null = null;
|
|
143
|
+
_linked: boolean = false;
|
|
142
144
|
_modelLookup: any = null;
|
|
143
145
|
_created: number = Date.now();
|
|
144
146
|
|
|
@@ -201,7 +203,7 @@ export abstract class HoistModel extends HoistBase implements Loadable {
|
|
|
201
203
|
// Linked model support
|
|
202
204
|
//---------------------------
|
|
203
205
|
get isLinked(): boolean {
|
|
204
|
-
return
|
|
206
|
+
return this._linked;
|
|
205
207
|
}
|
|
206
208
|
|
|
207
209
|
/**
|
package/core/model/Hooks.ts
CHANGED
|
@@ -67,6 +67,7 @@ export function useModelLinker(model: HoistModel, modelLookup: ModelLookup, prop
|
|
|
67
67
|
|
|
68
68
|
// 1) Linking synchronous work: resolve lookups, initialize props, and call onLinked()
|
|
69
69
|
if (isLinking) {
|
|
70
|
+
model._linked = true;
|
|
70
71
|
model._modelLookup = modelLookup;
|
|
71
72
|
each(model['_xhInjectedParentProperties'], (selector, name) => {
|
|
72
73
|
const parentModel = modelLookup?.lookupModel(selector);
|
|
@@ -22,6 +22,7 @@ export class ManagedRefreshContextModel extends RefreshContextModel {
|
|
|
22
22
|
|
|
23
23
|
model: ManagedRefreshTarget;
|
|
24
24
|
refreshPending: boolean = false;
|
|
25
|
+
private pendingIsAutoRefresh: boolean = false;
|
|
25
26
|
|
|
26
27
|
constructor(model: ManagedRefreshTarget) {
|
|
27
28
|
super();
|
|
@@ -42,6 +43,9 @@ export class ManagedRefreshContextModel extends RefreshContextModel {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
if (mode === 'onShowLazy') {
|
|
46
|
+
// Replay as an auto-refresh only if every missed refresh was one.
|
|
47
|
+
this.pendingIsAutoRefresh =
|
|
48
|
+
loadSpec.isAutoRefresh && (!this.refreshPending || this.pendingIsAutoRefresh);
|
|
45
49
|
this.refreshPending = true;
|
|
46
50
|
}
|
|
47
51
|
}
|
|
@@ -53,7 +57,7 @@ export class ManagedRefreshContextModel extends RefreshContextModel {
|
|
|
53
57
|
this.refreshAsync();
|
|
54
58
|
} else if (mode === 'onShowLazy' && this.refreshPending) {
|
|
55
59
|
this.refreshPending = false;
|
|
56
|
-
this.refreshAsync();
|
|
60
|
+
this.pendingIsAutoRefresh ? this.autoRefreshAsync() : this.refreshAsync();
|
|
57
61
|
}
|
|
58
62
|
}
|
|
59
63
|
}
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
get,
|
|
15
15
|
isArray,
|
|
16
16
|
isEmpty,
|
|
17
|
+
isFunction,
|
|
17
18
|
isNumber,
|
|
18
19
|
isObject,
|
|
19
20
|
isString,
|
|
@@ -138,7 +139,7 @@ export abstract class PersistenceProvider<S = any> {
|
|
|
138
139
|
|
|
139
140
|
// Drop any debounced write still pending - it holds pre-clear state and would otherwise
|
|
140
141
|
// land after this call and resurrect it.
|
|
141
|
-
|
|
142
|
+
this.cancelPendingWrite();
|
|
142
143
|
|
|
143
144
|
const obj = cloneDeep(this.readRaw()),
|
|
144
145
|
path = toPath(this.path);
|
|
@@ -153,10 +154,12 @@ export abstract class PersistenceProvider<S = any> {
|
|
|
153
154
|
|
|
154
155
|
destroy() {
|
|
155
156
|
this.disposer?.();
|
|
157
|
+
this.debouncedWrite?.flush(); // write any pending change now
|
|
156
158
|
}
|
|
157
159
|
|
|
158
160
|
/** Push the current state of this provider to its target. */
|
|
159
161
|
pushStateToTarget() {
|
|
162
|
+
this.cancelPendingWrite(); // stale - would overwrite pushed state
|
|
160
163
|
const state = this.read();
|
|
161
164
|
this.target.setPersistableState(state ? state : this.defaultState);
|
|
162
165
|
}
|
|
@@ -223,6 +226,11 @@ export abstract class PersistenceProvider<S = any> {
|
|
|
223
226
|
return null;
|
|
224
227
|
}
|
|
225
228
|
|
|
229
|
+
/** Drop any debounced write still pending. */
|
|
230
|
+
protected cancelPendingWrite() {
|
|
231
|
+
this.debouncedWrite?.cancel();
|
|
232
|
+
}
|
|
233
|
+
|
|
226
234
|
/**
|
|
227
235
|
* Resolve the PersistenceProvider class that the given options would produce, applying the
|
|
228
236
|
* same precedence used by {@link create}. Throws if the options do not resolve to a known
|
|
@@ -254,6 +262,12 @@ export abstract class PersistenceProvider<S = any> {
|
|
|
254
262
|
return ret;
|
|
255
263
|
}
|
|
256
264
|
|
|
265
|
+
// The debounced write function, or null if writes are not debounced - see constructor.
|
|
266
|
+
private get debouncedWrite(): DebouncedFunc<(data: S) => void> {
|
|
267
|
+
const ret = this.writeInternal as DebouncedFunc<(data: S) => void>;
|
|
268
|
+
return isFunction(ret.cancel) ? ret : null;
|
|
269
|
+
}
|
|
270
|
+
|
|
257
271
|
private ensureValid() {
|
|
258
272
|
const data = this.readRaw();
|
|
259
273
|
throwIf(
|
package/data/cube/View.ts
CHANGED
|
@@ -149,8 +149,6 @@ export class View
|
|
|
149
149
|
|
|
150
150
|
private _fieldsByName: Map<string, CubeField> = null;
|
|
151
151
|
private _rowDataGenerator: RowDataGenerator = null;
|
|
152
|
-
// Monotonic source for cubeRowDigest stamps - safe-integer headroom spans centuries of use.
|
|
153
|
-
_rowDigest = 0;
|
|
154
152
|
// Fields eligible for aggregation at each level of the query - i.e. those with an aggregator
|
|
155
153
|
// that are not themselves an applied dimension there - and useful subsets of same. Indexed by
|
|
156
154
|
// row depth, with entry 0 (no dimensions applied) holding the superset for the whole query.
|
|
@@ -335,7 +333,7 @@ export class View
|
|
|
335
333
|
*/
|
|
336
334
|
newParentRowData(id: string): ViewRowData {
|
|
337
335
|
const ret = this._rowDataGenerator.newParentRowData(id);
|
|
338
|
-
|
|
336
|
+
BaseRow.assignDigest(ret);
|
|
339
337
|
return ret;
|
|
340
338
|
}
|
|
341
339
|
|
|
@@ -345,14 +343,10 @@ export class View
|
|
|
345
343
|
*/
|
|
346
344
|
newLeafRowData(id: string, src: PlainObject): ViewRowData {
|
|
347
345
|
const ret = this._rowDataGenerator.newLeafRowData(id, src);
|
|
348
|
-
|
|
346
|
+
BaseRow.assignDigest(ret);
|
|
349
347
|
return ret;
|
|
350
348
|
}
|
|
351
349
|
|
|
352
|
-
assignDigest(data: ViewRowData) {
|
|
353
|
-
data.cubeRowDigest = ++this._rowDigest;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
350
|
private buildIndices() {
|
|
357
351
|
this._fieldsByName = new Map(this.fields.map(it => [it.name, it]));
|
|
358
352
|
|
|
@@ -419,7 +413,7 @@ export class View
|
|
|
419
413
|
_leafMap.get(rec.id)?.applyLeafDataUpdate(rec, checkFields, changed);
|
|
420
414
|
});
|
|
421
415
|
|
|
422
|
-
changed.rows.forEach(rowData =>
|
|
416
|
+
changed.rows.forEach(rowData => BaseRow.assignDigest(rowData));
|
|
423
417
|
|
|
424
418
|
this.createAggregationContext();
|
|
425
419
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import type {StoreRecord} from '@xh/hoist/data';
|
|
9
9
|
import {isEqual, map} from 'lodash';
|
|
10
10
|
import type {Query} from '../Query';
|
|
11
|
-
import
|
|
11
|
+
import {BaseRow} from '../row/BaseRow';
|
|
12
12
|
import {ExposedLeafRow, type LeafRow} from '../row/LeafRow';
|
|
13
13
|
import type {ParentRow} from '../row/ParentRow';
|
|
14
14
|
import type {View} from '../View';
|
|
@@ -93,7 +93,7 @@ export class RowCache {
|
|
|
93
93
|
beginGeneration() {
|
|
94
94
|
const {view} = this;
|
|
95
95
|
this.pruneForQueryChange(view.query);
|
|
96
|
-
this.genStartDigest =
|
|
96
|
+
this.genStartDigest = BaseRow.currentDigest;
|
|
97
97
|
this.exposedLeaves = view.exposesLeaves;
|
|
98
98
|
this.reused = this.rebuilt = this.created = 0;
|
|
99
99
|
}
|
package/data/cube/row/BaseRow.ts
CHANGED
|
@@ -19,6 +19,19 @@ import type {ParentRow} from './ParentRow';
|
|
|
19
19
|
* @internal
|
|
20
20
|
*/
|
|
21
21
|
export abstract class BaseRow implements ViewRow {
|
|
22
|
+
// Shared by all Views, so stamps never repeat across Views on the same Store.
|
|
23
|
+
private static lastDigest = 0;
|
|
24
|
+
|
|
25
|
+
/** The latest cubeRowDigest stamp given out by any View. */
|
|
26
|
+
static get currentDigest(): number {
|
|
27
|
+
return BaseRow.lastDigest;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** Stamp row data with a new cubeRowDigest, marking it changed. */
|
|
31
|
+
static assignDigest(data: ViewRowData) {
|
|
32
|
+
data.cubeRowDigest = ++BaseRow.lastDigest;
|
|
33
|
+
}
|
|
34
|
+
|
|
22
35
|
readonly view: View = null;
|
|
23
36
|
readonly id: string = null;
|
|
24
37
|
|
|
@@ -53,7 +66,7 @@ export abstract class BaseRow implements ViewRow {
|
|
|
53
66
|
|
|
54
67
|
if (!shallowEqualObjects(data.cubeBuckets, buckets)) {
|
|
55
68
|
data.cubeBuckets = buckets;
|
|
56
|
-
|
|
69
|
+
BaseRow.assignDigest(data as ViewRowData);
|
|
57
70
|
}
|
|
58
71
|
|
|
59
72
|
this.children?.forEach(it => it.syncBuckets(buckets));
|
|
@@ -136,7 +136,7 @@ export abstract class ParentRow extends BaseRow {
|
|
|
136
136
|
changed = this.recomputeAggregatesForContextChange(this.recomputeCanAggregate());
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
if (changed)
|
|
139
|
+
if (changed) BaseRow.assignDigest(this.data);
|
|
140
140
|
return this;
|
|
141
141
|
}
|
|
142
142
|
|
|
@@ -28,7 +28,8 @@ export interface DashViewSpec {
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Group name to display within the add view component. The default context menu will
|
|
31
|
-
* automatically group its available views if provided.
|
|
31
|
+
* automatically group its available views if provided. Separate names with '/' to nest
|
|
32
|
+
* groups - e.g. `Charts/Line`.
|
|
32
33
|
*/
|
|
33
34
|
groupName?: string;
|
|
34
35
|
|
|
@@ -78,7 +78,7 @@ DashViewSpec (base interface)
|
|
|
78
78
|
├── content: Content # Rendered content
|
|
79
79
|
├── title: string # Default title (defaults to startCase(id))
|
|
80
80
|
├── icon: ReactElement # Default icon
|
|
81
|
-
├── groupName: string # Menu grouping
|
|
81
|
+
├── groupName: string # Menu grouping, '/' to nest
|
|
82
82
|
├── unique: boolean # Allow multiple instances?
|
|
83
83
|
├── allowAdd/Remove/Rename # Permission flags
|
|
84
84
|
└── omit: Thunkable<boolean> # Exclude from dashboard
|
|
@@ -367,9 +367,10 @@ canvasModel.isEmpty; // No widgets?
|
|
|
367
367
|
view specs for a `DashCanvas`. Users can drag widgets from the chooser and drop them onto the
|
|
368
368
|
canvas. It is typically placed inside a collapsible panel alongside the canvas.
|
|
369
369
|
|
|
370
|
-
Available view specs are listed in their defined order, grouped by their
|
|
371
|
-
if present
|
|
372
|
-
automatically hidden from the
|
|
370
|
+
Available view specs are listed in their defined order, grouped into collapsible cards by their
|
|
371
|
+
`groupName` property if present - a slash-delimited name nests cards within cards. Specs with
|
|
372
|
+
`unique: true` that already have an instance on the canvas are automatically hidden from the
|
|
373
|
+
chooser.
|
|
373
374
|
|
|
374
375
|
### Requirements
|
|
375
376
|
|
|
@@ -413,7 +414,7 @@ Both dash types share these base properties on their ViewSpecs:
|
|
|
413
414
|
| `content` | `Content` | View content to render. Required. |
|
|
414
415
|
| `title` | `string` | Default display title. Defaults to `startCase(id)`. |
|
|
415
416
|
| `icon` | `ReactElement` | Display icon. |
|
|
416
|
-
| `groupName` | `string` | Group name for the "Add" menu
|
|
417
|
+
| `groupName` | `string` | Group name for the "Add" menu - specs with the same group are nested into a submenu. Separate names with `/` to nest groups, e.g. `Charts/Line`. Each group is listed where its first spec appears. |
|
|
417
418
|
| `omit` | `Thunkable<boolean>` | Skip this spec entirely. References in state are quietly dropped. Useful for role-based exclusion. Default `false`. |
|
|
418
419
|
| `unique` | `boolean` | Only one instance allowed at a time. Default `false`. |
|
|
419
420
|
| `allowAdd` | `boolean` | Can add new instances via the menu. Existing instances in state are still loaded. Default `true`. |
|
|
@@ -15,7 +15,7 @@ import {isEmpty} from 'lodash';
|
|
|
15
15
|
* Context menu to add items to a DashCanvas
|
|
16
16
|
*
|
|
17
17
|
* Available view specs are listed in their defined order, optionally
|
|
18
|
-
* grouped by their
|
|
18
|
+
* grouped by their `groupName` property into (nested) submenus.
|
|
19
19
|
* @internal
|
|
20
20
|
*/
|
|
21
21
|
export const dashCanvasContextMenu = hoistCmp.factory({
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import {type MenuItemLike} from '@xh/hoist/core';
|
|
9
|
-
import {
|
|
9
|
+
import {createViewSpecMenuItems} from '../../impl/DashUtils';
|
|
10
10
|
import {DashCanvasModel} from '../DashCanvasModel';
|
|
11
11
|
|
|
12
12
|
/**
|
|
@@ -21,64 +21,29 @@ export function createViewMenuItems({
|
|
|
21
21
|
}): MenuItemLike[] {
|
|
22
22
|
if (!dashCanvasModel.ref.current) return [];
|
|
23
23
|
|
|
24
|
-
const
|
|
25
|
-
ungroupedItems = [],
|
|
26
|
-
x = position?.x ?? 0,
|
|
24
|
+
const x = position?.x ?? 0,
|
|
27
25
|
y = position?.y ?? 0,
|
|
28
|
-
addPosition = !viewId ? calcAddPosition(x, y, dashCanvasModel) : null
|
|
29
|
-
|
|
30
|
-
const addToGroup = (item, groupName) => {
|
|
31
|
-
const group = groupedItems[groupName];
|
|
32
|
-
if (group) {
|
|
33
|
-
group.push(item);
|
|
34
|
-
} else {
|
|
35
|
-
groupedItems[groupName] = [item];
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
dashCanvasModel.viewSpecs
|
|
40
|
-
.filter(viewSpec => {
|
|
26
|
+
addPosition = !viewId ? calcAddPosition(x, y, dashCanvasModel) : null,
|
|
27
|
+
addableSpecs = dashCanvasModel.viewSpecs.filter(viewSpec => {
|
|
41
28
|
return (
|
|
42
29
|
viewSpec.allowAdd &&
|
|
43
30
|
(!viewSpec.unique || !dashCanvasModel.getViewsBySpecId(viewSpec.id).length)
|
|
44
31
|
);
|
|
45
|
-
})
|
|
46
|
-
.forEach(viewSpec => {
|
|
47
|
-
const {title, icon, groupName, id} = viewSpec,
|
|
48
|
-
item = {
|
|
49
|
-
text: title,
|
|
50
|
-
icon: icon,
|
|
51
|
-
actionFn: () => {
|
|
52
|
-
if (replaceExisting) {
|
|
53
|
-
dashCanvasModel.replaceView(viewId, id);
|
|
54
|
-
} else {
|
|
55
|
-
dashCanvasModel
|
|
56
|
-
.addViewInternal(id, {layout: addPosition, previousViewId: viewId})
|
|
57
|
-
.ensureVisible();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
};
|
|
32
|
+
});
|
|
61
33
|
|
|
62
|
-
|
|
63
|
-
|
|
34
|
+
return createViewSpecMenuItems(addableSpecs, ({title, icon, id}) => ({
|
|
35
|
+
text: title,
|
|
36
|
+
icon: icon,
|
|
37
|
+
actionFn: () => {
|
|
38
|
+
if (replaceExisting) {
|
|
39
|
+
dashCanvasModel.replaceView(viewId, id);
|
|
64
40
|
} else {
|
|
65
|
-
|
|
41
|
+
dashCanvasModel
|
|
42
|
+
.addViewInternal(id, {layout: addPosition, previousViewId: viewId})
|
|
43
|
+
.ensureVisible();
|
|
66
44
|
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return [
|
|
70
|
-
...Object.keys(groupedItems).map(group => {
|
|
71
|
-
// If we have any ungrouped root items (i.e. in a 'mixed mode'),
|
|
72
|
-
// insert a hidden icon to align the item text.
|
|
73
|
-
const icon = ungroupedItems.length
|
|
74
|
-
? Icon.angleRight({style: {visibility: 'hidden'}})
|
|
75
|
-
: undefined,
|
|
76
|
-
text = group,
|
|
77
|
-
items = groupedItems[group];
|
|
78
|
-
return {icon, text, items};
|
|
79
|
-
}),
|
|
80
|
-
...ungroupedItems
|
|
81
|
-
];
|
|
45
|
+
}
|
|
46
|
+
}));
|
|
82
47
|
}
|
|
83
48
|
|
|
84
49
|
/**
|