@noya-app/noya-multiplayer-react 0.1.26 → 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.
- package/.turbo/turbo-build.log +9 -9
- package/CHANGELOG.md +16 -0
- package/dist/index.d.mts +10 -9
- package/dist/index.d.ts +10 -9
- package/dist/index.js +41 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/__tests__/noyaApp.test.ts +107 -0
- package/src/noyaApp.ts +55 -44
package/.turbo/turbo-build.log
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
[34mCLI[39m Target: esnext
|
|
6
6
|
[34mCJS[39m Build start
|
|
7
7
|
[34mESM[39m Build start
|
|
8
|
-
[
|
|
9
|
-
[
|
|
10
|
-
[
|
|
11
|
-
[
|
|
12
|
-
[
|
|
13
|
-
[
|
|
8
|
+
[32mESM[39m [1mdist/index.mjs [22m[32m45.02 KB[39m
|
|
9
|
+
[32mESM[39m [1mdist/index.mjs.map [22m[32m82.40 KB[39m
|
|
10
|
+
[32mESM[39m ⚡️ Build success in 103ms
|
|
11
|
+
[32mCJS[39m [1mdist/index.js [22m[32m50.60 KB[39m
|
|
12
|
+
[32mCJS[39m [1mdist/index.js.map [22m[32m82.18 KB[39m
|
|
13
|
+
[32mCJS[39m ⚡️ Build success in 104ms
|
|
14
14
|
[34mDTS[39m Build start
|
|
15
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
|
-
[32mDTS[39m ⚡️ Build success in
|
|
17
|
-
[32mDTS[39m [1mdist/index.d.ts [22m[32m7.
|
|
18
|
-
[32mDTS[39m [1mdist/index.d.mts [22m[32m7.
|
|
16
|
+
[32mDTS[39m ⚡️ Build success in 4481ms
|
|
17
|
+
[32mDTS[39m [1mdist/index.d.ts [22m[32m7.41 KB[39m
|
|
18
|
+
[32mDTS[39m [1mdist/index.d.mts [22m[32m7.41 KB[39m
|
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
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
|
+
|
|
12
|
+
## 0.1.27
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies [b1903d5]
|
|
17
|
+
- @noya-app/state-manager@0.1.25
|
|
18
|
+
|
|
3
19
|
## 0.1.26
|
|
4
20
|
|
|
5
21
|
### 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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
type GetAppDataOptions = {
|
|
104
|
+
window?: {
|
|
105
|
+
location: {
|
|
106
|
+
hash: string;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
107
109
|
};
|
|
108
|
-
|
|
109
|
-
|
|
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,
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
type GetAppDataOptions = {
|
|
104
|
+
window?: {
|
|
105
|
+
location: {
|
|
106
|
+
hash: string;
|
|
107
|
+
};
|
|
108
|
+
};
|
|
107
109
|
};
|
|
108
|
-
|
|
109
|
-
|
|
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,
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
1452
|
+
return null;
|
|
1449
1453
|
}
|
|
1450
1454
|
}
|
|
1451
|
-
function
|
|
1452
|
-
const
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
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 [
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
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
|
-
|
|
1542
|
+
parseAppDataParameter,
|
|
1533
1543
|
useBroadcastConnectedUsers,
|
|
1534
1544
|
useBroadcastMenuItems,
|
|
1535
1545
|
useEphemeralUserData,
|