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 +4 -4
- data/app/assets/javascripts/hotwire-livereload-turbo-stream.js +27 -0
- data/app/assets/javascripts/hotwire-livereload.js +29 -36
- data/app/javascript/hotwire-livereload.js +4 -18
- data/app/javascript/lib/hotwire-livereload-received.js +2 -0
- data/app/javascript/lib/hotwire-livereload-scroll-position.js +9 -6
- data/lib/hotwire/livereload/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 42f6430166f2bcdcb52940e92965a5e1d202c57b09966ddb72f76b746918b473
|
4
|
+
data.tar.gz: be8743a9b6cbced10614d8fb4fc9cae8306c4355648175a91ed716a763722453
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
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
|
-
|
657
|
-
module.exports =
|
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
|
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
|
690
|
-
localStorage.
|
679
|
+
function remove() {
|
680
|
+
localStorage.removeItem(KEY);
|
691
681
|
}
|
692
682
|
function restore() {
|
693
683
|
const value = read();
|
694
|
-
|
695
|
-
|
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,
|
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
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
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
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
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
|
15
|
-
localStorage.
|
14
|
+
export function remove() {
|
15
|
+
localStorage.removeItem(KEY)
|
16
16
|
}
|
17
17
|
|
18
18
|
export function restore() {
|
19
19
|
const value = read()
|
20
|
-
|
21
|
-
|
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,
|
27
|
+
export default { read, save, restore, remove }
|
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.
|
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:
|
11
|
+
date: 2024-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|