@shoppexio/builder-runtime 0.1.3 → 0.1.4

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": "@shoppexio/builder-runtime",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Theme-side Builder v2 runtime helpers for Shoppex storefront themes",
5
5
  "type": "module",
6
6
  "repository": {
@@ -0,0 +1,22 @@
1
+ import { afterEach, describe, expect, test } from 'bun:test';
2
+ import { isBuilderPreviewMode } from './preview-mode.js';
3
+
4
+ describe('isBuilderPreviewMode', () => {
5
+ const previousWindow = globalThis.window;
6
+
7
+ afterEach(() => {
8
+ globalThis.window = previousWindow;
9
+ });
10
+
11
+ test('returns false during SSR without touching window.location', () => {
12
+ delete (globalThis as { window?: Window }).window;
13
+
14
+ expect(isBuilderPreviewMode()).toBe(false);
15
+ });
16
+
17
+ test('reads the provided location search params', () => {
18
+ expect(isBuilderPreviewMode({ search: '?shoppex-preview-mode=builder' })).toBe(true);
19
+ expect(isBuilderPreviewMode({ search: '?shoppex-preview-mode=theme' })).toBe(true);
20
+ expect(isBuilderPreviewMode({ search: '?shoppex-preview-mode=live' })).toBe(false);
21
+ });
22
+ });
@@ -1,8 +1,8 @@
1
- export function isBuilderPreviewMode(location: Pick<Location, 'search'> = window.location): boolean {
1
+ export function isBuilderPreviewMode(location?: Pick<Location, 'search'>): boolean {
2
2
  if (typeof window === 'undefined') {
3
3
  return false;
4
4
  }
5
5
 
6
- const mode = new URLSearchParams(location.search).get('shoppex-preview-mode');
6
+ const mode = new URLSearchParams((location ?? window.location).search).get('shoppex-preview-mode');
7
7
  return mode === 'theme' || mode === 'builder';
8
8
  }