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