@xh/hoist 74.0.0-SNAPSHOT.1748339158877 → 74.0.0-SNAPSHOT.1748339737885
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.
|
@@ -43,6 +43,11 @@ export interface ViewManagerConfig {
|
|
|
43
43
|
* True (default) to allow users to share their views with other users.
|
|
44
44
|
*/
|
|
45
45
|
enableSharing?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* True (default) to save pending state to SessionStorage so that it can be restored across
|
|
48
|
+
* browser refreshes. Unlike auto-save, this does not write to the database.
|
|
49
|
+
*/
|
|
50
|
+
preserveUnsavedChanges?: boolean;
|
|
46
51
|
/**
|
|
47
52
|
* Function to determine the initial view for a user, when no view has already been persisted.
|
|
48
53
|
* Will be passed a list of views available to the current user. Implementations where
|
|
@@ -132,6 +137,7 @@ export declare class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
132
137
|
readonly enableDefault: boolean;
|
|
133
138
|
readonly enableGlobal: boolean;
|
|
134
139
|
readonly enableSharing: boolean;
|
|
140
|
+
readonly preserveUnsavedChanges: boolean;
|
|
135
141
|
readonly manageGlobal: boolean;
|
|
136
142
|
readonly settleTime: number;
|
|
137
143
|
readonly initialViewSpec: (views: ViewInfo[]) => ViewInfo;
|
|
@@ -198,6 +204,7 @@ export declare class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
198
204
|
resetAsync(): Promise<void>;
|
|
199
205
|
getValue(): Partial<T>;
|
|
200
206
|
setValue(value: Partial<T>): void;
|
|
207
|
+
noteStatePushed(): void;
|
|
201
208
|
userPin(view: ViewInfo): void;
|
|
202
209
|
userUnpin(view: ViewInfo): void;
|
|
203
210
|
isUserPinned(view: ViewInfo): boolean | null;
|
|
@@ -74,6 +74,12 @@ export interface ViewManagerConfig {
|
|
|
74
74
|
*/
|
|
75
75
|
enableSharing?: boolean;
|
|
76
76
|
|
|
77
|
+
/**
|
|
78
|
+
* True (default) to save pending state to SessionStorage so that it can be restored across
|
|
79
|
+
* browser refreshes. Unlike auto-save, this does not write to the database.
|
|
80
|
+
*/
|
|
81
|
+
preserveUnsavedChanges?: boolean;
|
|
82
|
+
|
|
77
83
|
/**
|
|
78
84
|
* Function to determine the initial view for a user, when no view has already been persisted.
|
|
79
85
|
* Will be passed a list of views available to the current user. Implementations where
|
|
@@ -176,6 +182,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
176
182
|
readonly enableDefault: boolean;
|
|
177
183
|
readonly enableGlobal: boolean;
|
|
178
184
|
readonly enableSharing: boolean;
|
|
185
|
+
readonly preserveUnsavedChanges: boolean;
|
|
179
186
|
readonly manageGlobal: boolean;
|
|
180
187
|
readonly settleTime: number;
|
|
181
188
|
readonly initialViewSpec: (views: ViewInfo[]) => ViewInfo;
|
|
@@ -296,6 +303,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
296
303
|
enableDefault = true,
|
|
297
304
|
enableGlobal = true,
|
|
298
305
|
enableSharing = true,
|
|
306
|
+
preserveUnsavedChanges = true,
|
|
299
307
|
settleTime = 1000,
|
|
300
308
|
initialViewSpec = null
|
|
301
309
|
}: ViewManagerConfig) {
|
|
@@ -317,6 +325,7 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
317
325
|
this.enableGlobal = enableGlobal;
|
|
318
326
|
this.enableSharing = enableSharing;
|
|
319
327
|
this.enableAutoSave = enableAutoSave;
|
|
328
|
+
this.preserveUnsavedChanges = preserveUnsavedChanges;
|
|
320
329
|
this.settleTime = settleTime;
|
|
321
330
|
this.initialViewSpec = initialViewSpec;
|
|
322
331
|
|
|
@@ -438,6 +447,10 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
438
447
|
}
|
|
439
448
|
}
|
|
440
449
|
|
|
450
|
+
noteStatePushed() {
|
|
451
|
+
this.lastPushed = Date.now();
|
|
452
|
+
}
|
|
453
|
+
|
|
441
454
|
//------------------
|
|
442
455
|
// Pinning
|
|
443
456
|
//------------------
|
|
@@ -515,7 +528,9 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
515
528
|
this.views = views;
|
|
516
529
|
this.userPinned = state.userPinned;
|
|
517
530
|
this.autoSave = state.autoSave;
|
|
518
|
-
this.
|
|
531
|
+
if (this.preserveUnsavedChanges) {
|
|
532
|
+
this.pendingValue = XH.sessionStorageService.get(pendingValueStorageKey);
|
|
533
|
+
}
|
|
519
534
|
});
|
|
520
535
|
|
|
521
536
|
// 2) Initialize/choose initial view. Null is ok, and will yield default.
|
|
@@ -546,7 +561,10 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
546
561
|
private pendingValueReaction(): ReactionSpec {
|
|
547
562
|
return {
|
|
548
563
|
track: () => this.pendingValue,
|
|
549
|
-
run: v =>
|
|
564
|
+
run: v => {
|
|
565
|
+
if (!this.preserveUnsavedChanges) return;
|
|
566
|
+
XH.sessionStorageService.set(this.pendingValueStorageKey, v);
|
|
567
|
+
}
|
|
550
568
|
};
|
|
551
569
|
}
|
|
552
570
|
|
|
@@ -588,7 +606,6 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
|
|
|
588
606
|
.thenAction(latest => {
|
|
589
607
|
this.setAsView(latest, pendingValue?.token == token ? pendingValue : null);
|
|
590
608
|
this.providers.forEach(it => it.pushStateToTarget());
|
|
591
|
-
this.lastPushed = Date.now();
|
|
592
609
|
})
|
|
593
610
|
.linkTo(this.selectTask);
|
|
594
611
|
}
|
|
@@ -19,11 +19,13 @@ export class ViewManagerProvider<S> extends PersistenceProvider<S> {
|
|
|
19
19
|
throwIf(!viewManagerModel, `ViewManagerProvider requires a 'viewManagerModel'.`);
|
|
20
20
|
this.viewManagerModel = viewManagerModel;
|
|
21
21
|
viewManagerModel.providers.push(this);
|
|
22
|
+
viewManagerModel.noteStatePushed();
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
pushStateToTarget() {
|
|
25
26
|
const state = this.read();
|
|
26
27
|
this.target.setPersistableState(state ? state : this.defaultState);
|
|
28
|
+
this.viewManagerModel.noteStatePushed();
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
//----------------
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xh/hoist",
|
|
3
|
-
"version": "74.0.0-SNAPSHOT.
|
|
3
|
+
"version": "74.0.0-SNAPSHOT.1748339737885",
|
|
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",
|