astro-tractstack 2.0.42 → 2.0.43

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": "astro-tractstack",
3
- "version": "2.0.42",
3
+ "version": "2.0.43",
4
4
  "description": "Astro integration for TractStack - redeeming the web from boring experiences",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -34,7 +34,6 @@ const {
34
34
  } = Astro.props;
35
35
 
36
36
  const isHome = slug === brandConfig?.HOME_SLUG;
37
- console.log(slug, isHome);
38
37
 
39
38
  const tenantId =
40
39
  Astro.locals.tenant?.id || import.meta.env.PUBLIC_TENANTID || 'default';
@@ -46,30 +46,32 @@ const mainStylesUrl = isDev
46
46
  )
47
47
  }
48
48
 
49
- <script>
50
- (function initCleanSlate() {
51
- try {
52
- document.cookie =
53
- 'admin_auth=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax';
54
- document.cookie =
55
- 'editor_auth=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax';
56
- document.cookie =
57
- 'tractstack_session_id=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax';
49
+ <script is:inline>
50
+ if (typeof document !== 'undefined') {
51
+ (function initCleanSlate() {
52
+ try {
53
+ document.cookie =
54
+ 'admin_auth=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax';
55
+ document.cookie =
56
+ 'editor_auth=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax';
57
+ document.cookie =
58
+ 'tractstack_session_id=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT; SameSite=Lax';
58
59
 
59
- const tractStackKeys = [];
60
- for (let i = 0; i < localStorage.length; i++) {
61
- const key = localStorage.key(i);
62
- if (key && key.startsWith('tractstack_')) {
63
- tractStackKeys.push(key);
60
+ const tractStackKeys = [];
61
+ for (let i = 0; i < localStorage.length; i++) {
62
+ const key = localStorage.key(i);
63
+ if (key && key.startsWith('tractstack_')) {
64
+ tractStackKeys.push(key);
65
+ }
64
66
  }
65
- }
66
- tractStackKeys.forEach((key) => localStorage.removeItem(key));
67
+ tractStackKeys.forEach((key) => localStorage.removeItem(key));
67
68
 
68
- console.log('TractStack: Clean slate initialization complete');
69
- } catch (error) {
70
- console.warn('TractStack: Error during clean slate init:', error);
71
- }
72
- })();
69
+ console.log('TractStack: Clean slate initialization complete');
70
+ } catch (error) {
71
+ console.warn('TractStack: Error during clean slate init:', error);
72
+ }
73
+ })();
74
+ }
73
75
  </script>
74
76
  </body>
75
77
  </html>
@@ -21,16 +21,18 @@ function cleanupLayoutObservers() {
21
21
  settingsPanelSubscription();
22
22
  settingsPanelSubscription = null;
23
23
  }
24
- if (debouncedUpdateListener) {
24
+ if (debouncedUpdateListener && typeof window !== `undefined`) {
25
25
  window.removeEventListener('scroll', debouncedUpdateListener);
26
26
  window.removeEventListener('resize', debouncedUpdateListener);
27
27
  debouncedUpdateListener = null;
28
28
  }
29
- const storykeepHeader = document.getElementById('storykeepHeader');
30
- if (storykeepHeader) {
31
- document.body.style.paddingTop = '';
32
- storykeepHeader.style.position = '';
33
- storykeepHeader.style.top = '';
29
+ if (typeof document !== `undefined`) {
30
+ const storykeepHeader = document.getElementById('storykeepHeader');
31
+ if (storykeepHeader) {
32
+ document.body.style.paddingTop = '';
33
+ storykeepHeader.style.position = '';
34
+ storykeepHeader.style.top = '';
35
+ }
34
36
  }
35
37
  }
36
38
 
@@ -45,7 +47,7 @@ function setupPaneObserver() {
45
47
  currentPaneObserver = null;
46
48
  }
47
49
 
48
- if (signalValue && signalValue.nodeId) {
50
+ if (signalValue && signalValue.nodeId && typeof document !== `undefined`) {
49
51
  setTimeout(() => {
50
52
  const { nodeId } = signalValue;
51
53
 
@@ -77,84 +79,92 @@ function setupPaneObserver() {
77
79
  export function setupLayoutObservers(): void {
78
80
  cleanupLayoutObservers();
79
81
 
80
- const storykeepHeader = document.getElementById('storykeepHeader');
81
- const settingsControls = document.getElementById('settingsControls');
82
- const standardHeader = document.querySelector('header');
83
-
84
- if (!storykeepHeader || !settingsControls || !standardHeader) return;
85
-
86
- let standardHeaderHeight = 0;
87
- const updateStandardHeaderHeight = () => {
88
- standardHeaderHeight = standardHeader.offsetHeight;
89
- };
90
-
91
- const updatePanelPosition = () => {
92
- const headerRect = storykeepHeader.getBoundingClientRect();
93
- const panelTop = headerRect.bottom;
94
- settingsControls.style.top = `${panelTop}px`;
95
- };
96
-
97
- const handleScroll = () => {
98
- const scrollY = window.scrollY;
99
- const shouldBeSticky = scrollY > standardHeaderHeight;
100
- const currentPosition = headerPositionStore.get();
101
- const newPosition = shouldBeSticky ? 'sticky' : 'normal';
102
-
103
- if (currentPosition !== newPosition) {
104
- setHeaderPosition(newPosition);
105
- if (shouldBeSticky) {
106
- document.body.style.paddingTop = `${storykeepHeader.offsetHeight}px`;
107
- storykeepHeader.style.position = 'fixed';
108
- storykeepHeader.style.top = '0';
109
- } else {
110
- document.body.style.paddingTop = '';
111
- storykeepHeader.style.position = '';
112
- storykeepHeader.style.top = '';
82
+ if (typeof document !== `undefined` || typeof window !== `undefined`) {
83
+ const storykeepHeader = document.getElementById('storykeepHeader');
84
+ const settingsControls = document.getElementById('settingsControls');
85
+ const standardHeader = document.querySelector('header');
86
+
87
+ if (!storykeepHeader || !settingsControls || !standardHeader) return;
88
+
89
+ let standardHeaderHeight = 0;
90
+ const updateStandardHeaderHeight = () => {
91
+ standardHeaderHeight = standardHeader.offsetHeight;
92
+ };
93
+
94
+ const updatePanelPosition = () => {
95
+ const headerRect = storykeepHeader.getBoundingClientRect();
96
+ const panelTop = headerRect.bottom;
97
+ settingsControls.style.top = `${panelTop}px`;
98
+ };
99
+
100
+ const handleScroll = () => {
101
+ const scrollY = window.scrollY;
102
+ const shouldBeSticky = scrollY > standardHeaderHeight;
103
+ const currentPosition = headerPositionStore.get();
104
+ const newPosition = shouldBeSticky ? 'sticky' : 'normal';
105
+
106
+ if (currentPosition !== newPosition) {
107
+ setHeaderPosition(newPosition);
108
+ if (shouldBeSticky) {
109
+ document.body.style.paddingTop = `${storykeepHeader.offsetHeight}px`;
110
+ storykeepHeader.style.position = 'fixed';
111
+ storykeepHeader.style.top = '0';
112
+ } else {
113
+ document.body.style.paddingTop = '';
114
+ storykeepHeader.style.position = '';
115
+ storykeepHeader.style.top = '';
116
+ }
113
117
  }
114
- }
115
- };
118
+ };
116
119
 
117
- debouncedUpdateListener = debounce(() => {
118
- updateStandardHeaderHeight();
119
- handleScroll();
120
- updatePanelPosition();
121
- }, 50);
120
+ debouncedUpdateListener = debounce(() => {
121
+ updateStandardHeaderHeight();
122
+ handleScroll();
123
+ updatePanelPosition();
124
+ }, 50);
122
125
 
123
- const handleSettingsPanelChange = () => {
124
- if (!settingsPanelOpenStore.get()) {
125
- hasScrolledForSettingsPanel = false;
126
- }
127
- };
126
+ const handleSettingsPanelChange = () => {
127
+ if (!settingsPanelOpenStore.get()) {
128
+ hasScrolledForSettingsPanel = false;
129
+ }
130
+ };
128
131
 
129
- window.addEventListener('scroll', debouncedUpdateListener, { passive: true });
130
- window.addEventListener('resize', debouncedUpdateListener);
131
- settingsPanelOpenStore.subscribe(handleSettingsPanelChange);
132
+ window.addEventListener('scroll', debouncedUpdateListener, {
133
+ passive: true,
134
+ });
135
+ window.addEventListener('resize', debouncedUpdateListener);
136
+ settingsPanelOpenStore.subscribe(handleSettingsPanelChange);
132
137
 
133
- setupPaneObserver();
138
+ setupPaneObserver();
134
139
 
135
- updateStandardHeaderHeight();
136
- handleScroll();
137
- updatePanelPosition();
140
+ updateStandardHeaderHeight();
141
+ handleScroll();
142
+ updatePanelPosition();
143
+ }
138
144
  }
139
145
 
140
146
  export function handleSettingsPanelMobile(isOpen: boolean): void {
141
- const isMobile = window.innerWidth < 801;
142
- if (!isMobile) return;
143
-
144
- if (isOpen) {
145
- const header = document.querySelector('header');
146
- const headerHeight = header?.offsetHeight || 0;
147
- const currentScrollY = window.scrollY;
148
-
149
- if (currentScrollY <= headerHeight && !hasScrolledForSettingsPanel) {
150
- window.scrollTo({ top: headerHeight + 10, behavior: 'smooth' });
151
- hasScrolledForSettingsPanel = true;
147
+ if (typeof window !== `undefined` && typeof document !== `undefined`) {
148
+ const isMobile = window.innerWidth < 801;
149
+ if (!isMobile) return;
150
+
151
+ if (isOpen) {
152
+ const header = document.querySelector('header');
153
+ const headerHeight = header?.offsetHeight || 0;
154
+ const currentScrollY = window.scrollY;
155
+
156
+ if (currentScrollY <= headerHeight && !hasScrolledForSettingsPanel) {
157
+ window.scrollTo({ top: headerHeight + 10, behavior: 'smooth' });
158
+ hasScrolledForSettingsPanel = true;
159
+ }
160
+ setMobileHeaderFaded(true);
161
+ } else {
162
+ setMobileHeaderFaded(false);
163
+ hasScrolledForSettingsPanel = false;
152
164
  }
153
- setMobileHeaderFaded(true);
154
- } else {
155
- setMobileHeaderFaded(false);
156
- hasScrolledForSettingsPanel = false;
157
165
  }
158
166
  }
159
167
 
160
- document.addEventListener('astro:before-swap', cleanupLayoutObservers);
168
+ if (typeof document !== `undefined`) {
169
+ document.addEventListener('astro:before-swap', cleanupLayoutObservers);
170
+ }