@almadar/ui 1.0.20 → 1.0.22

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.
@@ -1,30 +1,7 @@
1
- import { useUISlotManager } from './chunk-7NEWMNNU.js';
2
- import { createContext, useMemo, useContext, useState, useEffect, useCallback } from 'react';
1
+ import { createContext, useMemo, useState, useEffect, useCallback, useContext } from 'react';
3
2
  import { jsx } from 'react/jsx-runtime';
4
3
 
5
- var UISlotContext = createContext(null);
6
- function UISlotProvider({ children }) {
7
- const slotManager = useUISlotManager();
8
- const contextValue = useMemo(() => slotManager, [slotManager]);
9
- return /* @__PURE__ */ jsx(UISlotContext.Provider, { value: contextValue, children });
10
- }
11
- function useUISlots() {
12
- const context = useContext(UISlotContext);
13
- if (!context) {
14
- throw new Error(
15
- "useUISlots must be used within a UISlotProvider. Make sure your component tree is wrapped with <UISlotProvider>."
16
- );
17
- }
18
- return context;
19
- }
20
- function useSlotContent(slot) {
21
- const { getContent } = useUISlots();
22
- return getContent(slot);
23
- }
24
- function useSlotHasContent(slot) {
25
- const { hasContent } = useUISlots();
26
- return hasContent(slot);
27
- }
4
+ // context/ThemeContext.tsx
28
5
  var BUILT_IN_THEMES = [
29
6
  {
30
7
  name: "wireframe",
@@ -43,6 +20,85 @@ var BUILT_IN_THEMES = [
43
20
  displayName: "Almadar",
44
21
  hasLightMode: true,
45
22
  hasDarkMode: true
23
+ },
24
+ {
25
+ name: "trait-wars",
26
+ displayName: "Trait Wars",
27
+ hasLightMode: false,
28
+ hasDarkMode: true
29
+ },
30
+ // Extended themes
31
+ {
32
+ name: "ocean",
33
+ displayName: "Ocean",
34
+ hasLightMode: true,
35
+ hasDarkMode: true
36
+ },
37
+ {
38
+ name: "forest",
39
+ displayName: "Forest",
40
+ hasLightMode: true,
41
+ hasDarkMode: true
42
+ },
43
+ {
44
+ name: "sunset",
45
+ displayName: "Sunset",
46
+ hasLightMode: true,
47
+ hasDarkMode: true
48
+ },
49
+ {
50
+ name: "lavender",
51
+ displayName: "Lavender",
52
+ hasLightMode: true,
53
+ hasDarkMode: true
54
+ },
55
+ {
56
+ name: "rose",
57
+ displayName: "Rose",
58
+ hasLightMode: true,
59
+ hasDarkMode: true
60
+ },
61
+ {
62
+ name: "slate",
63
+ displayName: "Slate",
64
+ hasLightMode: true,
65
+ hasDarkMode: true
66
+ },
67
+ {
68
+ name: "ember",
69
+ displayName: "Ember",
70
+ hasLightMode: true,
71
+ hasDarkMode: true
72
+ },
73
+ {
74
+ name: "midnight",
75
+ displayName: "Midnight",
76
+ hasLightMode: true,
77
+ hasDarkMode: true
78
+ },
79
+ {
80
+ name: "sand",
81
+ displayName: "Sand",
82
+ hasLightMode: true,
83
+ hasDarkMode: true
84
+ },
85
+ {
86
+ name: "neon",
87
+ displayName: "Neon",
88
+ hasLightMode: true,
89
+ hasDarkMode: true
90
+ },
91
+ {
92
+ name: "arctic",
93
+ displayName: "Arctic",
94
+ hasLightMode: true,
95
+ hasDarkMode: true
96
+ },
97
+ {
98
+ name: "copper",
99
+ displayName: "Copper",
100
+ hasLightMode: true,
101
+ hasDarkMode: true
46
102
  }
47
103
  ];
48
104
  var ThemeContext = createContext(void 0);
@@ -187,4 +243,4 @@ function useTheme() {
187
243
  }
188
244
  var ThemeContext_default = ThemeContext;
189
245
 
190
- export { BUILT_IN_THEMES, ThemeContext_default, ThemeProvider, UISlotContext, UISlotProvider, useSlotContent, useSlotHasContent, useTheme, useUISlots };
246
+ export { BUILT_IN_THEMES, ThemeContext_default, ThemeProvider, useTheme };
@@ -1,5 +1,5 @@
1
1
  import { apiClient } from './chunk-XSEDIUM6.js';
2
- import { useEventBus, SelectionContext } from './chunk-TTXKOHDO.js';
2
+ import { useEventBus, SelectionContext, entityDataKeys } from './chunk-WXFQV3ZP.js';
3
3
  import { subscribe, getSnapshot, clearEntities, removeEntity, updateSingleton, updateEntity, spawnEntity, getSingleton, getAllEntities, getByType, getEntity } from './chunk-N7MVUW4R.js';
4
4
  import { useCallback, useState, useEffect, useMemo, useContext, useSyncExternalStore } from 'react';
5
5
  import { useQueryClient, useMutation, useQuery } from '@tanstack/react-query';
@@ -985,118 +985,6 @@ function useSelectionContext() {
985
985
  const context = useContext(SelectionContext);
986
986
  return context;
987
987
  }
988
- var entityDataKeys = {
989
- all: ["entities"],
990
- lists: () => [...entityDataKeys.all, "list"],
991
- list: (entity, filters) => [...entityDataKeys.lists(), entity, filters],
992
- details: () => [...entityDataKeys.all, "detail"],
993
- detail: (entity, id) => [...entityDataKeys.details(), entity, id]
994
- };
995
- function useEntityList(entity, options = {}) {
996
- const { skip = false } = options;
997
- const [data, setData] = useState([]);
998
- const [isLoading, setIsLoading] = useState(!skip && !!entity);
999
- const [error, setError] = useState(null);
1000
- const refetch = () => {
1001
- if (!entity || skip) return;
1002
- setIsLoading(true);
1003
- setError(null);
1004
- setTimeout(() => {
1005
- setData([]);
1006
- setIsLoading(false);
1007
- }, 100);
1008
- };
1009
- useEffect(() => {
1010
- if (skip || !entity) {
1011
- setIsLoading(false);
1012
- return;
1013
- }
1014
- refetch();
1015
- }, [entity, skip]);
1016
- return { data, isLoading, error, refetch };
1017
- }
1018
- function useEntity(entity, id) {
1019
- const [data, setData] = useState(null);
1020
- const [isLoading, setIsLoading] = useState(!!entity && !!id);
1021
- const [error, setError] = useState(null);
1022
- useEffect(() => {
1023
- if (!entity || !id) {
1024
- setIsLoading(false);
1025
- return;
1026
- }
1027
- setIsLoading(true);
1028
- setTimeout(() => {
1029
- setData(null);
1030
- setIsLoading(false);
1031
- }, 100);
1032
- }, [entity, id]);
1033
- return { data, isLoading, error };
1034
- }
1035
- function useEntityDetail(entity, id) {
1036
- const [data, setData] = useState(null);
1037
- const [isLoading, setIsLoading] = useState(!!entity && !!id);
1038
- const [error, setError] = useState(null);
1039
- const refetch = () => {
1040
- if (!entity || !id) return;
1041
- setIsLoading(true);
1042
- setError(null);
1043
- setTimeout(() => {
1044
- setData(null);
1045
- setIsLoading(false);
1046
- }, 100);
1047
- };
1048
- useEffect(() => {
1049
- if (!entity || !id) {
1050
- setIsLoading(false);
1051
- return;
1052
- }
1053
- refetch();
1054
- }, [entity, id]);
1055
- return { data, isLoading, error, refetch };
1056
- }
1057
- function usePaginatedEntityList(entity, params, options = {}) {
1058
- const { skip = false } = options;
1059
- const [data, setData] = useState([]);
1060
- const [isLoading, setIsLoading] = useState(!skip && !!entity);
1061
- const [error, setError] = useState(null);
1062
- const [totalCount, setTotalCount] = useState(0);
1063
- const refetch = () => {
1064
- if (!entity || skip) return;
1065
- setIsLoading(true);
1066
- setError(null);
1067
- setTimeout(() => {
1068
- setData([]);
1069
- setTotalCount(0);
1070
- setIsLoading(false);
1071
- }, 100);
1072
- };
1073
- useEffect(() => {
1074
- if (skip || !entity) {
1075
- setIsLoading(false);
1076
- return;
1077
- }
1078
- refetch();
1079
- }, [
1080
- entity,
1081
- params.page,
1082
- params.pageSize,
1083
- params.search,
1084
- params.sortBy,
1085
- params.sortDirection,
1086
- skip
1087
- ]);
1088
- const totalPages = Math.ceil(totalCount / params.pageSize) || 1;
1089
- return {
1090
- data,
1091
- isLoading,
1092
- error,
1093
- totalCount,
1094
- totalPages,
1095
- hasNextPage: params.page < totalPages,
1096
- hasPreviousPage: params.page > 1,
1097
- refetch
1098
- };
1099
- }
1100
988
  var queryStores = /* @__PURE__ */ new Map();
1101
989
  function getOrCreateStore(query) {
1102
990
  if (!queryStores.has(query)) {
@@ -1465,7 +1353,7 @@ function useEntities() {
1465
1353
  clearEntities
1466
1354
  };
1467
1355
  }
1468
- function useEntity2(id) {
1356
+ function useEntity(id) {
1469
1357
  const entities = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
1470
1358
  return entities.get(id);
1471
1359
  }
@@ -1584,4 +1472,4 @@ function useGitHubBranches(owner, repo, enabled = true) {
1584
1472
  });
1585
1473
  }
1586
1474
 
1587
- export { ENTITY_EVENTS, entityDataKeys, parseQueryBinding, useAgentChat, useAuthContext, useCompile, useConnectGitHub, useCreateEntity, useDeepAgentGeneration, useDeleteEntity, useDisconnectGitHub, useEntities, useEntitiesByType, useEntity, useEntity2, useEntityDetail, useEntityList, useEntityMutations, useExtensions, useFileEditor, useFileSystem, useGitHubBranches, useGitHubRepo, useGitHubRepos, useGitHubStatus, useInput, useOrbitalHistory, useOrbitalMutations, usePaginatedEntityList, usePhysics, usePlayer, usePreview, useQuerySingleton, useSelectedEntity, useSendOrbitalEvent, useSingletonEntity, useUIEvents, useUpdateEntity, useValidation };
1475
+ export { ENTITY_EVENTS, parseQueryBinding, useAgentChat, useAuthContext, useCompile, useConnectGitHub, useCreateEntity, useDeepAgentGeneration, useDeleteEntity, useDisconnectGitHub, useEntities, useEntitiesByType, useEntity, useEntityMutations, useExtensions, useFileEditor, useFileSystem, useGitHubBranches, useGitHubRepo, useGitHubRepos, useGitHubStatus, useInput, useOrbitalHistory, useOrbitalMutations, usePhysics, usePlayer, usePreview, useQuerySingleton, useSelectedEntity, useSendOrbitalEvent, useSingletonEntity, useUIEvents, useUpdateEntity, useValidation };
@@ -0,0 +1,29 @@
1
+ import { useUISlotManager } from './chunk-7NEWMNNU.js';
2
+ import { createContext, useMemo, useContext } from 'react';
3
+ import { jsx } from 'react/jsx-runtime';
4
+
5
+ var UISlotContext = createContext(null);
6
+ function UISlotProvider({ children }) {
7
+ const slotManager = useUISlotManager();
8
+ const contextValue = useMemo(() => slotManager, [slotManager]);
9
+ return /* @__PURE__ */ jsx(UISlotContext.Provider, { value: contextValue, children });
10
+ }
11
+ function useUISlots() {
12
+ const context = useContext(UISlotContext);
13
+ if (!context) {
14
+ throw new Error(
15
+ "useUISlots must be used within a UISlotProvider. Make sure your component tree is wrapped with <UISlotProvider>."
16
+ );
17
+ }
18
+ return context;
19
+ }
20
+ function useSlotContent(slot) {
21
+ const { getContent } = useUISlots();
22
+ return getContent(slot);
23
+ }
24
+ function useSlotHasContent(slot) {
25
+ const { hasContent } = useUISlots();
26
+ return hasContent(slot);
27
+ }
28
+
29
+ export { UISlotContext, UISlotProvider, useSlotContent, useSlotHasContent, useUISlots };
@@ -1,4 +1,4 @@
1
- import { createContext, useContext, useRef, useEffect, useCallback, useMemo, useState } from 'react';
1
+ import React2, { createContext, useContext, useRef, useEffect, useCallback, useMemo, useState } from 'react';
2
2
  import { jsx } from 'react/jsx-runtime';
3
3
 
4
4
  // providers/EventBusProvider.tsx
@@ -179,6 +179,152 @@ function EventBusProvider({ children, debug = false }) {
179
179
  }, [contextValue]);
180
180
  return /* @__PURE__ */ jsx(EventBusContext.Provider, { value: contextValue, children });
181
181
  }
182
+ var EntityDataContext = createContext(null);
183
+ function EntityDataProvider({
184
+ adapter,
185
+ children
186
+ }) {
187
+ return React2.createElement(
188
+ EntityDataContext.Provider,
189
+ { value: adapter },
190
+ children
191
+ );
192
+ }
193
+ function useEntityDataAdapter() {
194
+ return useContext(EntityDataContext);
195
+ }
196
+ var entityDataKeys = {
197
+ all: ["entities"],
198
+ lists: () => [...entityDataKeys.all, "list"],
199
+ list: (entity, filters) => [...entityDataKeys.lists(), entity, filters],
200
+ details: () => [...entityDataKeys.all, "detail"],
201
+ detail: (entity, id) => [...entityDataKeys.details(), entity, id]
202
+ };
203
+ function useEntityList(entity, options = {}) {
204
+ const { skip = false } = options;
205
+ const adapter = useContext(EntityDataContext);
206
+ const adapterData = useMemo(() => {
207
+ if (!adapter || !entity || skip) return [];
208
+ return adapter.getData(entity);
209
+ }, [adapter, entity, skip, adapter?.isLoading]);
210
+ const [stubData, setStubData] = useState([]);
211
+ const [stubLoading, setStubLoading] = useState(!skip && !!entity && !adapter);
212
+ const [stubError, setStubError] = useState(null);
213
+ useEffect(() => {
214
+ if (adapter || skip || !entity) {
215
+ setStubLoading(false);
216
+ return;
217
+ }
218
+ setStubLoading(true);
219
+ const t = setTimeout(() => {
220
+ setStubData([]);
221
+ setStubLoading(false);
222
+ }, 100);
223
+ return () => clearTimeout(t);
224
+ }, [entity, skip, adapter]);
225
+ if (adapter) {
226
+ return {
227
+ data: adapterData,
228
+ isLoading: adapter.isLoading,
229
+ error: adapter.error ? new Error(adapter.error) : null,
230
+ refetch: () => {
231
+ }
232
+ };
233
+ }
234
+ return { data: stubData, isLoading: stubLoading, error: stubError, refetch: () => {
235
+ } };
236
+ }
237
+ function useEntity(entity, id) {
238
+ const adapter = useContext(EntityDataContext);
239
+ const adapterData = useMemo(() => {
240
+ if (!adapter || !entity || !id) return null;
241
+ return adapter.getById(entity, id) ?? null;
242
+ }, [adapter, entity, id, adapter?.isLoading]);
243
+ const [stubData, setStubData] = useState(null);
244
+ const [stubLoading, setStubLoading] = useState(!!entity && !!id && !adapter);
245
+ const [stubError, setStubError] = useState(null);
246
+ useEffect(() => {
247
+ if (adapter || !entity || !id) {
248
+ setStubLoading(false);
249
+ return;
250
+ }
251
+ setStubLoading(true);
252
+ const t = setTimeout(() => {
253
+ setStubData(null);
254
+ setStubLoading(false);
255
+ }, 100);
256
+ return () => clearTimeout(t);
257
+ }, [entity, id, adapter]);
258
+ if (adapter) {
259
+ return {
260
+ data: adapterData,
261
+ isLoading: adapter.isLoading,
262
+ error: adapter.error ? new Error(adapter.error) : null
263
+ };
264
+ }
265
+ return { data: stubData, isLoading: stubLoading, error: stubError };
266
+ }
267
+ function useEntityDetail(entity, id) {
268
+ const result = useEntity(entity, id);
269
+ return { ...result, refetch: () => {
270
+ } };
271
+ }
272
+ function usePaginatedEntityList(entity, params, options = {}) {
273
+ const { skip = false } = options;
274
+ const adapter = useContext(EntityDataContext);
275
+ const adapterResult = useMemo(() => {
276
+ if (!adapter || !entity || skip) {
277
+ return { data: [], totalCount: 0 };
278
+ }
279
+ const all = adapter.getData(entity);
280
+ const start = (params.page - 1) * params.pageSize;
281
+ const paged = all.slice(start, start + params.pageSize);
282
+ return { data: paged, totalCount: all.length };
283
+ }, [adapter, entity, skip, params.page, params.pageSize, adapter?.isLoading]);
284
+ const [stubData, setStubData] = useState([]);
285
+ const [stubLoading, setStubLoading] = useState(!skip && !!entity && !adapter);
286
+ const [stubError, setStubError] = useState(null);
287
+ const [stubTotalCount, setStubTotalCount] = useState(0);
288
+ useEffect(() => {
289
+ if (adapter || skip || !entity) {
290
+ setStubLoading(false);
291
+ return;
292
+ }
293
+ setStubLoading(true);
294
+ const t = setTimeout(() => {
295
+ setStubData([]);
296
+ setStubTotalCount(0);
297
+ setStubLoading(false);
298
+ }, 100);
299
+ return () => clearTimeout(t);
300
+ }, [entity, params.page, params.pageSize, params.search, params.sortBy, params.sortDirection, skip, adapter]);
301
+ const totalCount = adapter ? adapterResult.totalCount : stubTotalCount;
302
+ const totalPages = Math.ceil(totalCount / params.pageSize) || 1;
303
+ if (adapter) {
304
+ return {
305
+ data: adapterResult.data,
306
+ isLoading: adapter.isLoading,
307
+ error: adapter.error ? new Error(adapter.error) : null,
308
+ totalCount: adapterResult.totalCount,
309
+ totalPages,
310
+ hasNextPage: params.page < totalPages,
311
+ hasPreviousPage: params.page > 1,
312
+ refetch: () => {
313
+ }
314
+ };
315
+ }
316
+ return {
317
+ data: stubData,
318
+ isLoading: stubLoading,
319
+ error: stubError,
320
+ totalCount: stubTotalCount,
321
+ totalPages,
322
+ hasNextPage: params.page < totalPages,
323
+ hasPreviousPage: params.page > 1,
324
+ refetch: () => {
325
+ }
326
+ };
327
+ }
182
328
  var SelectionContext = createContext(null);
183
329
  var defaultCompareEntities = (a, b) => {
184
330
  if (a === b) return true;
@@ -267,4 +413,4 @@ function useSelectionOptional() {
267
413
  return context;
268
414
  }
269
415
 
270
- export { EventBusContext, EventBusProvider, SelectionContext, SelectionProvider, useEmitEvent, useEventBus, useEventListener, useSelection, useSelectionOptional };
416
+ export { EntityDataProvider, EventBusContext, EventBusProvider, SelectionContext, SelectionProvider, entityDataKeys, useEmitEvent, useEntity, useEntityDataAdapter, useEntityDetail, useEntityList, useEventBus, useEventListener, usePaginatedEntityList, useSelection, useSelectionOptional };