@noya-app/noya-multiplayer-react 0.1.27 → 0.1.28

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.
@@ -5,14 +5,14 @@
5
5
  CLI Target: esnext
6
6
  CJS Build start
7
7
  ESM Build start
8
- CJS dist/index.js 50.29 KB
9
- CJS dist/index.js.map 81.83 KB
10
- CJS ⚡️ Build success in 43ms
11
- ESM dist/index.mjs 44.76 KB
12
- ESM dist/index.mjs.map 82.05 KB
13
- ESM ⚡️ Build success in 44ms
8
+ ESM dist/index.mjs 45.02 KB
9
+ ESM dist/index.mjs.map 82.40 KB
10
+ ESM ⚡️ Build success in 103ms
11
+ CJS dist/index.js 50.60 KB
12
+ CJS dist/index.js.map 82.18 KB
13
+ CJS ⚡️ Build success in 104ms
14
14
  DTS Build start
15
- "ComponentPropsWithoutRef" is imported from external module "react" but never used in "src/inspector/StateInspector.tsx", "src/hooks.ts" and "src/components/UserPointersOverlay.tsx".
16
- DTS ⚡️ Build success in 2585ms
17
- DTS dist/index.d.ts 7.30 KB
18
- DTS dist/index.d.mts 7.30 KB
15
+ "ComponentPropsWithoutRef" is imported from external module "react" but never used in "src/components/UserPointersOverlay.tsx", "src/inspector/StateInspector.tsx" and "src/hooks.ts".
16
+ DTS ⚡️ Build success in 4481ms
17
+ DTS dist/index.d.ts 7.41 KB
18
+ DTS dist/index.d.mts 7.41 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # @noya-app/state-manager
2
2
 
3
+ ## 0.1.28
4
+
5
+ ### Patch Changes
6
+
7
+ - 8ff67bc: Improve group dnd
8
+ - 9a73bc7: Improve getting default app data
9
+ - Updated dependencies [8ff67bc]
10
+ - @noya-app/state-manager@0.1.26
11
+
3
12
  ## 0.1.27
4
13
 
5
14
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -100,15 +100,16 @@ type AppData<State> = {
100
100
  inspector: boolean | StateInspectorOptions;
101
101
  };
102
102
  declare function createDefaultAppData<State>(initialState: State): AppData<State>;
103
- declare function getAppData<State>(): AppData<State> | undefined;
104
- declare function getAppData<State>(initialState: State): AppData<State>;
105
- type AppDataOptions = {
106
- schema?: TSchema;
103
+ type GetAppDataOptions = {
104
+ window?: {
105
+ location: {
106
+ hash: string;
107
+ };
108
+ };
107
109
  };
108
- /**
109
- * Get data from host app. Fall back to default data.
110
- */
111
- declare function useAppData<S>(initialState: S, { schema }?: AppDataOptions): AppData<S>;
110
+ declare function enforceSchema<State>(initialState: State, schema?: TSchema): State;
111
+ declare function parseAppDataParameter(options?: GetAppDataOptions): any;
112
+ declare function getAppData<State>(initialState: State | (() => State), schema?: TSchema, options?: GetAppDataOptions): AppData<State>;
112
113
  type IframeToHostMessage = {
113
114
  type: "application.setMenuItems";
114
115
  payload: {
@@ -145,4 +146,4 @@ declare function useNoyaAppState<S, M = void, E = void>(initialState: S | (() =>
145
146
  declare function useObservable<T>(observable: Observable<T>): T;
146
147
  declare function useObservable<T, P extends PathKey[]>(observable: Observable<T>, path: P): GetWithPath<T, P>;
147
148
 
148
- export { type AppData, type AppTheme, type AppViewType, type HostToIframeMessage, type IframeToHostMessage, StateInspector, type StateInspectorAnchor, type StateInspectorOptions, type UseMultiplayerStateOptions, UserNameTag, UserPointer, UserPointerContainer, type UserPointerData, UserPointerIcon, type UserPointerProps, UserPointersOverlay, type UserPointersOverlayProps, createDefaultAppData, getAppData, getAvatarInitials, getAvatarStyle, isEmbeddedApp, useAppData, useBroadcastConnectedUsers, useBroadcastMenuItems, useEphemeralUserData, useManagedHistory, useManagedState, useMultiplayerState, useNoyaAppState, useObservable, useSyncMultiplayerStateManager, useSyncStateManager };
149
+ export { type AppData, type AppTheme, type AppViewType, type GetAppDataOptions, type HostToIframeMessage, type IframeToHostMessage, StateInspector, type StateInspectorAnchor, type StateInspectorOptions, type UseMultiplayerStateOptions, UserNameTag, UserPointer, UserPointerContainer, type UserPointerData, UserPointerIcon, type UserPointerProps, UserPointersOverlay, type UserPointersOverlayProps, createDefaultAppData, enforceSchema, getAppData, getAvatarInitials, getAvatarStyle, isEmbeddedApp, parseAppDataParameter, useBroadcastConnectedUsers, useBroadcastMenuItems, useEphemeralUserData, useManagedHistory, useManagedState, useMultiplayerState, useNoyaAppState, useObservable, useSyncMultiplayerStateManager, useSyncStateManager };
package/dist/index.d.ts CHANGED
@@ -100,15 +100,16 @@ type AppData<State> = {
100
100
  inspector: boolean | StateInspectorOptions;
101
101
  };
102
102
  declare function createDefaultAppData<State>(initialState: State): AppData<State>;
103
- declare function getAppData<State>(): AppData<State> | undefined;
104
- declare function getAppData<State>(initialState: State): AppData<State>;
105
- type AppDataOptions = {
106
- schema?: TSchema;
103
+ type GetAppDataOptions = {
104
+ window?: {
105
+ location: {
106
+ hash: string;
107
+ };
108
+ };
107
109
  };
108
- /**
109
- * Get data from host app. Fall back to default data.
110
- */
111
- declare function useAppData<S>(initialState: S, { schema }?: AppDataOptions): AppData<S>;
110
+ declare function enforceSchema<State>(initialState: State, schema?: TSchema): State;
111
+ declare function parseAppDataParameter(options?: GetAppDataOptions): any;
112
+ declare function getAppData<State>(initialState: State | (() => State), schema?: TSchema, options?: GetAppDataOptions): AppData<State>;
112
113
  type IframeToHostMessage = {
113
114
  type: "application.setMenuItems";
114
115
  payload: {
@@ -145,4 +146,4 @@ declare function useNoyaAppState<S, M = void, E = void>(initialState: S | (() =>
145
146
  declare function useObservable<T>(observable: Observable<T>): T;
146
147
  declare function useObservable<T, P extends PathKey[]>(observable: Observable<T>, path: P): GetWithPath<T, P>;
147
148
 
148
- export { type AppData, type AppTheme, type AppViewType, type HostToIframeMessage, type IframeToHostMessage, StateInspector, type StateInspectorAnchor, type StateInspectorOptions, type UseMultiplayerStateOptions, UserNameTag, UserPointer, UserPointerContainer, type UserPointerData, UserPointerIcon, type UserPointerProps, UserPointersOverlay, type UserPointersOverlayProps, createDefaultAppData, getAppData, getAvatarInitials, getAvatarStyle, isEmbeddedApp, useAppData, useBroadcastConnectedUsers, useBroadcastMenuItems, useEphemeralUserData, useManagedHistory, useManagedState, useMultiplayerState, useNoyaAppState, useObservable, useSyncMultiplayerStateManager, useSyncStateManager };
149
+ export { type AppData, type AppTheme, type AppViewType, type GetAppDataOptions, type HostToIframeMessage, type IframeToHostMessage, StateInspector, type StateInspectorAnchor, type StateInspectorOptions, type UseMultiplayerStateOptions, UserNameTag, UserPointer, UserPointerContainer, type UserPointerData, UserPointerIcon, type UserPointerProps, UserPointersOverlay, type UserPointersOverlayProps, createDefaultAppData, enforceSchema, getAppData, getAvatarInitials, getAvatarStyle, isEmbeddedApp, parseAppDataParameter, useBroadcastConnectedUsers, useBroadcastMenuItems, useEphemeralUserData, useManagedHistory, useManagedState, useMultiplayerState, useNoyaAppState, useObservable, useSyncMultiplayerStateManager, useSyncStateManager };
package/dist/index.js CHANGED
@@ -38,11 +38,12 @@ __export(src_exports, {
38
38
  UserPointerIcon: () => UserPointerIcon,
39
39
  UserPointersOverlay: () => UserPointersOverlay,
40
40
  createDefaultAppData: () => createDefaultAppData,
41
+ enforceSchema: () => enforceSchema,
41
42
  getAppData: () => getAppData,
42
43
  getAvatarInitials: () => getAvatarInitials,
43
44
  getAvatarStyle: () => getAvatarStyle,
44
45
  isEmbeddedApp: () => isEmbeddedApp,
45
- useAppData: () => useAppData,
46
+ parseAppDataParameter: () => parseAppDataParameter,
46
47
  useBroadcastConnectedUsers: () => useBroadcastConnectedUsers,
47
48
  useBroadcastMenuItems: () => useBroadcastMenuItems,
48
49
  useEphemeralUserData: () => useEphemeralUserData,
@@ -1431,30 +1432,37 @@ function createDefaultAppData(initialState) {
1431
1432
  inspector: false
1432
1433
  };
1433
1434
  }
1434
- function getAppData(initialState) {
1435
+ function enforceSchema(initialState, schema) {
1436
+ return schema ? (0, import_state_manager2.createOrCastValue)({
1437
+ schema,
1438
+ value: initialState,
1439
+ defs: (0, import_state_manager2.findAllDefs)(schema)
1440
+ }) : initialState;
1441
+ }
1442
+ function parseAppDataParameter(options) {
1443
+ const window2 = options?.window ?? globalThis;
1444
+ const urlHash = (window2.location.hash || "").replace(/^#/, "");
1445
+ const params = new URLSearchParams(urlHash);
1446
+ const data = params.get("data");
1447
+ if (!data)
1448
+ return null;
1435
1449
  try {
1436
- const urlHash = (window.location.hash || "").replace(/^#/, "");
1437
- const params = new URLSearchParams(urlHash);
1438
- const data = params.get("data");
1439
- if (!data) {
1440
- return initialState ? createDefaultAppData(initialState) : void 0;
1441
- }
1442
- const parsed = JSON.parse(data);
1443
- if (!parsed.initialState) {
1444
- parsed.initialState = initialState;
1445
- }
1446
- return parsed;
1450
+ return JSON.parse(data);
1447
1451
  } catch (e) {
1448
- return initialState ? createDefaultAppData(initialState) : void 0;
1452
+ return null;
1449
1453
  }
1450
1454
  }
1451
- function useAppData(initialState, { schema } = {}) {
1452
- const appData = (0, import_react8.useMemo)(() => {
1453
- return getAppData(
1454
- schema ? (0, import_state_manager2.createOrCastValue)(schema, initialState) : initialState
1455
- );
1456
- }, [initialState, schema]);
1457
- return appData;
1455
+ function getAppData(initialState, schema, options) {
1456
+ const resolvedInitialState = initialState instanceof Function ? initialState() : initialState;
1457
+ try {
1458
+ const appData = parseAppDataParameter(options) ?? createDefaultAppData(resolvedInitialState);
1459
+ return {
1460
+ ...appData,
1461
+ initialState: enforceSchema(appData.initialState, schema)
1462
+ };
1463
+ } catch (e) {
1464
+ return createDefaultAppData(enforceSchema(resolvedInitialState, schema));
1465
+ }
1458
1466
  }
1459
1467
  function useBroadcastConnectedUsers(connectedUsers) {
1460
1468
  (0, import_react8.useEffect)(() => {
@@ -1491,15 +1499,16 @@ function isEmbeddedApp() {
1491
1499
  return window.self !== window.top;
1492
1500
  }
1493
1501
  function useNoyaAppState(initialState, options) {
1494
- const [state] = (0, import_react8.useState)(initialState);
1495
- const {
1496
- multiplayerUrl,
1497
- inspector,
1498
- initialState: noyaAppInitialState,
1499
- theme,
1500
- viewType
1501
- } = useAppData(state, {
1502
- schema: options.schema
1502
+ const [
1503
+ {
1504
+ multiplayerUrl,
1505
+ inspector,
1506
+ initialState: noyaAppInitialState,
1507
+ theme,
1508
+ viewType
1509
+ }
1510
+ ] = (0, import_react8.useState)(() => {
1511
+ return getAppData(initialState, options.schema);
1503
1512
  });
1504
1513
  const sync = (0, import_react8.useMemo)(() => {
1505
1514
  return multiplayerUrl ? (0, import_state_manager2.webSocketSync)(multiplayerUrl) : (0, import_state_manager2.localStorageSync)({ key: options.localStorageKey || "noya-app" });
@@ -1525,11 +1534,12 @@ function useNoyaAppState(initialState, options) {
1525
1534
  UserPointerIcon,
1526
1535
  UserPointersOverlay,
1527
1536
  createDefaultAppData,
1537
+ enforceSchema,
1528
1538
  getAppData,
1529
1539
  getAvatarInitials,
1530
1540
  getAvatarStyle,
1531
1541
  isEmbeddedApp,
1532
- useAppData,
1542
+ parseAppDataParameter,
1533
1543
  useBroadcastConnectedUsers,
1534
1544
  useBroadcastMenuItems,
1535
1545
  useEphemeralUserData,