hotwire-livereload 1.3.0 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 588323a498a0f2aa7b4ebb53c417b0f937b3d9df5e06af8ec4039e26f35de0c9
4
- data.tar.gz: 15c0688010ad47a244cbcf4c1bb543ce199f5ba9f73b822228b9d5aafe71c5b0
3
+ metadata.gz: 42f6430166f2bcdcb52940e92965a5e1d202c57b09966ddb72f76b746918b473
4
+ data.tar.gz: be8743a9b6cbced10614d8fb4fc9cae8306c4355648175a91ed716a763722453
5
5
  SHA512:
6
- metadata.gz: c4389aeae81c93d5f9ec646748e587a084bebf0993173bce97bf3629f81dd1c8763d31635729218b0e2631b5529a16e2d63403c696301f24c9a788d84aa6c5fc
7
- data.tar.gz: 429fb41ac85243a1dd9aa0b7f5461b189e10f06f98e5547af125f65996026b4ea44ea1ceceb8c0dbe07ce297091438490d257b51b0e7f9319e0e7e7a80bbf6f2
6
+ metadata.gz: 909b0a55ec3d9d4dcbb0f7536e72c380a2d2d8e885cc5d988fe64f91771b759a2809d65f3fad8e500e565a51620532ae1b43c338880c7da977f396852f3b2d6b
7
+ data.tar.gz: 90116c0e4b698346603d398cc3a4c7dd6616403f6caae041a014251ea24f57a5e36f83bc6e8554d1c65b21e36e92592c9a583f2f14ca042f357a7d324ecbff8d
@@ -81,6 +81,32 @@
81
81
 
82
82
  // app/javascript/lib/hotwire-livereload-received.js
83
83
  var import_debounce = __toESM(require_debounce());
84
+
85
+ // app/javascript/lib/hotwire-livereload-scroll-position.js
86
+ var KEY = "hotwire-livereload-scrollPosition";
87
+ function read() {
88
+ const value = localStorage.getItem(KEY);
89
+ if (!value)
90
+ return;
91
+ return parseInt(value);
92
+ }
93
+ function save() {
94
+ const pos = window.scrollY;
95
+ localStorage.setItem(KEY, pos.toString());
96
+ }
97
+ function remove() {
98
+ localStorage.removeItem(KEY);
99
+ }
100
+ function restore() {
101
+ const value = read();
102
+ if (value) {
103
+ console.log("[Hotwire::Livereload] Restoring scroll position to", value);
104
+ window.scrollTo(0, value);
105
+ }
106
+ }
107
+ var hotwire_livereload_scroll_position_default = { read, save, restore, remove };
108
+
109
+ // app/javascript/lib/hotwire-livereload-received.js
84
110
  var hotwire_livereload_received_default = (0, import_debounce.default)(({ force_reload }) => {
85
111
  const onErrorPage = document.title === "Action Controller: Exception caught";
86
112
  if (onErrorPage || force_reload) {
@@ -88,6 +114,7 @@
88
114
  document.location.reload();
89
115
  } else {
90
116
  console.log("[Hotwire::Livereload] Files changed. Reloading..");
117
+ hotwire_livereload_scroll_position_default.save();
91
118
  Turbo.visit(window.location.href, { action: "replace" });
92
119
  }
93
120
  }, 300);
@@ -453,7 +453,7 @@
453
453
  this.subscribe(subscription);
454
454
  return subscription;
455
455
  };
456
- Subscriptions2.prototype.remove = function remove(subscription) {
456
+ Subscriptions2.prototype.remove = function remove2(subscription) {
457
457
  this.forget(subscription);
458
458
  if (!this.findAll(subscription.identifier).length) {
459
459
  this.sendCommand(subscription, "unsubscribe");
@@ -607,7 +607,7 @@
607
607
  // node_modules/debounce/index.js
608
608
  var require_debounce = __commonJS({
609
609
  "node_modules/debounce/index.js"(exports, module) {
610
- function debounce3(func, wait, immediate) {
610
+ function debounce2(func, wait, immediate) {
611
611
  var timeout, args, context, timestamp, result;
612
612
  if (null == wait)
613
613
  wait = 100;
@@ -653,8 +653,8 @@
653
653
  };
654
654
  return debounced;
655
655
  }
656
- debounce3.debounce = debounce3;
657
- module.exports = debounce3;
656
+ debounce2.debounce = debounce2;
657
+ module.exports = debounce2;
658
658
  }
659
659
  });
660
660
 
@@ -663,41 +663,45 @@
663
663
 
664
664
  // app/javascript/lib/hotwire-livereload-received.js
665
665
  var import_debounce = __toESM(require_debounce());
666
- var hotwire_livereload_received_default = (0, import_debounce.default)(({ force_reload }) => {
667
- const onErrorPage = document.title === "Action Controller: Exception caught";
668
- if (onErrorPage || force_reload) {
669
- console.log("[Hotwire::Livereload] Files changed. Force reloading..");
670
- document.location.reload();
671
- } else {
672
- console.log("[Hotwire::Livereload] Files changed. Reloading..");
673
- Turbo.visit(window.location.href, { action: "replace" });
674
- }
675
- }, 300);
676
666
 
677
667
  // app/javascript/lib/hotwire-livereload-scroll-position.js
678
668
  var KEY = "hotwire-livereload-scrollPosition";
679
669
  function read() {
680
670
  const value = localStorage.getItem(KEY);
681
671
  if (!value)
682
- return 0;
672
+ return;
683
673
  return parseInt(value);
684
674
  }
685
675
  function save() {
686
676
  const pos = window.scrollY;
687
677
  localStorage.setItem(KEY, pos.toString());
688
678
  }
689
- function reset() {
690
- localStorage.setItem(KEY, "0");
679
+ function remove() {
680
+ localStorage.removeItem(KEY);
691
681
  }
692
682
  function restore() {
693
683
  const value = read();
694
- console.log("[Hotwire::Livereload] Restoring scroll position to", value);
695
- window.scrollTo(0, value);
684
+ if (value) {
685
+ console.log("[Hotwire::Livereload] Restoring scroll position to", value);
686
+ window.scrollTo(0, value);
687
+ }
696
688
  }
697
- var hotwire_livereload_scroll_position_default = { read, save, restore, reset };
689
+ var hotwire_livereload_scroll_position_default = { read, save, restore, remove };
690
+
691
+ // app/javascript/lib/hotwire-livereload-received.js
692
+ var hotwire_livereload_received_default = (0, import_debounce.default)(({ force_reload }) => {
693
+ const onErrorPage = document.title === "Action Controller: Exception caught";
694
+ if (onErrorPage || force_reload) {
695
+ console.log("[Hotwire::Livereload] Files changed. Force reloading..");
696
+ document.location.reload();
697
+ } else {
698
+ console.log("[Hotwire::Livereload] Files changed. Reloading..");
699
+ hotwire_livereload_scroll_position_default.save();
700
+ Turbo.visit(window.location.href, { action: "replace" });
701
+ }
702
+ }, 300);
698
703
 
699
704
  // app/javascript/hotwire-livereload.js
700
- var import_debounce2 = __toESM(require_debounce());
701
705
  var consumer = (0, import_actioncable.createConsumer)();
702
706
  consumer.subscriptions.create("Hotwire::Livereload::ReloadChannel", {
703
707
  received: hotwire_livereload_received_default,
@@ -708,19 +712,8 @@
708
712
  console.log("[Hotwire::Livereload] Websocket disconnected");
709
713
  }
710
714
  });
711
- var debouncedScroll = (0, import_debounce2.default)(() => {
712
- if (window.scrollY !== 0)
713
- return hotwire_livereload_scroll_position_default.save();
714
- setTimeout(() => {
715
- if (window.scrollY !== 0)
716
- return;
717
- hotwire_livereload_scroll_position_default.save();
718
- }, 1e3);
719
- }, 100);
720
- window.addEventListener("scroll", debouncedScroll);
721
- document.addEventListener("turbo:click", hotwire_livereload_scroll_position_default.reset);
722
- document.addEventListener("turbo:before-visit", hotwire_livereload_scroll_position_default.restore);
723
- document.addEventListener("turbo:load", hotwire_livereload_scroll_position_default.restore);
724
- document.addEventListener("DOMContentLoaded", hotwire_livereload_scroll_position_default.restore);
725
- document.addEventListener("turbo:frame-load", hotwire_livereload_scroll_position_default.restore);
715
+ document.addEventListener("turbo:load", () => {
716
+ hotwire_livereload_scroll_position_default.restore();
717
+ hotwire_livereload_scroll_position_default.remove();
718
+ });
726
719
  })();
@@ -1,7 +1,6 @@
1
1
  import { createConsumer } from "@rails/actioncable"
2
2
  import received from "./lib/hotwire-livereload-received"
3
3
  import scrollPosition from "./lib/hotwire-livereload-scroll-position"
4
- import debounce from "debounce"
5
4
 
6
5
  const consumer = createConsumer()
7
6
  consumer.subscriptions.create("Hotwire::Livereload::ReloadChannel", {
@@ -16,21 +15,8 @@ consumer.subscriptions.create("Hotwire::Livereload::ReloadChannel", {
16
15
  },
17
16
  })
18
17
 
19
- const debouncedScroll = debounce(() => {
20
- if (window.scrollY !== 0) return scrollPosition.save();
21
-
22
- // On a second update, the page mysteriously jumps to the top and sends a scroll event.
23
- // So we wait a bit and if the page is still is at the top, it was likely on purpose.
24
- setTimeout(() => {
25
- if (window.scrollY !== 0) return;
26
- scrollPosition.save();
27
- }, 1000);
28
- }, 100)
29
- window.addEventListener("scroll", debouncedScroll)
30
-
31
- document.addEventListener("turbo:click", scrollPosition.reset)
32
- document.addEventListener("turbo:before-visit", scrollPosition.restore)
33
- document.addEventListener("turbo:load", scrollPosition.restore)
34
- document.addEventListener("DOMContentLoaded", scrollPosition.restore)
35
- document.addEventListener("turbo:frame-load", scrollPosition.restore)
18
+ document.addEventListener("turbo:load", () => {
19
+ scrollPosition.restore()
20
+ scrollPosition.remove()
21
+ })
36
22
 
@@ -1,4 +1,5 @@
1
1
  import debounce from "debounce"
2
+ import scrollPosition from "./hotwire-livereload-scroll-position"
2
3
 
3
4
  export default debounce(({force_reload}) => {
4
5
  const onErrorPage = document.title === "Action Controller: Exception caught"
@@ -8,6 +9,7 @@ export default debounce(({force_reload}) => {
8
9
  document.location.reload()
9
10
  } else {
10
11
  console.log("[Hotwire::Livereload] Files changed. Reloading..")
12
+ scrollPosition.save()
11
13
  Turbo.visit(window.location.href, { action: 'replace' })
12
14
  }
13
15
  }, 300)
@@ -2,7 +2,7 @@ const KEY = "hotwire-livereload-scrollPosition"
2
2
 
3
3
  export function read() {
4
4
  const value = localStorage.getItem(KEY)
5
- if (!value) return 0;
5
+ if (!value) return
6
6
  return parseInt(value)
7
7
  }
8
8
 
@@ -11,14 +11,17 @@ export function save() {
11
11
  localStorage.setItem(KEY, pos.toString())
12
12
  }
13
13
 
14
- export function reset() {
15
- localStorage.setItem(KEY, "0");
14
+ export function remove() {
15
+ localStorage.removeItem(KEY)
16
16
  }
17
17
 
18
18
  export function restore() {
19
19
  const value = read()
20
- console.log("[Hotwire::Livereload] Restoring scroll position to", value)
21
- window.scrollTo(0, value)
20
+ if (value) {
21
+ console.log("[Hotwire::Livereload] Restoring scroll position to", value)
22
+ window.scrollTo(0, value)
23
+ }
24
+
22
25
  }
23
26
 
24
- export default { read, save, restore, reset }
27
+ export default { read, save, restore, remove }
@@ -1,5 +1,5 @@
1
1
  module Hotwire
2
2
  module Livereload
3
- VERSION = "1.3.0"
3
+ VERSION = "1.3.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hotwire-livereload
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Platonov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-11 00:00:00.000000000 Z
11
+ date: 2024-01-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties