@noya-app/noya-multiplayer-react 0.1.89 → 0.2.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.
@@ -26,6 +26,34 @@ it("gets AppData with no data", () => {
26
26
  });
27
27
  });
28
28
 
29
+ it("enables the inspector from a direct hash parameter", () => {
30
+ const data = getAppData({ foo: "bar" }, undefined, {
31
+ window: { location: { hash: "#inspector=true" } },
32
+ });
33
+
34
+ expect(data.inspector).toBe(true);
35
+ });
36
+
37
+ it("lets an explicit hash parameter override embedded inspector data", () => {
38
+ const existing = {
39
+ theme: "light",
40
+ viewType: "editable",
41
+ initialState: { foo: "bar" },
42
+ inspector: true,
43
+ };
44
+ const data = getAppData(null as unknown, undefined, {
45
+ window: {
46
+ location: {
47
+ hash: `#data=${encodeURIComponent(
48
+ JSON.stringify(existing)
49
+ )}&inspector=false`,
50
+ },
51
+ },
52
+ });
53
+
54
+ expect(data.inspector).toBe(false);
55
+ });
56
+
29
57
  it("gets AppData with data param", () => {
30
58
  const existing = {
31
59
  theme: "light",
package/src/noyaApp.ts CHANGED
@@ -92,6 +92,19 @@ export function parseAppDataParameter(
92
92
  }
93
93
  }
94
94
 
95
+ export function parseInspectorParameter(
96
+ options?: GetAppDataOptions
97
+ ): boolean | null {
98
+ const window = options?.window ?? globalThis;
99
+ const location = window.location;
100
+ if (!location) return null;
101
+ const params = new URLSearchParams((location.hash || "").replace(/^#/, ""));
102
+ const inspector = params.get("inspector");
103
+ if (inspector === "true") return true;
104
+ if (inspector === "false") return false;
105
+ return null;
106
+ }
107
+
95
108
  function applyClientIdentityFromAppData(appData: {
96
109
  clientId?: string;
97
110
  clientName?: string;
@@ -121,6 +134,8 @@ export function getAppData<State>(
121
134
  let appData =
122
135
  parseAppDataParameter(options) ??
123
136
  createDefaultAppData(resolvedInitialState);
137
+ const inspector = parseInspectorParameter(options);
138
+ if (inspector !== null) appData.inspector = inspector;
124
139
 
125
140
  if (options?.overrideExistingState || appData.initialState === null) {
126
141
  appData.initialState = resolvedInitialState;