@xh/hoist 74.0.0-SNAPSHOT.1748002015150 → 74.0.0-SNAPSHOT.1748338432179

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.
@@ -372,7 +372,7 @@ export class ActivityTrackingModel extends HoistModel implements ActivityDetailP
372
372
  {field: 'instance'},
373
373
  {field: 'loadId'},
374
374
  {field: 'msg', displayName: 'Message'},
375
- {field: 'severity'},
375
+ {field: 'severity', values: ['DEBUG', 'INFO', 'WARN', 'ERROR']},
376
376
  {field: 'tabId'},
377
377
  {field: 'userAgent'},
378
378
  {field: 'username', displayName: 'User'},
@@ -17,6 +17,11 @@ export declare class View<T extends PlainObject = PlainObject> {
17
17
  * state of the components is captured.
18
18
  */
19
19
  readonly value: Partial<T>;
20
+ /**
21
+ * Defaulted to value, but may be updated during ViewManagerModel's settleTime to be
22
+ * the "settled" state after loading. Used for comparison to determine dirtiness.
23
+ */
24
+ settledValue: Partial<T>;
20
25
  private readonly model;
21
26
  get name(): string;
22
27
  get group(): string;
@@ -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;
@@ -27,6 +27,12 @@ export class View<T extends PlainObject = PlainObject> {
27
27
  */
28
28
  readonly value: Partial<T> = null;
29
29
 
30
+ /**
31
+ * Defaulted to value, but may be updated during ViewManagerModel's settleTime to be
32
+ * the "settled" state after loading. Used for comparison to determine dirtiness.
33
+ */
34
+ settledValue: Partial<T> = null;
35
+
30
36
  private readonly model: ViewManagerModel;
31
37
 
32
38
  get name(): string {
@@ -92,6 +98,7 @@ export class View<T extends PlainObject = PlainObject> {
92
98
  constructor(info: ViewInfo, value: Partial<T>, model: ViewManagerModel) {
93
99
  this.info = info;
94
100
  this.value = value;
101
+ this.settledValue = value;
95
102
  this.model = model;
96
103
  }
97
104
  }
@@ -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
 
@@ -421,13 +430,14 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
421
430
 
422
431
  @action
423
432
  setValue(value: Partial<T>) {
433
+ value = this.cleanState(value);
434
+
424
435
  const {view, pendingValue, lastPushed, settleTime} = this;
425
436
  if (!pendingValue && settleTime && !olderThan(lastPushed, settleTime)) {
426
- return;
437
+ this.view.settledValue = value;
427
438
  }
428
439
 
429
- value = this.cleanState(value);
430
- if (!isEqual(value, view.value)) {
440
+ if (!isEqual(value, view.settledValue)) {
431
441
  this.pendingValue = {
432
442
  token: pendingValue ? pendingValue.token : view.token,
433
443
  baseUpdated: pendingValue ? pendingValue.baseUpdated : view.lastUpdated,
@@ -438,6 +448,10 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
438
448
  }
439
449
  }
440
450
 
451
+ noteStatePushed() {
452
+ this.lastPushed = Date.now();
453
+ }
454
+
441
455
  //------------------
442
456
  // Pinning
443
457
  //------------------
@@ -515,7 +529,9 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
515
529
  this.views = views;
516
530
  this.userPinned = state.userPinned;
517
531
  this.autoSave = state.autoSave;
518
- this.pendingValue = XH.sessionStorageService.get(pendingValueStorageKey);
532
+ if (this.preserveUnsavedChanges) {
533
+ this.pendingValue = XH.sessionStorageService.get(pendingValueStorageKey);
534
+ }
519
535
  });
520
536
 
521
537
  // 2) Initialize/choose initial view. Null is ok, and will yield default.
@@ -546,7 +562,10 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
546
562
  private pendingValueReaction(): ReactionSpec {
547
563
  return {
548
564
  track: () => this.pendingValue,
549
- run: v => XH.sessionStorageService.set(this.pendingValueStorageKey, v)
565
+ run: v => {
566
+ if (!this.preserveUnsavedChanges) return;
567
+ XH.sessionStorageService.set(this.pendingValueStorageKey, v);
568
+ }
550
569
  };
551
570
  }
552
571
 
@@ -588,7 +607,6 @@ export class ViewManagerModel<T = PlainObject> extends HoistModel {
588
607
  .thenAction(latest => {
589
608
  this.setAsView(latest, pendingValue?.token == token ? pendingValue : null);
590
609
  this.providers.forEach(it => it.pushStateToTarget());
591
- this.lastPushed = Date.now();
592
610
  })
593
611
  .linkTo(this.selectTask);
594
612
  }
@@ -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.1748002015150",
3
+ "version": "74.0.0-SNAPSHOT.1748338432179",
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",