@almadar/ui 3.9.1 → 4.0.1

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.
@@ -14,13 +14,9 @@ export { useEventBus, useEventListener, useEmitEvent } from './useEventBus';
14
14
  export type { BusEvent, BusEventSource, EventListener, Unsubscribe, EventBusContextType, } from './event-bus-types';
15
15
  export { useUISlotManager, DEFAULT_SLOTS, type UISlot, type SlotAnimation, type SlotContent, type RenderUIConfig, type SlotChangeCallback, type UISlotManager, } from './useUISlots';
16
16
  export { useUIEvents, useSelectedEntity } from './useUIEvents';
17
- export { useEntityList, useEntityDetail, useEntity, useEntityListSuspense, useEntitySuspense, entityDataKeys, EntityDataProvider, useEntityDataAdapter, type EntityDataAdapter, type EntityDataRecord, type UseEntityListOptions, type UseEntityListResult, type UseEntityDetailResult, } from './useEntityData';
18
17
  export { useQuerySingleton, parseQueryBinding, type QueryState, type QuerySingletonEntity, type QuerySingletonResult, type QuerySingletonState, } from './useQuerySingleton';
19
- export { useEntityMutations, useCreateEntity, useUpdateEntity, useDeleteEntity, type EntityMutationResult, type UseEntityMutationsOptions, } from './useEntityMutations';
20
- export { useOrbitalMutations, useSendOrbitalEvent, ENTITY_EVENTS, type OrbitalEventPayload, type OrbitalEventResponse, } from './useOrbitalMutations';
21
18
  export { useEntities, useEntity as useEntityById, useEntitiesByType, useSingletonEntity, usePlayer, usePhysics, useInput, spawnEntity, updateEntity, updateSingleton, removeEntity, clearEntities, getEntity, getByType, getAllEntities, getSingleton, type Entity, } from './useEntities';
22
19
  export { useTranslate, I18nProvider, createTranslate, type TranslateFunction, type I18nContextValue, } from './useTranslate';
23
- export { useResolvedEntity, type ResolvedEntity, } from './useResolvedEntity';
24
20
  export { useAuthContext, type AuthUser, type AuthContextValue, } from './useAuthContext';
25
21
  export { useSwipeGesture, type SwipeGestureOptions, type SwipeGestureResult, type SwipeHandlers, } from './useSwipeGesture';
26
22
  export { useLongPress, type LongPressOptions, type LongPressHandlers, } from './useLongPress';
@@ -1,13 +1,10 @@
1
- import React, { createContext, useCallback, useState, useEffect, useMemo, useContext, useRef, useSyncExternalStore } from 'react';
1
+ import { createContext, useCallback, useState, useEffect, useMemo, useContext, useRef, useSyncExternalStore } from 'react';
2
2
  import { EventBusContext, SelectionContext } from '@almadar/ui/providers';
3
- import { useQueryClient, useMutation, useQuery } from '@tanstack/react-query';
3
+ import { useQuery, useQueryClient, useMutation } from '@tanstack/react-query';
4
4
 
5
- var __defProp = Object.defineProperty;
6
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
7
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
8
5
  function useOrbitalHistory(options) {
9
6
  const { appId, authToken, userId, onHistoryChange, onRevertSuccess } = options;
10
- const getHeaders2 = useCallback(() => {
7
+ const getHeaders = useCallback(() => {
11
8
  const headers = {
12
9
  "Content-Type": "application/json"
13
10
  };
@@ -28,7 +25,7 @@ function useOrbitalHistory(options) {
28
25
  setIsLoading(true);
29
26
  setError(null);
30
27
  try {
31
- const headers = getHeaders2();
28
+ const headers = getHeaders();
32
29
  const [changesetsRes, snapshotsRes] = await Promise.all([
33
30
  fetch(`/api/graphs/${appId}/history/changesets`, { headers }),
34
31
  fetch(`/api/graphs/${appId}/history/snapshots`, { headers })
@@ -71,7 +68,7 @@ function useOrbitalHistory(options) {
71
68
  } finally {
72
69
  setIsLoading(false);
73
70
  }
74
- }, [appId, getHeaders2]);
71
+ }, [appId, getHeaders]);
75
72
  const revertToSnapshot = useCallback(async (snapshotId) => {
76
73
  if (!appId) {
77
74
  return { success: false, error: "No app ID provided" };
@@ -79,7 +76,7 @@ function useOrbitalHistory(options) {
79
76
  try {
80
77
  const response = await fetch(`/api/graphs/${appId}/history/revert/${snapshotId}`, {
81
78
  method: "POST",
82
- headers: getHeaders2()
79
+ headers: getHeaders()
83
80
  });
84
81
  if (!response.ok) {
85
82
  const errorData = await response.json().catch(() => ({}));
@@ -105,7 +102,7 @@ function useOrbitalHistory(options) {
105
102
  error: err instanceof Error ? err.message : "Failed to revert"
106
103
  };
107
104
  }
108
- }, [appId, getHeaders2, refresh, onRevertSuccess]);
105
+ }, [appId, getHeaders, refresh, onRevertSuccess]);
109
106
  useEffect(() => {
110
107
  if (appId && authToken && userId) {
111
108
  refresh();
@@ -1312,208 +1309,6 @@ function useSelectionContext() {
1312
1309
  const context = useContext(SelectionContext);
1313
1310
  return context;
1314
1311
  }
1315
- var EntityDataContext = createContext(null);
1316
- function EntityDataProvider({
1317
- adapter,
1318
- children
1319
- }) {
1320
- return React.createElement(
1321
- EntityDataContext.Provider,
1322
- { value: adapter },
1323
- children
1324
- );
1325
- }
1326
- function useEntityDataAdapter() {
1327
- return useContext(EntityDataContext);
1328
- }
1329
- var entityDataKeys = {
1330
- all: ["entities"],
1331
- lists: () => [...entityDataKeys.all, "list"],
1332
- list: (entity, filters) => [...entityDataKeys.lists(), entity, filters],
1333
- details: () => [...entityDataKeys.all, "detail"],
1334
- detail: (entity, id) => [...entityDataKeys.details(), entity, id]
1335
- };
1336
- function useEntityList(entity, options = {}) {
1337
- const { skip = false } = options;
1338
- const adapter = useContext(EntityDataContext);
1339
- const adapterData = useMemo(() => {
1340
- if (!adapter || !entity || skip) return [];
1341
- return adapter.getData(entity);
1342
- }, [adapter, entity, skip, adapter?.isLoading]);
1343
- const [stubData, setStubData] = useState([]);
1344
- const [stubLoading, setStubLoading] = useState(!skip && !!entity && !adapter);
1345
- const [stubError, setStubError] = useState(null);
1346
- useEffect(() => {
1347
- if (adapter || skip || !entity) {
1348
- setStubLoading(false);
1349
- return;
1350
- }
1351
- setStubLoading(true);
1352
- const t = setTimeout(() => {
1353
- setStubData([]);
1354
- setStubLoading(false);
1355
- }, 100);
1356
- return () => clearTimeout(t);
1357
- }, [entity, skip, adapter]);
1358
- if (adapter) {
1359
- return {
1360
- data: adapterData,
1361
- isLoading: adapter.isLoading,
1362
- error: adapter.error ? new Error(adapter.error) : null,
1363
- refetch: () => {
1364
- }
1365
- };
1366
- }
1367
- return { data: stubData, isLoading: stubLoading, error: stubError, refetch: () => {
1368
- } };
1369
- }
1370
- function useEntity(entity, id) {
1371
- const adapter = useContext(EntityDataContext);
1372
- const adapterData = useMemo(() => {
1373
- if (!adapter || !entity || !id) return null;
1374
- return adapter.getById(entity, id) ?? null;
1375
- }, [adapter, entity, id, adapter?.isLoading]);
1376
- const [stubData, setStubData] = useState(null);
1377
- const [stubLoading, setStubLoading] = useState(!!entity && !!id && !adapter);
1378
- const [stubError, setStubError] = useState(null);
1379
- useEffect(() => {
1380
- if (adapter || !entity || !id) {
1381
- setStubLoading(false);
1382
- return;
1383
- }
1384
- setStubLoading(true);
1385
- const t = setTimeout(() => {
1386
- setStubData(null);
1387
- setStubLoading(false);
1388
- }, 100);
1389
- return () => clearTimeout(t);
1390
- }, [entity, id, adapter]);
1391
- if (adapter) {
1392
- return {
1393
- data: adapterData,
1394
- isLoading: adapter.isLoading,
1395
- error: adapter.error ? new Error(adapter.error) : null
1396
- };
1397
- }
1398
- return { data: stubData, isLoading: stubLoading, error: stubError };
1399
- }
1400
- function useEntityDetail(entity, id) {
1401
- const result = useEntity(entity, id);
1402
- return { ...result, refetch: () => {
1403
- } };
1404
- }
1405
- var suspenseCache = /* @__PURE__ */ new Map();
1406
- function getSuspenseCacheKey(entity, type, id) {
1407
- return id ? `${type}:${entity}:${id}` : `${type}:${entity}`;
1408
- }
1409
- function useEntityListSuspense(entity) {
1410
- const adapter = useContext(EntityDataContext);
1411
- if (adapter) {
1412
- if (adapter.isLoading) {
1413
- const cacheKey2 = getSuspenseCacheKey(entity, "list");
1414
- let entry2 = suspenseCache.get(cacheKey2);
1415
- if (!entry2 || entry2.status === "resolved") {
1416
- let resolve;
1417
- const promise = new Promise((r) => {
1418
- resolve = r;
1419
- });
1420
- entry2 = { promise, status: "pending" };
1421
- suspenseCache.set(cacheKey2, entry2);
1422
- const check = setInterval(() => {
1423
- if (!adapter.isLoading) {
1424
- clearInterval(check);
1425
- entry2.status = "resolved";
1426
- resolve();
1427
- }
1428
- }, 50);
1429
- }
1430
- if (entry2.status === "pending") {
1431
- throw entry2.promise;
1432
- }
1433
- }
1434
- if (adapter.error) {
1435
- throw new Error(adapter.error);
1436
- }
1437
- return {
1438
- data: adapter.getData(entity),
1439
- refetch: () => {
1440
- }
1441
- };
1442
- }
1443
- const cacheKey = getSuspenseCacheKey(entity, "list");
1444
- let entry = suspenseCache.get(cacheKey);
1445
- if (!entry) {
1446
- let resolve;
1447
- const promise = new Promise((r) => {
1448
- resolve = r;
1449
- setTimeout(() => {
1450
- entry.status = "resolved";
1451
- resolve();
1452
- }, 100);
1453
- });
1454
- entry = { promise, status: "pending" };
1455
- suspenseCache.set(cacheKey, entry);
1456
- }
1457
- if (entry.status === "pending") {
1458
- throw entry.promise;
1459
- }
1460
- return { data: [], refetch: () => {
1461
- } };
1462
- }
1463
- function useEntitySuspense(entity, id) {
1464
- const adapter = useContext(EntityDataContext);
1465
- if (adapter) {
1466
- if (adapter.isLoading) {
1467
- const cacheKey2 = getSuspenseCacheKey(entity, "detail", id);
1468
- let entry2 = suspenseCache.get(cacheKey2);
1469
- if (!entry2 || entry2.status === "resolved") {
1470
- let resolve;
1471
- const promise = new Promise((r) => {
1472
- resolve = r;
1473
- });
1474
- entry2 = { promise, status: "pending" };
1475
- suspenseCache.set(cacheKey2, entry2);
1476
- const check = setInterval(() => {
1477
- if (!adapter.isLoading) {
1478
- clearInterval(check);
1479
- entry2.status = "resolved";
1480
- resolve();
1481
- }
1482
- }, 50);
1483
- }
1484
- if (entry2.status === "pending") {
1485
- throw entry2.promise;
1486
- }
1487
- }
1488
- if (adapter.error) {
1489
- throw new Error(adapter.error);
1490
- }
1491
- return {
1492
- data: adapter.getById(entity, id) ?? null,
1493
- refetch: () => {
1494
- }
1495
- };
1496
- }
1497
- const cacheKey = getSuspenseCacheKey(entity, "detail", id);
1498
- let entry = suspenseCache.get(cacheKey);
1499
- if (!entry) {
1500
- let resolve;
1501
- const promise = new Promise((r) => {
1502
- resolve = r;
1503
- setTimeout(() => {
1504
- entry.status = "resolved";
1505
- resolve();
1506
- }, 100);
1507
- });
1508
- entry = { promise, status: "pending" };
1509
- suspenseCache.set(cacheKey, entry);
1510
- }
1511
- if (entry.status === "pending") {
1512
- throw entry.promise;
1513
- }
1514
- return { data: null, refetch: () => {
1515
- } };
1516
- }
1517
1312
  var queryStores = /* @__PURE__ */ new Map();
1518
1313
  function getOrCreateStore(query) {
1519
1314
  if (!queryStores.has(query)) {
@@ -1581,385 +1376,6 @@ function parseQueryBinding(binding) {
1581
1376
  };
1582
1377
  }
1583
1378
 
1584
- // lib/api-client.ts
1585
- var API_BASE_URL = typeof process !== "undefined" && process.env?.VITE_API_URL ? process.env.VITE_API_URL : "/api";
1586
- var ApiError = class extends Error {
1587
- constructor(status, statusText, message) {
1588
- super(message || `API Error: ${status} ${statusText}`);
1589
- __publicField(this, "status", status);
1590
- __publicField(this, "statusText", statusText);
1591
- this.name = "ApiError";
1592
- }
1593
- };
1594
- async function handleResponse(response) {
1595
- if (!response.ok) {
1596
- let message;
1597
- try {
1598
- const errorData = await response.json();
1599
- message = errorData.message || errorData.error;
1600
- } catch {
1601
- }
1602
- throw new ApiError(response.status, response.statusText, message);
1603
- }
1604
- const text = await response.text();
1605
- if (!text) {
1606
- return void 0;
1607
- }
1608
- return JSON.parse(text);
1609
- }
1610
- function getHeaders() {
1611
- const headers = {
1612
- "Content-Type": "application/json"
1613
- };
1614
- const token = typeof localStorage !== "undefined" ? localStorage.getItem("authToken") : null;
1615
- if (token) {
1616
- headers["Authorization"] = `Bearer ${token}`;
1617
- }
1618
- return headers;
1619
- }
1620
- var apiClient = {
1621
- /**
1622
- * GET request
1623
- */
1624
- async get(endpoint) {
1625
- const response = await fetch(`${API_BASE_URL}${endpoint}`, {
1626
- method: "GET",
1627
- headers: getHeaders()
1628
- });
1629
- return handleResponse(response);
1630
- },
1631
- /**
1632
- * POST request
1633
- */
1634
- async post(endpoint, data) {
1635
- const response = await fetch(`${API_BASE_URL}${endpoint}`, {
1636
- method: "POST",
1637
- headers: getHeaders(),
1638
- body: data ? JSON.stringify(data) : void 0
1639
- });
1640
- return handleResponse(response);
1641
- },
1642
- /**
1643
- * PUT request
1644
- */
1645
- async put(endpoint, data) {
1646
- const response = await fetch(`${API_BASE_URL}${endpoint}`, {
1647
- method: "PUT",
1648
- headers: getHeaders(),
1649
- body: data ? JSON.stringify(data) : void 0
1650
- });
1651
- return handleResponse(response);
1652
- },
1653
- /**
1654
- * PATCH request
1655
- */
1656
- async patch(endpoint, data) {
1657
- const response = await fetch(`${API_BASE_URL}${endpoint}`, {
1658
- method: "PATCH",
1659
- headers: getHeaders(),
1660
- body: data ? JSON.stringify(data) : void 0
1661
- });
1662
- return handleResponse(response);
1663
- },
1664
- /**
1665
- * DELETE request
1666
- */
1667
- async delete(endpoint) {
1668
- const response = await fetch(`${API_BASE_URL}${endpoint}`, {
1669
- method: "DELETE",
1670
- headers: getHeaders()
1671
- });
1672
- return handleResponse(response);
1673
- }
1674
- };
1675
- var ENTITY_EVENTS = {
1676
- CREATE: "ENTITY_CREATE",
1677
- UPDATE: "ENTITY_UPDATE",
1678
- DELETE: "ENTITY_DELETE"
1679
- };
1680
- async function sendOrbitalEvent(orbitalName, eventPayload) {
1681
- const response = await apiClient.post(
1682
- `/orbitals/${orbitalName}/events`,
1683
- eventPayload
1684
- );
1685
- return response;
1686
- }
1687
- function useOrbitalMutations(entityName, orbitalName, options) {
1688
- const queryClient = useQueryClient();
1689
- const events = {
1690
- create: options?.events?.create || ENTITY_EVENTS.CREATE,
1691
- update: options?.events?.update || ENTITY_EVENTS.UPDATE,
1692
- delete: options?.events?.delete || ENTITY_EVENTS.DELETE
1693
- };
1694
- const log2 = (message, data) => {
1695
- if (options?.debug) {
1696
- console.log(`[useOrbitalMutations:${orbitalName}] ${message}`, data ?? "");
1697
- }
1698
- };
1699
- const createMutation = useMutation({
1700
- mutationFn: async (data) => {
1701
- log2("Creating entity", data);
1702
- return sendOrbitalEvent(orbitalName, {
1703
- event: events.create,
1704
- payload: { data, entityType: entityName }
1705
- });
1706
- },
1707
- onSuccess: (response) => {
1708
- log2("Create succeeded", response);
1709
- queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1710
- },
1711
- onError: (error) => {
1712
- console.error(`[useOrbitalMutations] Create failed:`, error);
1713
- }
1714
- });
1715
- const updateMutation = useMutation({
1716
- mutationFn: async ({
1717
- id,
1718
- data
1719
- }) => {
1720
- log2(`Updating entity ${id}`, data);
1721
- return sendOrbitalEvent(orbitalName, {
1722
- event: events.update,
1723
- entityId: id,
1724
- payload: { data, entityType: entityName }
1725
- });
1726
- },
1727
- onSuccess: (response, variables) => {
1728
- log2("Update succeeded", response);
1729
- queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1730
- queryClient.invalidateQueries({
1731
- queryKey: entityDataKeys.detail(entityName, variables.id)
1732
- });
1733
- },
1734
- onError: (error) => {
1735
- console.error(`[useOrbitalMutations] Update failed:`, error);
1736
- }
1737
- });
1738
- const deleteMutation = useMutation({
1739
- mutationFn: async (id) => {
1740
- log2(`Deleting entity ${id}`);
1741
- return sendOrbitalEvent(orbitalName, {
1742
- event: events.delete,
1743
- entityId: id,
1744
- payload: { entityType: entityName }
1745
- });
1746
- },
1747
- onSuccess: (response, id) => {
1748
- log2("Delete succeeded", response);
1749
- queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1750
- queryClient.removeQueries({ queryKey: entityDataKeys.detail(entityName, id) });
1751
- },
1752
- onError: (error) => {
1753
- console.error(`[useOrbitalMutations] Delete failed:`, error);
1754
- }
1755
- });
1756
- return {
1757
- // Async functions
1758
- createEntity: async (data) => {
1759
- return createMutation.mutateAsync(data);
1760
- },
1761
- updateEntity: async (id, data) => {
1762
- if (!id) {
1763
- console.warn("[useOrbitalMutations] Cannot update without ID");
1764
- return;
1765
- }
1766
- return updateMutation.mutateAsync({ id, data });
1767
- },
1768
- deleteEntity: async (id) => {
1769
- if (!id) {
1770
- console.warn("[useOrbitalMutations] Cannot delete without ID");
1771
- return;
1772
- }
1773
- return deleteMutation.mutateAsync(id);
1774
- },
1775
- // Mutation objects for fine-grained control
1776
- createMutation,
1777
- updateMutation,
1778
- deleteMutation,
1779
- // Aggregate states
1780
- isCreating: createMutation.isPending,
1781
- isUpdating: updateMutation.isPending,
1782
- isDeleting: deleteMutation.isPending,
1783
- isMutating: createMutation.isPending || updateMutation.isPending || deleteMutation.isPending,
1784
- // Errors
1785
- createError: createMutation.error,
1786
- updateError: updateMutation.error,
1787
- deleteError: deleteMutation.error
1788
- };
1789
- }
1790
- function useSendOrbitalEvent(orbitalName) {
1791
- const mutation = useMutation({
1792
- mutationFn: async (payload) => {
1793
- return sendOrbitalEvent(orbitalName, payload);
1794
- }
1795
- });
1796
- return {
1797
- sendEvent: async (event, payload, entityId) => {
1798
- return mutation.mutateAsync({ event, payload, entityId });
1799
- },
1800
- isPending: mutation.isPending,
1801
- error: mutation.error,
1802
- data: mutation.data
1803
- };
1804
- }
1805
-
1806
- // hooks/useEntityMutations.ts
1807
- function entityToCollection(entityName) {
1808
- return entityName.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase() + "-list";
1809
- }
1810
- function useCreateEntity(entityName) {
1811
- const queryClient = useQueryClient();
1812
- const collection = entityToCollection(entityName);
1813
- return useMutation({
1814
- mutationFn: async (data) => {
1815
- console.log(`[useCreateEntity] Creating ${entityName}:`, data);
1816
- const response = await apiClient.post(
1817
- `/${collection}`,
1818
- data
1819
- );
1820
- return response.data;
1821
- },
1822
- onSuccess: () => {
1823
- queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1824
- },
1825
- onError: (error) => {
1826
- console.error(`[useCreateEntity] Failed to create ${entityName}:`, error);
1827
- }
1828
- });
1829
- }
1830
- function useUpdateEntity(entityName) {
1831
- const queryClient = useQueryClient();
1832
- const collection = entityToCollection(entityName);
1833
- return useMutation({
1834
- mutationFn: async ({ id, data }) => {
1835
- console.log(`[useUpdateEntity] Updating ${entityName} ${id}:`, data);
1836
- const response = await apiClient.patch(
1837
- `/${collection}/${id}`,
1838
- data
1839
- );
1840
- return response.data;
1841
- },
1842
- onSuccess: (_, variables) => {
1843
- queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1844
- queryClient.invalidateQueries({ queryKey: entityDataKeys.detail(entityName, variables.id) });
1845
- },
1846
- onError: (error) => {
1847
- console.error(`[useUpdateEntity] Failed to update ${entityName}:`, error);
1848
- }
1849
- });
1850
- }
1851
- function useDeleteEntity(entityName) {
1852
- const queryClient = useQueryClient();
1853
- const collection = entityToCollection(entityName);
1854
- return useMutation({
1855
- mutationFn: async (id) => {
1856
- console.log(`[useDeleteEntity] Deleting ${entityName} ${id}`);
1857
- await apiClient.delete(`/${collection}/${id}`);
1858
- return { id };
1859
- },
1860
- onSuccess: (_, id) => {
1861
- queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1862
- queryClient.removeQueries({ queryKey: entityDataKeys.detail(entityName, id) });
1863
- },
1864
- onError: (error) => {
1865
- console.error(`[useDeleteEntity] Failed to delete ${entityName}:`, error);
1866
- }
1867
- });
1868
- }
1869
- async function sendOrbitalMutation(orbitalName, event, entityId, payload) {
1870
- const response = await apiClient.post(
1871
- `/orbitals/${orbitalName}/events`,
1872
- { event, entityId, payload }
1873
- );
1874
- return response;
1875
- }
1876
- function useEntityMutations(entityName, options) {
1877
- const queryClient = useQueryClient();
1878
- const useOrbitalRoute = !!options?.orbitalName;
1879
- const events = {
1880
- create: options?.events?.create || ENTITY_EVENTS.CREATE,
1881
- update: options?.events?.update || ENTITY_EVENTS.UPDATE,
1882
- delete: options?.events?.delete || ENTITY_EVENTS.DELETE
1883
- };
1884
- const createMutation = useCreateEntity(entityName);
1885
- const updateMutation = useUpdateEntity(entityName);
1886
- const deleteMutation = useDeleteEntity(entityName);
1887
- const orbitalCreateMutation = useMutation({
1888
- mutationFn: async (data) => {
1889
- return sendOrbitalMutation(options.orbitalName, events.create, void 0, {
1890
- data,
1891
- entityType: entityName
1892
- });
1893
- },
1894
- onSuccess: () => {
1895
- queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1896
- }
1897
- });
1898
- const orbitalUpdateMutation = useMutation({
1899
- mutationFn: async ({ id, data }) => {
1900
- return sendOrbitalMutation(options.orbitalName, events.update, id, {
1901
- data,
1902
- entityType: entityName
1903
- });
1904
- },
1905
- onSuccess: (_, variables) => {
1906
- queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1907
- queryClient.invalidateQueries({
1908
- queryKey: entityDataKeys.detail(entityName, variables.id)
1909
- });
1910
- }
1911
- });
1912
- const orbitalDeleteMutation = useMutation({
1913
- mutationFn: async (id) => {
1914
- return sendOrbitalMutation(options.orbitalName, events.delete, id, {
1915
- entityType: entityName
1916
- });
1917
- },
1918
- onSuccess: (_, id) => {
1919
- queryClient.invalidateQueries({ queryKey: entityDataKeys.list(entityName) });
1920
- queryClient.removeQueries({ queryKey: entityDataKeys.detail(entityName, id) });
1921
- }
1922
- });
1923
- const activeMutations = {
1924
- create: useOrbitalRoute ? orbitalCreateMutation : createMutation,
1925
- update: useOrbitalRoute ? orbitalUpdateMutation : updateMutation,
1926
- delete: useOrbitalRoute ? orbitalDeleteMutation : deleteMutation
1927
- };
1928
- return {
1929
- // Async functions that can be called directly
1930
- // Accepts either (data) or (entityName, data) for compiler compatibility
1931
- createEntity: async (entityOrData, data) => {
1932
- const actualData = typeof entityOrData === "string" ? data : entityOrData;
1933
- if (!actualData) {
1934
- console.warn("[useEntityMutations] Cannot create entity without data");
1935
- return;
1936
- }
1937
- return activeMutations.create.mutateAsync(actualData);
1938
- },
1939
- updateEntity: async (id, data) => {
1940
- if (!id) {
1941
- console.warn("[useEntityMutations] Cannot update entity without ID");
1942
- return;
1943
- }
1944
- return activeMutations.update.mutateAsync({ id, data });
1945
- },
1946
- deleteEntity: async (id) => {
1947
- if (!id) {
1948
- console.warn("[useEntityMutations] Cannot delete entity without ID");
1949
- return;
1950
- }
1951
- return activeMutations.delete.mutateAsync(id);
1952
- },
1953
- // Mutation states for UI feedback
1954
- isCreating: activeMutations.create.isPending,
1955
- isUpdating: activeMutations.update.isPending,
1956
- isDeleting: activeMutations.delete.isPending,
1957
- createError: activeMutations.create.error,
1958
- updateError: activeMutations.update.error,
1959
- deleteError: activeMutations.delete.error
1960
- };
1961
- }
1962
-
1963
1379
  // stores/entityStore.ts
1964
1380
  var entities = /* @__PURE__ */ new Map();
1965
1381
  var listeners = /* @__PURE__ */ new Set();
@@ -2037,7 +1453,7 @@ function useEntities() {
2037
1453
  clearEntities
2038
1454
  };
2039
1455
  }
2040
- function useEntity2(id) {
1456
+ function useEntity(id) {
2041
1457
  const entities2 = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
2042
1458
  return entities2.get(id);
2043
1459
  }
@@ -2202,26 +1618,6 @@ function createTranslate(messages) {
2202
1618
  return msg;
2203
1619
  };
2204
1620
  }
2205
- function useResolvedEntity(entity, data) {
2206
- const shouldFetch = !data && !!entity;
2207
- const fetched = useEntityList(entity, { skip: !shouldFetch });
2208
- return useMemo(() => {
2209
- if (data) {
2210
- return {
2211
- data,
2212
- isLocal: true,
2213
- isLoading: false,
2214
- error: null
2215
- };
2216
- }
2217
- return {
2218
- data: fetched.data,
2219
- isLocal: false,
2220
- isLoading: fetched.isLoading,
2221
- error: fetched.error
2222
- };
2223
- }, [data, fetched.data, fetched.isLoading, fetched.error]);
2224
- }
2225
1621
 
2226
1622
  // hooks/useAuthContext.ts
2227
1623
  function useAuthContext() {
@@ -2708,4 +2104,4 @@ function useGitHubBranches(owner, repo, enabled = true) {
2708
2104
  });
2709
2105
  }
2710
2106
 
2711
- export { ALMADAR_DND_MIME, DEFAULT_SLOTS, ENTITY_EVENTS, EntityDataProvider, I18nProvider, clearEntities, createTranslate, entityDataKeys, getAllEntities, getByType, getEntity, getSingleton, parseQueryBinding, removeEntity, spawnEntity, updateEntity, updateSingleton, useAgentChat, useAuthContext, useCompile, useConnectGitHub, useCreateEntity, useDeepAgentGeneration, useDeleteEntity, useDisconnectGitHub, useDragReorder, useDraggable, useDropZone, useEmitEvent, useEntities, useEntitiesByType, useEntity, useEntity2 as useEntityById, useEntityDataAdapter, useEntityDetail, useEntityList, useEntityListSuspense, useEntityMutations, useEntitySuspense, useEventBus, useEventListener, useExtensions, useFileEditor, useFileSystem, useGitHubBranches, useGitHubRepo, useGitHubRepos, useGitHubStatus, useInfiniteScroll, useInput, useLongPress, useOrbitalHistory, useOrbitalMutations, usePhysics, usePinchZoom, usePlayer, usePreview, usePullToRefresh, useQuerySingleton, useResolvedEntity, useSelectedEntity, useSendOrbitalEvent, useSingletonEntity, useSwipeGesture, useTranslate, useUIEvents, useUISlotManager, useUpdateEntity, useValidation };
2107
+ export { ALMADAR_DND_MIME, DEFAULT_SLOTS, I18nProvider, clearEntities, createTranslate, getAllEntities, getByType, getEntity, getSingleton, parseQueryBinding, removeEntity, spawnEntity, updateEntity, updateSingleton, useAgentChat, useAuthContext, useCompile, useConnectGitHub, useDeepAgentGeneration, useDisconnectGitHub, useDragReorder, useDraggable, useDropZone, useEmitEvent, useEntities, useEntitiesByType, useEntity as useEntityById, useEventBus, useEventListener, useExtensions, useFileEditor, useFileSystem, useGitHubBranches, useGitHubRepo, useGitHubRepos, useGitHubStatus, useInfiniteScroll, useInput, useLongPress, useOrbitalHistory, usePhysics, usePinchZoom, usePlayer, usePreview, usePullToRefresh, useQuerySingleton, useSelectedEntity, useSingletonEntity, useSwipeGesture, useTranslate, useUIEvents, useUISlotManager, useValidation };