@shellui/sdk 0.0.2 → 0.0.3
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 +1 -1
- package/src/index.js +15 -1
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -6,7 +6,10 @@
|
|
|
6
6
|
class ShellUISDK {
|
|
7
7
|
constructor() {
|
|
8
8
|
this.initialized = false;
|
|
9
|
-
|
|
9
|
+
// Don't access window in constructor - it may not exist during SSR
|
|
10
|
+
this.currentPath = typeof window !== 'undefined'
|
|
11
|
+
? window.location.pathname + window.location.search + window.location.hash
|
|
12
|
+
: '';
|
|
10
13
|
this.version = '0.0.1';
|
|
11
14
|
}
|
|
12
15
|
|
|
@@ -31,6 +34,11 @@ class ShellUISDK {
|
|
|
31
34
|
* Sets up listeners for various URL change events
|
|
32
35
|
*/
|
|
33
36
|
setupUrlMonitoring() {
|
|
37
|
+
// Guard against SSR - window and document may not exist
|
|
38
|
+
if (typeof window === 'undefined' || typeof document === 'undefined') {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
34
42
|
// Listen for popstate (back/forward buttons)
|
|
35
43
|
window.addEventListener('popstate', () => this.handleUrlChange());
|
|
36
44
|
|
|
@@ -63,6 +71,9 @@ class ShellUISDK {
|
|
|
63
71
|
}
|
|
64
72
|
|
|
65
73
|
handleUrlChange() {
|
|
74
|
+
if (typeof window === 'undefined') {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
66
77
|
const newPath = window.location.pathname + window.location.search + window.location.hash;
|
|
67
78
|
if (newPath !== this.currentPath) {
|
|
68
79
|
this.currentPath = newPath;
|
|
@@ -74,6 +85,9 @@ class ShellUISDK {
|
|
|
74
85
|
* Sends a message to the parent frame with the current path information
|
|
75
86
|
*/
|
|
76
87
|
notifyParent() {
|
|
88
|
+
if (typeof window === 'undefined') {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
77
91
|
const message = {
|
|
78
92
|
type: 'SHELLUI_URL_CHANGED',
|
|
79
93
|
payload: {
|