@noya-app/noya-multiplayer-react 0.1.47 → 0.1.49
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 +11 -11
- package/CHANGELOG.md +18 -0
- package/dist/index.bundle.js +8 -8
- package/dist/index.d.mts +20 -4
- package/dist/index.d.ts +20 -4
- package/dist/index.js +113 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/NoyaStateContext.tsx +133 -47
- package/src/noyaApp.ts +4 -1
package/dist/index.mjs
CHANGED
|
@@ -1338,7 +1338,10 @@ function useNoyaState(...args) {
|
|
|
1338
1338
|
});
|
|
1339
1339
|
});
|
|
1340
1340
|
const sync = useMemo3(() => {
|
|
1341
|
-
return isEmbeddedApp() ? parentFrameSync({ debug: options?.debug }) : multiplayerUrl ? webSocketSync(
|
|
1341
|
+
return isEmbeddedApp() ? parentFrameSync({ debug: options?.debug }) : multiplayerUrl ? webSocketSync({
|
|
1342
|
+
url: multiplayerUrl,
|
|
1343
|
+
debug: options?.debug
|
|
1344
|
+
}) : options?.offlineStorageKey ? localStorageSync({ key: options.offlineStorageKey }) : stubSync2();
|
|
1342
1345
|
}, [multiplayerUrl, options?.offlineStorageKey, options?.debug]);
|
|
1343
1346
|
const result = useMultiplayerState(noyaAppInitialState, {
|
|
1344
1347
|
...options,
|
|
@@ -1373,69 +1376,81 @@ function useAnyNoyaStateContext() {
|
|
|
1373
1376
|
}
|
|
1374
1377
|
return value;
|
|
1375
1378
|
}
|
|
1379
|
+
function useAnyNoyaManager() {
|
|
1380
|
+
const { noyaManager } = useAnyNoyaStateContext();
|
|
1381
|
+
return noyaManager;
|
|
1382
|
+
}
|
|
1383
|
+
function useColorScheme() {
|
|
1384
|
+
const { theme } = useAnyNoyaStateContext();
|
|
1385
|
+
return theme;
|
|
1386
|
+
}
|
|
1387
|
+
function useViewType() {
|
|
1388
|
+
const { viewType } = useAnyNoyaStateContext();
|
|
1389
|
+
return viewType;
|
|
1390
|
+
}
|
|
1376
1391
|
function useAssets() {
|
|
1377
|
-
const {
|
|
1378
|
-
return useObservable(assetManager.assets$);
|
|
1392
|
+
const { noyaManager } = useAnyNoyaStateContext();
|
|
1393
|
+
return useObservable(noyaManager.assetManager.assets$);
|
|
1379
1394
|
}
|
|
1380
1395
|
function useAsset(id) {
|
|
1381
|
-
const {
|
|
1396
|
+
const { noyaManager } = useAnyNoyaStateContext();
|
|
1382
1397
|
const observable = useMemo4(
|
|
1383
|
-
() => assetManager.assets$.map(
|
|
1384
|
-
|
|
1398
|
+
() => noyaManager.assetManager.assets$.map(
|
|
1399
|
+
(assets) => assets.find((a) => a.id === id)
|
|
1400
|
+
),
|
|
1401
|
+
[noyaManager, id]
|
|
1385
1402
|
);
|
|
1386
1403
|
return useObservable(observable);
|
|
1387
1404
|
}
|
|
1388
1405
|
function useAssetManager() {
|
|
1389
|
-
const {
|
|
1406
|
+
const { noyaManager } = useAnyNoyaStateContext();
|
|
1407
|
+
const isInitialized = useObservable(noyaManager.assetManager.isInitialized$);
|
|
1390
1408
|
return useMemo4(
|
|
1391
1409
|
() => ({
|
|
1392
|
-
create: assetManager.create,
|
|
1393
|
-
delete: assetManager.delete
|
|
1410
|
+
create: noyaManager.assetManager.create,
|
|
1411
|
+
delete: noyaManager.assetManager.delete,
|
|
1412
|
+
isInitialized
|
|
1394
1413
|
}),
|
|
1395
|
-
[
|
|
1414
|
+
[noyaManager, isInitialized]
|
|
1396
1415
|
);
|
|
1397
1416
|
}
|
|
1398
1417
|
function useAIManager() {
|
|
1399
|
-
const {
|
|
1400
|
-
return aiManager;
|
|
1418
|
+
const { noyaManager } = useAnyNoyaStateContext();
|
|
1419
|
+
return noyaManager.aiManager;
|
|
1401
1420
|
}
|
|
1402
1421
|
function useSecretManager() {
|
|
1403
|
-
const {
|
|
1404
|
-
return secretManager;
|
|
1422
|
+
const { noyaManager } = useAnyNoyaStateContext();
|
|
1423
|
+
return noyaManager.secretManager;
|
|
1405
1424
|
}
|
|
1406
1425
|
function useSecrets() {
|
|
1407
|
-
const {
|
|
1408
|
-
return useObservable(secretManager.secrets$);
|
|
1426
|
+
const { noyaManager } = useAnyNoyaStateContext();
|
|
1427
|
+
return useObservable(noyaManager.secretManager.secrets$);
|
|
1409
1428
|
}
|
|
1410
1429
|
function useSecret(name) {
|
|
1411
|
-
const {
|
|
1430
|
+
const { noyaManager } = useAnyNoyaStateContext();
|
|
1412
1431
|
return useObservable(
|
|
1413
|
-
secretManager.secrets$,
|
|
1432
|
+
noyaManager.secretManager.secrets$,
|
|
1414
1433
|
useCallback2((secrets) => secrets.find((s) => s.name === name), [name])
|
|
1415
1434
|
);
|
|
1416
1435
|
}
|
|
1417
1436
|
function useIsInitialized() {
|
|
1418
|
-
const {
|
|
1419
|
-
multiplayerStateManager: ms,
|
|
1420
|
-
secretManager,
|
|
1421
|
-
assetManager
|
|
1422
|
-
} = useAnyNoyaStateContext();
|
|
1437
|
+
const { noyaManager, viewType } = useAnyNoyaStateContext();
|
|
1423
1438
|
const isInitializedObservable = useMemo4(
|
|
1424
1439
|
() => Observable.combine(
|
|
1425
1440
|
[
|
|
1426
|
-
|
|
1427
|
-
secretManager.isInitialized$,
|
|
1428
|
-
assetManager.isInitialized$
|
|
1441
|
+
...viewType === "preview" ? [] : [noyaManager.multiplayerStateManager.isInitialized$],
|
|
1442
|
+
noyaManager.secretManager.isInitialized$,
|
|
1443
|
+
noyaManager.assetManager.isInitialized$
|
|
1429
1444
|
],
|
|
1430
1445
|
(values) => values.every((v) => v)
|
|
1431
1446
|
),
|
|
1432
|
-
[
|
|
1447
|
+
[noyaManager, viewType]
|
|
1433
1448
|
);
|
|
1434
1449
|
return useObservable(isInitializedObservable);
|
|
1435
1450
|
}
|
|
1436
1451
|
function useWorkflowManager() {
|
|
1437
|
-
const {
|
|
1438
|
-
return workflowManager;
|
|
1452
|
+
const { noyaManager } = useAnyNoyaStateContext();
|
|
1453
|
+
return noyaManager.workflowManager;
|
|
1439
1454
|
}
|
|
1440
1455
|
var ConnectedUsersContext = createContext(void 0);
|
|
1441
1456
|
function useConnectedUsersManager() {
|
|
@@ -1467,12 +1482,23 @@ function createNoyaContext({
|
|
|
1467
1482
|
initialState,
|
|
1468
1483
|
...options
|
|
1469
1484
|
}) {
|
|
1470
|
-
const [, , { noyaManager }] = useNoyaState(
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1485
|
+
const [, , { noyaManager, theme, viewType }] = useNoyaState(
|
|
1486
|
+
initialState,
|
|
1487
|
+
{
|
|
1488
|
+
...options,
|
|
1489
|
+
schema,
|
|
1490
|
+
mergeHistoryEntries
|
|
1491
|
+
}
|
|
1492
|
+
);
|
|
1493
|
+
const contextValue = useMemo4(
|
|
1494
|
+
() => ({
|
|
1495
|
+
noyaManager,
|
|
1496
|
+
theme,
|
|
1497
|
+
viewType
|
|
1498
|
+
}),
|
|
1499
|
+
[noyaManager, theme, viewType]
|
|
1500
|
+
);
|
|
1501
|
+
return /* @__PURE__ */ React6.createElement(AnyNoyaStateContext.Provider, { value: contextValue }, /* @__PURE__ */ React6.createElement(
|
|
1476
1502
|
ConnectedUsersContext.Provider,
|
|
1477
1503
|
{
|
|
1478
1504
|
value: noyaManager.connectedUsersManager
|
|
@@ -1487,25 +1513,31 @@ function createNoyaContext({
|
|
|
1487
1513
|
));
|
|
1488
1514
|
}
|
|
1489
1515
|
function useValue(path, options) {
|
|
1490
|
-
const {
|
|
1516
|
+
const { noyaManager } = useAnyNoyaStateContext();
|
|
1491
1517
|
let actualPath = typeof path === "function" || !path ? "" : path;
|
|
1492
1518
|
const mappedObservable = useMemo4(() => {
|
|
1493
1519
|
if (typeof path === "function") {
|
|
1494
|
-
return
|
|
1520
|
+
return noyaManager.multiplayerStateManager.optimisticState$.map(path, {
|
|
1521
|
+
isEqual: options?.isEqual
|
|
1522
|
+
});
|
|
1495
1523
|
}
|
|
1496
|
-
return
|
|
1497
|
-
}, [
|
|
1524
|
+
return noyaManager.multiplayerStateManager.optimisticState$;
|
|
1525
|
+
}, [noyaManager, path, options?.isEqual]);
|
|
1498
1526
|
const value = useObservable(mappedObservable, actualPath);
|
|
1499
1527
|
return value;
|
|
1500
1528
|
}
|
|
1501
1529
|
function useSetValue(path) {
|
|
1502
|
-
const {
|
|
1530
|
+
const { noyaManager } = useAnyNoyaStateContext();
|
|
1503
1531
|
const setValue = useCallback2(
|
|
1504
1532
|
(...args) => {
|
|
1505
1533
|
const [metadata, value] = args.length === 2 ? args : [{}, args[0]];
|
|
1506
|
-
|
|
1534
|
+
noyaManager.multiplayerStateManager.setStateAtPath(
|
|
1535
|
+
metadata,
|
|
1536
|
+
path ?? "",
|
|
1537
|
+
value
|
|
1538
|
+
);
|
|
1507
1539
|
},
|
|
1508
|
-
[
|
|
1540
|
+
[noyaManager, path]
|
|
1509
1541
|
);
|
|
1510
1542
|
return setValue;
|
|
1511
1543
|
}
|
|
@@ -1516,8 +1548,8 @@ function createNoyaContext({
|
|
|
1516
1548
|
return [value, setValue];
|
|
1517
1549
|
}
|
|
1518
1550
|
function useStateManager() {
|
|
1519
|
-
const {
|
|
1520
|
-
return
|
|
1551
|
+
const { noyaManager } = useAnyNoyaStateContext();
|
|
1552
|
+
return noyaManager.multiplayerStateManager;
|
|
1521
1553
|
}
|
|
1522
1554
|
function useEphemeralUserDataManager() {
|
|
1523
1555
|
const ephemeralUserData = useContext(EphemeralUserDataManagerContext);
|
|
@@ -1529,16 +1561,32 @@ function createNoyaContext({
|
|
|
1529
1561
|
return ephemeralUserData;
|
|
1530
1562
|
}
|
|
1531
1563
|
function useNoyaManager() {
|
|
1532
|
-
return useAnyNoyaStateContext();
|
|
1564
|
+
return useAnyNoyaStateContext().noyaManager;
|
|
1533
1565
|
}
|
|
1534
1566
|
function useLeftMenuItems() {
|
|
1535
1567
|
const { menuManager } = useNoyaManager();
|
|
1536
1568
|
return useObservable(menuManager.leftMenuItems$);
|
|
1537
1569
|
}
|
|
1570
|
+
function useSetLeftMenuItems(leftMenuItems) {
|
|
1571
|
+
const { menuManager } = useNoyaManager();
|
|
1572
|
+
useEffect4(() => {
|
|
1573
|
+
if (leftMenuItems) {
|
|
1574
|
+
menuManager.setLeftMenuItems(leftMenuItems);
|
|
1575
|
+
}
|
|
1576
|
+
}, [menuManager, leftMenuItems]);
|
|
1577
|
+
}
|
|
1538
1578
|
function useRightMenuItems() {
|
|
1539
1579
|
const { menuManager } = useNoyaManager();
|
|
1540
1580
|
return useObservable(menuManager.rightMenuItems$);
|
|
1541
1581
|
}
|
|
1582
|
+
function useSetRightMenuItems(rightMenuItems) {
|
|
1583
|
+
const { menuManager } = useNoyaManager();
|
|
1584
|
+
useEffect4(() => {
|
|
1585
|
+
if (rightMenuItems) {
|
|
1586
|
+
menuManager.setRightMenuItems(rightMenuItems);
|
|
1587
|
+
}
|
|
1588
|
+
}, [menuManager, rightMenuItems]);
|
|
1589
|
+
}
|
|
1542
1590
|
function useHandleMenuItem(callback) {
|
|
1543
1591
|
const { menuManager } = useNoyaManager();
|
|
1544
1592
|
useEffect4(() => {
|
|
@@ -1549,6 +1597,14 @@ function createNoyaContext({
|
|
|
1549
1597
|
const { menuManager } = useNoyaManager();
|
|
1550
1598
|
return useCallback2((type) => menuManager.emit(type), [menuManager]);
|
|
1551
1599
|
}
|
|
1600
|
+
function useMenu(options) {
|
|
1601
|
+
const { leftMenuItems, rightMenuItems, onSelectMenuItem } = options;
|
|
1602
|
+
useSetLeftMenuItems(leftMenuItems);
|
|
1603
|
+
useSetRightMenuItems(rightMenuItems);
|
|
1604
|
+
const noop = useCallback2(() => {
|
|
1605
|
+
}, []);
|
|
1606
|
+
useHandleMenuItem(onSelectMenuItem ?? noop);
|
|
1607
|
+
}
|
|
1552
1608
|
return {
|
|
1553
1609
|
Context: NoyaStateContext,
|
|
1554
1610
|
Provider: NoyaStateProvider,
|
|
@@ -1558,10 +1614,13 @@ function createNoyaContext({
|
|
|
1558
1614
|
useStateManager,
|
|
1559
1615
|
useEphemeralUserDataManager,
|
|
1560
1616
|
useLeftMenuItems,
|
|
1617
|
+
useSetLeftMenuItems,
|
|
1561
1618
|
useRightMenuItems,
|
|
1619
|
+
useSetRightMenuItems,
|
|
1562
1620
|
useHandleMenuItem,
|
|
1563
1621
|
useOnSelectMenuItemCallback,
|
|
1564
|
-
useNoyaManager
|
|
1622
|
+
useNoyaManager,
|
|
1623
|
+
useMenu
|
|
1565
1624
|
};
|
|
1566
1625
|
}
|
|
1567
1626
|
|
|
@@ -1677,9 +1736,12 @@ export {
|
|
|
1677
1736
|
parseAppDataParameter,
|
|
1678
1737
|
useAIManager,
|
|
1679
1738
|
useAnyEphemeralUserData,
|
|
1739
|
+
useAnyNoyaManager,
|
|
1740
|
+
useAnyNoyaStateContext,
|
|
1680
1741
|
useAsset,
|
|
1681
1742
|
useAssetManager,
|
|
1682
1743
|
useAssets,
|
|
1744
|
+
useColorScheme,
|
|
1683
1745
|
useConnectedUsersManager,
|
|
1684
1746
|
useCurrentUserId,
|
|
1685
1747
|
useIsInitialized,
|
|
@@ -1692,6 +1754,7 @@ export {
|
|
|
1692
1754
|
useSecretManager,
|
|
1693
1755
|
useSecrets,
|
|
1694
1756
|
useSyncStateManager,
|
|
1757
|
+
useViewType,
|
|
1695
1758
|
useWorkflowManager
|
|
1696
1759
|
};
|
|
1697
1760
|
//# sourceMappingURL=index.mjs.map
|