foldkit 0.8.0-canary.0 → 0.9.0-canary.0
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"addNavigationEventListeners.d.ts","sourceRoot":"","sources":["../../src/runtime/addNavigationEventListeners.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"addNavigationEventListeners.d.ts","sourceRoot":"","sources":["../../src/runtime/addNavigationEventListeners.ts"],"names":[],"mappings":"AAAA,OAAO,EAAU,KAAK,EAAU,MAAM,QAAQ,CAAA;AAI9C,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAA;AAGzC,eAAO,MAAM,2BAA2B,GAAI,OAAO,EACjD,cAAc,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,EAClC,eAAe,aAAa,CAAC,OAAO,CAAC,SAKtC,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Option, Queue, String } from 'effect';
|
|
2
2
|
import { OptionExt, StringExt } from '../effectExtensions';
|
|
3
3
|
import { External, Internal } from './urlRequest';
|
|
4
4
|
export const addNavigationEventListeners = (messageQueue, browserConfig) => {
|
|
@@ -25,39 +25,34 @@ const addPopStateListener = (messageQueue, browserConfig) => {
|
|
|
25
25
|
const addLinkClickListener = (messageQueue, browserConfig) => {
|
|
26
26
|
const onLinkClick = (event) => {
|
|
27
27
|
const target = event.target;
|
|
28
|
-
if (!target || !('closest' in target))
|
|
28
|
+
if (!target || !('closest' in target)) {
|
|
29
29
|
return;
|
|
30
|
+
}
|
|
30
31
|
/* eslint-disable-next-line @typescript-eslint/consistent-type-assertions */
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
32
|
+
const maybeLink = Option.fromNullable(target.closest('a'));
|
|
33
|
+
if (Option.isNone(maybeLink)) {
|
|
33
34
|
return;
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
}
|
|
36
|
+
const { href } = maybeLink.value;
|
|
37
|
+
if (String.isEmpty(href)) {
|
|
36
38
|
return;
|
|
37
|
-
|
|
39
|
+
}
|
|
40
|
+
event.preventDefault();
|
|
41
|
+
const linkUrl = new URL(href);
|
|
42
|
+
const currentUrl = new URL(window.location.href);
|
|
43
|
+
if (linkUrl.origin !== currentUrl.origin) {
|
|
38
44
|
Queue.unsafeOffer(messageQueue, browserConfig.onUrlRequest(External.make({ href })));
|
|
39
45
|
return;
|
|
40
46
|
}
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const search = pipe(searchPart, String.split('#'), Array.headNonEmpty, OptionExt.fromString);
|
|
51
|
-
const hash = pipe(href, String.split('#'), (hashParts) => Array.isNonEmptyArray(hashParts) && hashParts.length > 1 ? hashParts[1] : '', OptionExt.fromString);
|
|
52
|
-
return {
|
|
53
|
-
protocol: window.location.protocol,
|
|
54
|
-
host: window.location.host,
|
|
55
|
-
port: OptionExt.fromString(window.location.port),
|
|
56
|
-
pathname,
|
|
57
|
-
search,
|
|
58
|
-
hash,
|
|
59
|
-
};
|
|
60
|
-
});
|
|
47
|
+
const { protocol, host, port, pathname, search, hash } = linkUrl;
|
|
48
|
+
const url = {
|
|
49
|
+
protocol,
|
|
50
|
+
host,
|
|
51
|
+
port: OptionExt.fromString(port),
|
|
52
|
+
pathname,
|
|
53
|
+
search: StringExt.stripPrefixNonEmpty('?')(search),
|
|
54
|
+
hash: StringExt.stripPrefixNonEmpty('#')(hash),
|
|
55
|
+
};
|
|
61
56
|
Queue.unsafeOffer(messageQueue, browserConfig.onUrlRequest(Internal.make({ url })));
|
|
62
57
|
};
|
|
63
58
|
document.addEventListener('click', onLinkClick);
|
|
@@ -66,11 +61,12 @@ const addProgrammaticNavigationListener = (messageQueue, browserConfig) => {
|
|
|
66
61
|
const onProgrammaticNavigation = () => {
|
|
67
62
|
const search = StringExt.stripPrefixNonEmpty('?')(window.location.search);
|
|
68
63
|
const hash = StringExt.stripPrefixNonEmpty('#')(window.location.hash);
|
|
64
|
+
const { location: { protocol, host, port, pathname }, } = window;
|
|
69
65
|
const newUrl = {
|
|
70
|
-
protocol
|
|
71
|
-
host
|
|
72
|
-
port: OptionExt.fromString(
|
|
73
|
-
pathname
|
|
66
|
+
protocol,
|
|
67
|
+
host,
|
|
68
|
+
port: OptionExt.fromString(port),
|
|
69
|
+
pathname,
|
|
74
70
|
search,
|
|
75
71
|
hash,
|
|
76
72
|
};
|