@trebco/treb 27.11.1 → 27.11.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trebco/treb",
3
- "version": "27.11.1",
3
+ "version": "27.11.4",
4
4
  "license": "LGPL-3.0-or-later",
5
5
  "homepage": "https://treb.app",
6
6
  "repository": {
@@ -565,12 +565,33 @@ export class EmbeddedSpreadsheet {
565
565
  // this one should not be done for a split view, but we should still
566
566
  // do it if the toll flag is set, and storage key is set.
567
567
 
568
+ // FIXME: shouldn't this gate on dirty? (...)
569
+ // ALSO: check if we can use a different event. see
570
+ //
571
+ // https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event#usage_notes
572
+ //
573
+ // and, including the alternatives:
574
+ //
575
+ // https://developer.mozilla.org/en-US/docs/Web/API/Window/unload_event
576
+ //
577
+
568
578
  if (this.options.local_storage && !options.model ) {
579
+
580
+ window.addEventListener('visibilitychange', event => {
581
+ if (document.visibilityState === 'hidden') {
582
+ if (this.options.local_storage && this.dirty) {
583
+ this.SaveLocalStorage(this.options.local_storage);
584
+ }
585
+ }
586
+ });
587
+
588
+ /*
569
589
  window.addEventListener('beforeunload', () => {
570
- if (this.options.local_storage) {
590
+ if (this.options.local_storage && this.dirty) {
571
591
  this.SaveLocalStorage(this.options.local_storage);
572
592
  }
573
593
  });
594
+ */
574
595
  }
575
596
 
576
597
  let container: HTMLElement | undefined;
@@ -5077,9 +5098,27 @@ export class EmbeddedSpreadsheet {
5077
5098
 
5078
5099
  // console.info(json);
5079
5100
 
5101
+ // why are we saving this here? and should we not route
5102
+ // through the method? I guess the question should be, is
5103
+ // the visibilitychange handler not sufficient to save the
5104
+ // file? (...)
5105
+
5106
+ // I would prefer to just save once, on visibilitychange -> hidden.
5107
+ // the problem is that this method gets called on "data" events,
5108
+ // which should not trigger saving. we could check the flag?
5109
+
5110
+ // if this does come back, (1) use a method -- maybe split the
5111
+ // SaveLocalStorage method in two, and call the inner half (because
5112
+ // we've already serialized); and (2) gate on dirty.
5113
+
5114
+ // but for the time being we're removing it.
5115
+
5116
+ /*
5080
5117
  if (this.options.local_storage) {
5081
5118
  localStorage.setItem(this.options.local_storage, json);
5082
5119
  }
5120
+ */
5121
+
5083
5122
  if (this.options.undo) {
5084
5123
  this.PushUndo(json, undo_selection, false);
5085
5124
  }
@@ -90,6 +90,15 @@
90
90
  white-space: nowrap;
91
91
  position: relative;
92
92
  // -webkit-user-modify: read-write;
93
+
94
+ // this fixes the firefox issue (firefox removing spaces), but
95
+ // I'm not sure if it will cause other problems. for the overlay
96
+ // editor we're trapping CR, so it shouldn't be a typing problem --
97
+ // it might be an issue on paste though. also need to check safari
98
+ // with pre here.
99
+
100
+ white-space: pre;
101
+
93
102
  }
94
103
 
95
104
  /** fix for firefox layout bug */
@@ -1113,6 +1113,35 @@ export class Editor<E = FormulaEditorEvent> extends EventSource<E|FormulaEditorE
1113
1113
 
1114
1114
  const Consume = (element: Node, range: Range) => {
1115
1115
 
1116
+ // it only seems to happen in firefox, but sometimes we'll get
1117
+ // a non-text node that is the start container and endcontainer.
1118
+ //
1119
+ // in that case we need to interpret the endOffset as nodes, not
1120
+ // characters. that's what's causing the firefox issues. I guess
1121
+ // that applies to startoffset as well?
1122
+
1123
+ // not sure if this is bugged or what but when we hit this case,
1124
+ // it's always "all the text in there" regardless of the offsets.
1125
+ // not sure what the offsets are even referring to, since we get
1126
+ // offsets > the number of child nodes. is this a bug in firefox?
1127
+
1128
+ if (element === range.startContainer && element === range.endContainer && !(element instanceof Text)) {
1129
+
1130
+ /*
1131
+ if (range.startOffset !== 0 || range.endOffset !== 0) {
1132
+ console.info("warn offset", range.startOffset, range.endOffset);
1133
+ console.info(element);
1134
+ }
1135
+ */
1136
+
1137
+ complete[0] = complete[1] = true;
1138
+
1139
+ result[0] += element.textContent;
1140
+ result[1] += element.textContent;
1141
+
1142
+ return;
1143
+ }
1144
+
1116
1145
  if (element === range.startContainer) {
1117
1146
  result[0] += (element.textContent || '').substring(0, range.startOffset);
1118
1147
  complete[0] = true;