@noya-app/noya-multiplayer-react 0.1.9 → 0.1.11

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.
@@ -39,10 +39,12 @@ function ToggleButton({
39
39
  showInspector,
40
40
  setShowInspector,
41
41
  theme,
42
+ anchor,
42
43
  }: {
43
44
  showInspector: boolean;
44
45
  setShowInspector: (value: boolean) => void;
45
46
  theme: typeof chromeLight;
47
+ anchor: Anchor;
46
48
  }) {
47
49
  return (
48
50
  <span
@@ -51,7 +53,6 @@ function ToggleButton({
51
53
  flex: "0",
52
54
  appearance: "none",
53
55
  color: theme.BASE_COLOR,
54
- background: "rgba(0,0,0,0.1)",
55
56
  border: "none",
56
57
  fontSize: "12px",
57
58
  whiteSpace: "nowrap",
@@ -63,7 +64,7 @@ function ToggleButton({
63
64
  onClick={() => setShowInspector(!showInspector)}
64
65
  >
65
66
  <span style={{ width: "12px", height: "12px" }}>
66
- {showInspector ? (
67
+ {showInspector === (anchor === "right") ? (
67
68
  <svg
68
69
  xmlns="http://www.w3.org/2000/svg"
69
70
  fill="none"
@@ -136,6 +137,7 @@ function DisclosureSection({
136
137
  fontSize: "12px",
137
138
  padding: "4px 10px",
138
139
  display: "flex",
140
+ alignItems: "center",
139
141
  ...(!isFirst && { borderTop: `1px solid ${borderColor}` }),
140
142
  ...(open && { borderBottom: `1px solid ${borderColor}` }),
141
143
  }}
@@ -144,9 +146,8 @@ function DisclosureSection({
144
146
  <Arrow
145
147
  expanded={open}
146
148
  style={{
147
- fontSize: "11px",
148
- // fontSize: theme.ARROW_FONT_SIZE,
149
- marginRight: theme.ARROW_MARGIN_RIGHT,
149
+ fontSize: theme.ARROW_FONT_SIZE,
150
+ marginRight: theme.ARROW_MARGIN_RIGHT + 1,
150
151
  color: theme.ARROW_COLOR,
151
152
  }}
152
153
  />
@@ -159,6 +160,10 @@ function DisclosureSection({
159
160
  );
160
161
  }
161
162
 
163
+ const HISTORY_ELEMENT_PREFIX = "noya-multiplayer-history-";
164
+
165
+ type Anchor = "left" | "right";
166
+
162
167
  export const StateInspector = memo(function StateInspector<
163
168
  S extends object,
164
169
  M,
@@ -168,6 +173,7 @@ export const StateInspector = memo(function StateInspector<
168
173
  unstyled,
169
174
  colorScheme = "light",
170
175
  stateManager,
176
+ anchor = "right",
171
177
  ...props
172
178
  }: {
173
179
  state: S;
@@ -175,6 +181,7 @@ export const StateInspector = memo(function StateInspector<
175
181
  unstyled?: boolean;
176
182
  colorScheme?: "light" | "dark";
177
183
  stateManager: StateManager<S, M>;
184
+ anchor?: Anchor;
178
185
  } & ComponentPropsWithoutRef<"div">) {
179
186
  const [didMount, setDidMount] = React.useState(false);
180
187
 
@@ -223,7 +230,7 @@ export const StateInspector = memo(function StateInspector<
223
230
  if (!historyContainerRef.current) return;
224
231
 
225
232
  const historyEntry = historyContainerRef.current.querySelector(
226
- `#history-${historySnapshot.historyIndex - 1}`
233
+ `#${HISTORY_ELEMENT_PREFIX}${historySnapshot.historyIndex}`
227
234
  );
228
235
 
229
236
  if (historyEntry) {
@@ -237,17 +244,19 @@ export const StateInspector = memo(function StateInspector<
237
244
  const theme = colorScheme === "light" ? lightTheme : darkTheme;
238
245
  const borderColor =
239
246
  colorScheme === "light" ? "rgba(0,0,0,0.1)" : "rgba(255,255,255,0.1)";
247
+ const solidBorderColor =
248
+ colorScheme === "light" ? "rgb(223 223 223)" : "rgb(29 29 29)";
240
249
 
241
250
  const baseStyle: CSSProperties = {
242
251
  position: "fixed",
243
252
  top: 12,
244
- right: 12,
253
+ ...(anchor === "right" ? { right: 12 } : { left: 12 }),
245
254
  bottom: 12,
246
255
  width: 400,
247
256
  background:
248
257
  colorScheme === "light" ? "rgba(255,255,255,0.95)" : "rgba(0,0,0,0.95)",
249
258
  backdropFilter: "blur(48px)",
250
- border: `1px solid ${borderColor}`,
259
+ border: `1px solid ${solidBorderColor}`,
251
260
  // outlineOffset: -1,
252
261
  borderRadius: 4,
253
262
  display: "flex",
@@ -256,6 +265,7 @@ export const StateInspector = memo(function StateInspector<
256
265
  color: theme.BASE_COLOR,
257
266
  overflow: "hidden",
258
267
  zIndex: 9999,
268
+ lineHeight: "13px",
259
269
  };
260
270
 
261
271
  if (!didMount) return null;
@@ -267,15 +277,16 @@ export const StateInspector = memo(function StateInspector<
267
277
  style={{
268
278
  ...baseStyle,
269
279
  padding: "4px 10px",
270
- borderRadius: 8,
271
280
  bottom: undefined,
272
281
  width: undefined,
273
282
  }}
283
+ onClick={() => setShowInspector(true)}
274
284
  >
275
285
  <ToggleButton
276
286
  showInspector={showInspector}
277
287
  setShowInspector={setShowInspector}
278
288
  theme={theme}
289
+ anchor={anchor}
279
290
  />
280
291
  </div>
281
292
  );
@@ -300,6 +311,7 @@ export const StateInspector = memo(function StateInspector<
300
311
  showInspector={showInspector}
301
312
  setShowInspector={setShowInspector}
302
313
  theme={theme}
314
+ anchor={anchor}
303
315
  />
304
316
  }
305
317
  >
@@ -332,48 +344,42 @@ export const StateInspector = memo(function StateInspector<
332
344
  flexDirection: "column",
333
345
  }}
334
346
  >
335
- {historySnapshot.history.length < 50 && (
336
- <div
337
- id={`history-${0}`}
347
+ <div
348
+ id={`${HISTORY_ELEMENT_PREFIX}0`}
349
+ style={{
350
+ borderBottom: `1px solid ${solidBorderColor}`,
351
+ fontSize: "12px",
352
+ fontFamily: "Menlo, monospace",
353
+ padding: "2px 12px 1px",
354
+ display: "flex",
355
+ alignItems: "center",
356
+ background:
357
+ historySnapshot.historyIndex === 0
358
+ ? "rgb(59 130 246 / 15%)"
359
+ : undefined,
360
+ }}
361
+ >
362
+ <span
338
363
  style={{
339
- borderBottom: `1px solid ${borderColor}`,
340
- fontSize: "12px",
341
364
  fontFamily: "Menlo, monospace",
342
- padding: "2px 12px 1px",
343
- display: "flex",
344
- alignItems: "center",
345
- background:
346
- historySnapshot.historyIndex === 0
347
- ? colorScheme === "light"
348
- ? "rgba(0,0,0,0.2)"
349
- : "rgb(59 130 246 / 38%)"
350
- : undefined,
365
+ fontSize: "11px",
366
+ borderRadius: 4,
367
+ display: "inline-block",
351
368
  }}
352
369
  >
353
- <span
354
- style={{
355
- fontFamily: "Menlo, monospace",
356
- fontSize: "11px",
357
- borderRadius: 4,
358
- display: "inline-block",
359
- }}
360
- >
361
- Initial state
362
- </span>
363
- </div>
364
- )}
365
- {historySnapshot.history.slice(-50).map((entry, index) => (
370
+ Initial state
371
+ </span>
372
+ </div>
373
+ {historySnapshot.history.map((entry, index) => (
366
374
  <div
367
- id={`history-${index}`}
375
+ id={`${HISTORY_ELEMENT_PREFIX}${index + 1}`}
368
376
  key={index}
369
377
  style={{
370
378
  padding: "0px 12px 1px",
371
- borderBottom: `1px solid ${borderColor}`,
379
+ borderBottom: `1px solid ${solidBorderColor}`,
372
380
  background:
373
- index === historySnapshot.historyIndex - 1
374
- ? colorScheme === "light"
375
- ? "rgba(0,0,0,0.2)"
376
- : "rgb(59 130 246 / 15%)"
381
+ index + 1 === historySnapshot.historyIndex
382
+ ? "rgb(59 130 246 / 15%)"
377
383
  : undefined,
378
384
  }}
379
385
  >
@@ -589,6 +595,7 @@ function Arrow({
589
595
  display: "inline-block",
590
596
  textAlign: "center",
591
597
  transform: expanded ? "rotate(0deg)" : "rotate(-90deg)",
598
+ fontFamily: "Menlo, monospace",
592
599
  ...style,
593
600
  }}
594
601
  >
@@ -16,14 +16,14 @@ export function useStateInspector<S extends object, M>({
16
16
  connectionEvents,
17
17
  disabled = false,
18
18
  colorScheme,
19
+ anchor,
19
20
  stateManager,
20
21
  }: {
21
22
  state: S;
22
23
  connectionEvents?: ConnectionEvent<S>[];
23
24
  disabled: boolean;
24
- colorScheme: ComponentProps<typeof StateInspector>["colorScheme"];
25
25
  stateManager: StateManager<S, M>;
26
- }) {
26
+ } & Pick<ComponentProps<typeof StateInspector>, "colorScheme" | "anchor">) {
27
27
  const [root, setRoot] = React.useState<Root | null>(null);
28
28
 
29
29
  useLayoutEffect(() => {
@@ -50,8 +50,9 @@ export function useStateInspector<S extends object, M>({
50
50
  state={state}
51
51
  connectionEvents={connectionEvents}
52
52
  colorScheme={colorScheme}
53
+ anchor={anchor}
53
54
  stateManager={stateManager as StateManager<any, any>}
54
55
  />
55
56
  );
56
- }, [colorScheme, connectionEvents, root, state, stateManager]);
57
+ }, [anchor, colorScheme, connectionEvents, root, state, stateManager]);
57
58
  }