@palettelab/sdk 0.1.19 → 0.1.20

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/dist/index.js CHANGED
@@ -841,6 +841,21 @@ function currentSearchParams() {
841
841
  if (typeof window === "undefined") return new URLSearchParams();
842
842
  return new URLSearchParams(window.location.search);
843
843
  }
844
+ function preserveCurrentPreviewParams(path, pluginId) {
845
+ if (typeof window === "undefined" || !pluginId || /^https?:\/\//i.test(path)) return path;
846
+ const currentParams = new URLSearchParams(window.location.search);
847
+ const previewPublishId = currentParams.get("preview_publish_id");
848
+ const previewToken = currentParams.get("preview_token");
849
+ if (!previewPublishId || !previewToken) return path;
850
+ const [beforeHash, hash = ""] = path.split("#", 2);
851
+ const [pathname, query = ""] = beforeHash.split("?", 2);
852
+ if (pathname !== `/apps/${pluginId}` && !pathname.startsWith(`/apps/${pluginId}/`)) return path;
853
+ const params = new URLSearchParams(query);
854
+ params.set("preview_publish_id", previewPublishId);
855
+ params.set("preview_token", previewToken);
856
+ const serialized = params.toString();
857
+ return `${pathname}${serialized ? `?${serialized}` : ""}${hash ? `#${hash}` : ""}`;
858
+ }
844
859
  var PaletteRouteErrorBoundary = class extends import_react4.Component {
845
860
  constructor() {
846
861
  super(...arguments);
@@ -918,8 +933,9 @@ function PaletteAppRouter({
918
933
  const currentPath = typeof window === "undefined" ? "" : window.location.pathname;
919
934
  const inPalettePath = platform.pluginId && (currentPath.startsWith(`/apps/${platform.pluginId}`) || platform.routePath !== void 0);
920
935
  const osPath = inPalettePath && platform.pluginId ? `/apps/${platform.pluginId}${pathname === "/" ? "" : pathname}${queryPart ? `?${queryPart}` : ""}` : next;
921
- if (replace && typeof window !== "undefined") window.history.replaceState(null, "", osPath);
922
- else platform.navigate(osPath);
936
+ const preservedOsPath = preserveCurrentPreviewParams(osPath, platform.pluginId);
937
+ if (replace && typeof window !== "undefined") window.history.replaceState(null, "", preservedOsPath);
938
+ else platform.navigate(preservedOsPath);
923
939
  }, [platform]);
924
940
  const state = (0, import_react4.useMemo)(() => ({
925
941
  pathname: location.pathname,
package/dist/index.mjs CHANGED
@@ -782,6 +782,21 @@ function currentSearchParams() {
782
782
  if (typeof window === "undefined") return new URLSearchParams();
783
783
  return new URLSearchParams(window.location.search);
784
784
  }
785
+ function preserveCurrentPreviewParams(path, pluginId) {
786
+ if (typeof window === "undefined" || !pluginId || /^https?:\/\//i.test(path)) return path;
787
+ const currentParams = new URLSearchParams(window.location.search);
788
+ const previewPublishId = currentParams.get("preview_publish_id");
789
+ const previewToken = currentParams.get("preview_token");
790
+ if (!previewPublishId || !previewToken) return path;
791
+ const [beforeHash, hash = ""] = path.split("#", 2);
792
+ const [pathname, query = ""] = beforeHash.split("?", 2);
793
+ if (pathname !== `/apps/${pluginId}` && !pathname.startsWith(`/apps/${pluginId}/`)) return path;
794
+ const params = new URLSearchParams(query);
795
+ params.set("preview_publish_id", previewPublishId);
796
+ params.set("preview_token", previewToken);
797
+ const serialized = params.toString();
798
+ return `${pathname}${serialized ? `?${serialized}` : ""}${hash ? `#${hash}` : ""}`;
799
+ }
785
800
  var PaletteRouteErrorBoundary = class extends Component {
786
801
  constructor() {
787
802
  super(...arguments);
@@ -859,8 +874,9 @@ function PaletteAppRouter({
859
874
  const currentPath = typeof window === "undefined" ? "" : window.location.pathname;
860
875
  const inPalettePath = platform.pluginId && (currentPath.startsWith(`/apps/${platform.pluginId}`) || platform.routePath !== void 0);
861
876
  const osPath = inPalettePath && platform.pluginId ? `/apps/${platform.pluginId}${pathname === "/" ? "" : pathname}${queryPart ? `?${queryPart}` : ""}` : next;
862
- if (replace && typeof window !== "undefined") window.history.replaceState(null, "", osPath);
863
- else platform.navigate(osPath);
877
+ const preservedOsPath = preserveCurrentPreviewParams(osPath, platform.pluginId);
878
+ if (replace && typeof window !== "undefined") window.history.replaceState(null, "", preservedOsPath);
879
+ else platform.navigate(preservedOsPath);
864
880
  }, [platform]);
865
881
  const state = useMemo(() => ({
866
882
  pathname: location.pathname,
@@ -103,6 +103,21 @@ function currentSearchParams() {
103
103
  if (typeof window === "undefined") return new URLSearchParams();
104
104
  return new URLSearchParams(window.location.search);
105
105
  }
106
+ function preserveCurrentPreviewParams(path, pluginId) {
107
+ if (typeof window === "undefined" || !pluginId || /^https?:\/\//i.test(path)) return path;
108
+ const currentParams = new URLSearchParams(window.location.search);
109
+ const previewPublishId = currentParams.get("preview_publish_id");
110
+ const previewToken = currentParams.get("preview_token");
111
+ if (!previewPublishId || !previewToken) return path;
112
+ const [beforeHash, hash = ""] = path.split("#", 2);
113
+ const [pathname, query = ""] = beforeHash.split("?", 2);
114
+ if (pathname !== `/apps/${pluginId}` && !pathname.startsWith(`/apps/${pluginId}/`)) return path;
115
+ const params = new URLSearchParams(query);
116
+ params.set("preview_publish_id", previewPublishId);
117
+ params.set("preview_token", previewToken);
118
+ const serialized = params.toString();
119
+ return `${pathname}${serialized ? `?${serialized}` : ""}${hash ? `#${hash}` : ""}`;
120
+ }
106
121
  var PaletteRouteErrorBoundary = class extends import_react2.Component {
107
122
  constructor() {
108
123
  super(...arguments);
@@ -180,8 +195,9 @@ function PaletteAppRouter({
180
195
  const currentPath = typeof window === "undefined" ? "" : window.location.pathname;
181
196
  const inPalettePath = platform.pluginId && (currentPath.startsWith(`/apps/${platform.pluginId}`) || platform.routePath !== void 0);
182
197
  const osPath = inPalettePath && platform.pluginId ? `/apps/${platform.pluginId}${pathname === "/" ? "" : pathname}${queryPart ? `?${queryPart}` : ""}` : next;
183
- if (replace && typeof window !== "undefined") window.history.replaceState(null, "", osPath);
184
- else platform.navigate(osPath);
198
+ const preservedOsPath = preserveCurrentPreviewParams(osPath, platform.pluginId);
199
+ if (replace && typeof window !== "undefined") window.history.replaceState(null, "", preservedOsPath);
200
+ else platform.navigate(preservedOsPath);
185
201
  }, [platform]);
186
202
  const state = (0, import_react2.useMemo)(() => ({
187
203
  pathname: location.pathname,
@@ -82,6 +82,21 @@ function currentSearchParams() {
82
82
  if (typeof window === "undefined") return new URLSearchParams();
83
83
  return new URLSearchParams(window.location.search);
84
84
  }
85
+ function preserveCurrentPreviewParams(path, pluginId) {
86
+ if (typeof window === "undefined" || !pluginId || /^https?:\/\//i.test(path)) return path;
87
+ const currentParams = new URLSearchParams(window.location.search);
88
+ const previewPublishId = currentParams.get("preview_publish_id");
89
+ const previewToken = currentParams.get("preview_token");
90
+ if (!previewPublishId || !previewToken) return path;
91
+ const [beforeHash, hash = ""] = path.split("#", 2);
92
+ const [pathname, query = ""] = beforeHash.split("?", 2);
93
+ if (pathname !== `/apps/${pluginId}` && !pathname.startsWith(`/apps/${pluginId}/`)) return path;
94
+ const params = new URLSearchParams(query);
95
+ params.set("preview_publish_id", previewPublishId);
96
+ params.set("preview_token", previewToken);
97
+ const serialized = params.toString();
98
+ return `${pathname}${serialized ? `?${serialized}` : ""}${hash ? `#${hash}` : ""}`;
99
+ }
85
100
  var PaletteRouteErrorBoundary = class extends Component {
86
101
  constructor() {
87
102
  super(...arguments);
@@ -159,8 +174,9 @@ function PaletteAppRouter({
159
174
  const currentPath = typeof window === "undefined" ? "" : window.location.pathname;
160
175
  const inPalettePath = platform.pluginId && (currentPath.startsWith(`/apps/${platform.pluginId}`) || platform.routePath !== void 0);
161
176
  const osPath = inPalettePath && platform.pluginId ? `/apps/${platform.pluginId}${pathname === "/" ? "" : pathname}${queryPart ? `?${queryPart}` : ""}` : next;
162
- if (replace && typeof window !== "undefined") window.history.replaceState(null, "", osPath);
163
- else platform.navigate(osPath);
177
+ const preservedOsPath = preserveCurrentPreviewParams(osPath, platform.pluginId);
178
+ if (replace && typeof window !== "undefined") window.history.replaceState(null, "", preservedOsPath);
179
+ else platform.navigate(preservedOsPath);
164
180
  }, [platform]);
165
181
  const state = useMemo(() => ({
166
182
  pathname: location.pathname,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@palettelab/sdk",
3
- "version": "0.1.19",
3
+ "version": "0.1.20",
4
4
  "description": "Palette Platform SDK for building plugins and apps",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",