@almadar/ui 5.126.0 → 5.128.0

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,7 +1,8 @@
1
1
  import React__default, { ReactNode } from 'react';
2
2
  import { EntityRow, FieldValue } from '@almadar/core';
3
- import { U as UIThemeDefinition } from '../UserContext-BKckAUv7.cjs';
4
- export { A as ANONYMOUS_USER, a as CurrentPagePathContext, b as CurrentPagePathProvider, c as CurrentPagePathProviderProps, d as DesignThemeProvider, O as OrbitalThemeProvider, e as OrbitalThemeProviderProps, h as UserContext, i as UserContextValue, j as UserData, k as UserProvider, l as UserProviderProps, u as useCurrentPagePath, m as useDesignTheme, n as useHasPermission, o as useHasRole, q as useUser, r as useUserForEvaluation } from '../UserContext-BKckAUv7.cjs';
3
+ export { ANONYMOUS_USER } from '@almadar/core';
4
+ import { U as UIThemeDefinition, j as UserData } from '../UserContext-g_LcDiGN.cjs';
5
+ export { a as CurrentPagePathContext, b as CurrentPagePathProvider, c as CurrentPagePathProviderProps, d as DesignThemeProvider, O as OrbitalThemeProvider, e as OrbitalThemeProviderProps, h as UserContext, i as UserContextValue, k as UserProvider, l as UserProviderProps, u as useCurrentPagePath, m as useDesignTheme, n as useHasPermission, o as useHasRole, q as useUser, r as useUserForEvaluation } from '../UserContext-g_LcDiGN.cjs';
5
6
  export { E as EntitySchemaContextValue, a as EntitySchemaProvider, b as EntitySchemaProviderProps, S as SendEventResult, c as ServerBridgeContextValue, d as ServerBridgeProvider, e as ServerBridgeProviderProps, f as ServerBridgeTransport, g as ServerClientEffect, h as ServerResponseMeta, T as TraitContext, i as TraitContextValue, j as TraitInstance, k as TraitProvider, l as TraitProviderProps, u as useEntitySchema, m as useEntitySchemaOptional, n as useServerBridge, o as useTrait, p as useTraitContext } from '../TraitProvider-Ch79cUcb.cjs';
6
7
  import { U as UseOfflineExecutorResult, a as UseOfflineExecutorOptions } from '../offline-executor-Qz4b6GpF.cjs';
7
8
  export { N as NavigationContextValue, b as NavigationProvider, c as NavigationProviderProps, d as NavigationState, e as comparePathSpecificity, f as extractRouteParams, g as findPageByName, h as findPageByPath, i as getAllPages, j as getDefaultPage, m as matchPath, k as matchPathAmong, p as pathMatches, u as useActivePage, l as useInitPayload, n as useNavigateTo, o as useNavigation, q as useNavigationId, r as useNavigationState } from '../offline-executor-Qz4b6GpF.cjs';
@@ -145,6 +146,7 @@ declare function useSelectionOptional<T = EntityRow>(): SelectionContextType<T>
145
146
  * - ThemeProvider - Theme and color mode management
146
147
  * - EventBusProvider - Page-scoped event pub/sub
147
148
  * - SelectionProvider - Selected entity tracking
149
+ * - UserProvider - the viewer `@user.x` bindings resolve against
148
150
  *
149
151
  * Entity data flows through props (via enrichFromResponse in ServerBridge),
150
152
  * not through context. FetchedDataProvider has been removed.
@@ -188,6 +190,15 @@ interface OrbitalProviderProps {
188
190
  * preview's events don't clobber the host's global bus). Default false.
189
191
  */
190
192
  isolated?: boolean;
193
+ /**
194
+ * The signed-in viewer. Generated trait hooks read `@user.x` through
195
+ * `useUser()`, so without this every role gate takes its negative branch and
196
+ * every ownership-scoped list renders empty — silently, since `useUser()`
197
+ * falls back to anonymous rather than throwing
198
+ * (U-USERPROVIDER-MOUNTED-NOWHERE). Mounting the provider here means every
199
+ * host that already wraps its app in OrbitalProvider only has to pass the user.
200
+ */
201
+ user?: UserData | null;
191
202
  }
192
203
  /**
193
204
  * OrbitalProvider - Unified context provider for Orbital applications
@@ -236,7 +247,7 @@ interface OrbitalProviderProps {
236
247
  * }
237
248
  * ```
238
249
  */
239
- declare function OrbitalProvider({ children, themes, defaultTheme, defaultMode, targetRef, skipTheme, debug, initialData, suspense, verification, isolated, }: OrbitalProviderProps): React__default.ReactElement;
250
+ declare function OrbitalProvider({ children, themes, defaultTheme, defaultMode, targetRef, skipTheme, debug, initialData, suspense, verification, isolated, user, }: OrbitalProviderProps): React__default.ReactElement;
240
251
  declare namespace OrbitalProvider {
241
252
  var displayName: string;
242
253
  }
@@ -454,4 +465,4 @@ declare function useOfflineMode(): OfflineModeContextValue;
454
465
  */
455
466
  declare function useOptionalOfflineMode(): OfflineModeContextValue | null;
456
467
 
457
- export { EventBusContext, EventBusProvider, type OfflineModeContextValue, OfflineModeProvider, type OfflineModeProviderProps, OrbitalProvider, type OrbitalProviderProps, SelectionContext, type SelectionContextType, SelectionProvider, type TraitScope, TraitScopeProvider, type TraitScopeProviderProps, UIThemeDefinition, VerificationProvider, type VerificationProviderProps, useOfflineMode, useOptionalOfflineMode, useSelection, useSelectionOptional, useTraitScope, useTraitScopeChain };
468
+ export { EventBusContext, EventBusProvider, type OfflineModeContextValue, OfflineModeProvider, type OfflineModeProviderProps, OrbitalProvider, type OrbitalProviderProps, SelectionContext, type SelectionContextType, SelectionProvider, type TraitScope, TraitScopeProvider, type TraitScopeProviderProps, UIThemeDefinition, UserData, VerificationProvider, type VerificationProviderProps, useOfflineMode, useOptionalOfflineMode, useSelection, useSelectionOptional, useTraitScope, useTraitScopeChain };
@@ -1,7 +1,8 @@
1
1
  import React__default, { ReactNode } from 'react';
2
2
  import { EntityRow, FieldValue } from '@almadar/core';
3
- import { U as UIThemeDefinition } from '../UserContext-BKckAUv7.js';
4
- export { A as ANONYMOUS_USER, a as CurrentPagePathContext, b as CurrentPagePathProvider, c as CurrentPagePathProviderProps, d as DesignThemeProvider, O as OrbitalThemeProvider, e as OrbitalThemeProviderProps, h as UserContext, i as UserContextValue, j as UserData, k as UserProvider, l as UserProviderProps, u as useCurrentPagePath, m as useDesignTheme, n as useHasPermission, o as useHasRole, q as useUser, r as useUserForEvaluation } from '../UserContext-BKckAUv7.js';
3
+ export { ANONYMOUS_USER } from '@almadar/core';
4
+ import { U as UIThemeDefinition, j as UserData } from '../UserContext-g_LcDiGN.js';
5
+ export { a as CurrentPagePathContext, b as CurrentPagePathProvider, c as CurrentPagePathProviderProps, d as DesignThemeProvider, O as OrbitalThemeProvider, e as OrbitalThemeProviderProps, h as UserContext, i as UserContextValue, k as UserProvider, l as UserProviderProps, u as useCurrentPagePath, m as useDesignTheme, n as useHasPermission, o as useHasRole, q as useUser, r as useUserForEvaluation } from '../UserContext-g_LcDiGN.js';
5
6
  export { E as EntitySchemaContextValue, a as EntitySchemaProvider, b as EntitySchemaProviderProps, S as SendEventResult, c as ServerBridgeContextValue, d as ServerBridgeProvider, e as ServerBridgeProviderProps, f as ServerBridgeTransport, g as ServerClientEffect, h as ServerResponseMeta, T as TraitContext, i as TraitContextValue, j as TraitInstance, k as TraitProvider, l as TraitProviderProps, u as useEntitySchema, m as useEntitySchemaOptional, n as useServerBridge, o as useTrait, p as useTraitContext } from '../TraitProvider-Ch79cUcb.js';
6
7
  import { U as UseOfflineExecutorResult, a as UseOfflineExecutorOptions } from '../offline-executor-Qz4b6GpF.js';
7
8
  export { N as NavigationContextValue, b as NavigationProvider, c as NavigationProviderProps, d as NavigationState, e as comparePathSpecificity, f as extractRouteParams, g as findPageByName, h as findPageByPath, i as getAllPages, j as getDefaultPage, m as matchPath, k as matchPathAmong, p as pathMatches, u as useActivePage, l as useInitPayload, n as useNavigateTo, o as useNavigation, q as useNavigationId, r as useNavigationState } from '../offline-executor-Qz4b6GpF.js';
@@ -145,6 +146,7 @@ declare function useSelectionOptional<T = EntityRow>(): SelectionContextType<T>
145
146
  * - ThemeProvider - Theme and color mode management
146
147
  * - EventBusProvider - Page-scoped event pub/sub
147
148
  * - SelectionProvider - Selected entity tracking
149
+ * - UserProvider - the viewer `@user.x` bindings resolve against
148
150
  *
149
151
  * Entity data flows through props (via enrichFromResponse in ServerBridge),
150
152
  * not through context. FetchedDataProvider has been removed.
@@ -188,6 +190,15 @@ interface OrbitalProviderProps {
188
190
  * preview's events don't clobber the host's global bus). Default false.
189
191
  */
190
192
  isolated?: boolean;
193
+ /**
194
+ * The signed-in viewer. Generated trait hooks read `@user.x` through
195
+ * `useUser()`, so without this every role gate takes its negative branch and
196
+ * every ownership-scoped list renders empty — silently, since `useUser()`
197
+ * falls back to anonymous rather than throwing
198
+ * (U-USERPROVIDER-MOUNTED-NOWHERE). Mounting the provider here means every
199
+ * host that already wraps its app in OrbitalProvider only has to pass the user.
200
+ */
201
+ user?: UserData | null;
191
202
  }
192
203
  /**
193
204
  * OrbitalProvider - Unified context provider for Orbital applications
@@ -236,7 +247,7 @@ interface OrbitalProviderProps {
236
247
  * }
237
248
  * ```
238
249
  */
239
- declare function OrbitalProvider({ children, themes, defaultTheme, defaultMode, targetRef, skipTheme, debug, initialData, suspense, verification, isolated, }: OrbitalProviderProps): React__default.ReactElement;
250
+ declare function OrbitalProvider({ children, themes, defaultTheme, defaultMode, targetRef, skipTheme, debug, initialData, suspense, verification, isolated, user, }: OrbitalProviderProps): React__default.ReactElement;
240
251
  declare namespace OrbitalProvider {
241
252
  var displayName: string;
242
253
  }
@@ -454,4 +465,4 @@ declare function useOfflineMode(): OfflineModeContextValue;
454
465
  */
455
466
  declare function useOptionalOfflineMode(): OfflineModeContextValue | null;
456
467
 
457
- export { EventBusContext, EventBusProvider, type OfflineModeContextValue, OfflineModeProvider, type OfflineModeProviderProps, OrbitalProvider, type OrbitalProviderProps, SelectionContext, type SelectionContextType, SelectionProvider, type TraitScope, TraitScopeProvider, type TraitScopeProviderProps, UIThemeDefinition, VerificationProvider, type VerificationProviderProps, useOfflineMode, useOptionalOfflineMode, useSelection, useSelectionOptional, useTraitScope, useTraitScopeChain };
468
+ export { EventBusContext, EventBusProvider, type OfflineModeContextValue, OfflineModeProvider, type OfflineModeProviderProps, OrbitalProvider, type OrbitalProviderProps, SelectionContext, type SelectionContextType, SelectionProvider, type TraitScope, TraitScopeProvider, type TraitScopeProviderProps, UIThemeDefinition, UserData, VerificationProvider, type VerificationProviderProps, useOfflineMode, useOptionalOfflineMode, useSelection, useSelectionOptional, useTraitScope, useTraitScopeChain };
@@ -68,7 +68,8 @@ import ReactMarkdown from 'react-markdown';
68
68
  import remarkGfm from 'remark-gfm';
69
69
  import remarkMath from 'remark-math';
70
70
  import rehypeKatex from 'rehype-katex';
71
- import { isInlineTrait } from '@almadar/core';
71
+ import { ANONYMOUS_USER, isInlineTrait } from '@almadar/core';
72
+ export { ANONYMOUS_USER } from '@almadar/core';
72
73
  import { DndContext, pointerWithin, rectIntersection, closestCorners, useSensors, useSensor, PointerSensor, KeyboardSensor, useDroppable } from '@dnd-kit/core';
73
74
  import { useSortable, arrayMove, sortableKeyboardCoordinates, SortableContext, rectSortingStrategy, verticalListSortingStrategy } from '@dnd-kit/sortable';
74
75
  import { CSS } from '@dnd-kit/utilities';
@@ -18801,6 +18802,32 @@ var init_ButtonGroup = __esm({
18801
18802
  ButtonGroup.displayName = "ButtonGroup";
18802
18803
  }
18803
18804
  });
18805
+
18806
+ // lib/getNestedValue.ts
18807
+ function getNestedValue(obj, path) {
18808
+ if (obj === null || obj === void 0 || !path) {
18809
+ return void 0;
18810
+ }
18811
+ if (!path.includes(".")) {
18812
+ return obj[path];
18813
+ }
18814
+ const parts = path.split(".");
18815
+ let value = obj;
18816
+ for (const part of parts) {
18817
+ if (value === null || value === void 0) {
18818
+ return void 0;
18819
+ }
18820
+ if (typeof value !== "object" || Array.isArray(value)) {
18821
+ return void 0;
18822
+ }
18823
+ value = value[part];
18824
+ }
18825
+ return value;
18826
+ }
18827
+ var init_getNestedValue = __esm({
18828
+ "lib/getNestedValue.ts"() {
18829
+ }
18830
+ });
18804
18831
  function useSwipeGesture(callbacks, options = {}) {
18805
18832
  const { threshold = 50, velocityThreshold = 0.3, preventDefault = false } = options;
18806
18833
  const startX = useRef(0);
@@ -18914,11 +18941,15 @@ function getWeekDays(start) {
18914
18941
  }
18915
18942
  return days;
18916
18943
  }
18917
- function generateDefaultTimeSlots(events2) {
18944
+ function eventStartDate(event, startField) {
18945
+ const raw = getNestedValue(event, startField);
18946
+ return new Date(raw ?? "");
18947
+ }
18948
+ function generateDefaultTimeSlots(events2, startField) {
18918
18949
  let first = DEFAULT_FIRST_HOUR;
18919
18950
  let last = DEFAULT_LAST_HOUR;
18920
18951
  for (const ev of events2) {
18921
- const start = new Date(ev.startTime);
18952
+ const start = eventStartDate(ev, startField);
18922
18953
  if (Number.isNaN(start.getTime())) continue;
18923
18954
  const hour = start.getHours();
18924
18955
  if (hour < first) first = hour;
@@ -18930,8 +18961,8 @@ function generateDefaultTimeSlots(events2) {
18930
18961
  }
18931
18962
  return slots;
18932
18963
  }
18933
- function eventInSlot(event, day, slotTime) {
18934
- const eventStart = new Date(event.startTime);
18964
+ function eventInSlot(event, day, slotTime, startField) {
18965
+ const eventStart = eventStartDate(event, startField);
18935
18966
  if (Number.isNaN(eventStart.getTime())) return false;
18936
18967
  const [slotHour] = slotTime.split(":").map(Number);
18937
18968
  return eventStart.toDateString() === day.toDateString() && eventStart.getHours() === slotHour;
@@ -18948,7 +18979,12 @@ function CalendarGrid({
18948
18979
  longPressPayload,
18949
18980
  swipeLeftEvent,
18950
18981
  swipeRightEvent,
18951
- dayWindow = "auto"
18982
+ dayWindow = "auto",
18983
+ titleField = "title",
18984
+ startField = "startTime",
18985
+ colorField = "color",
18986
+ children,
18987
+ renderItem
18952
18988
  }) {
18953
18989
  const evs = Array.isArray(events2) ? events2 : events2 ? [events2] : [];
18954
18990
  const eventBus = useEventBus();
@@ -18963,8 +18999,8 @@ function CalendarGrid({
18963
18999
  [resolvedWeekStart]
18964
19000
  );
18965
19001
  const resolvedTimeSlots = useMemo(
18966
- () => timeSlots ?? generateDefaultTimeSlots(evs),
18967
- [timeSlots, evs]
19002
+ () => timeSlots ?? generateDefaultTimeSlots(evs, startField),
19003
+ [timeSlots, evs, startField]
18968
19004
  );
18969
19005
  const visibleCount = useDayWindow(dayWindow);
18970
19006
  const [dayOffset, setDayOffset] = useState(0);
@@ -19001,9 +19037,9 @@ function CalendarGrid({
19001
19037
  );
19002
19038
  const eventsForDayCount = useCallback(
19003
19039
  (day) => evs.filter(
19004
- (ev) => new Date(ev.startTime).toDateString() === day.toDateString()
19040
+ (ev) => eventStartDate(ev, startField).toDateString() === day.toDateString()
19005
19041
  ).length,
19006
- [events2]
19042
+ [events2, startField]
19007
19043
  );
19008
19044
  const swipeCallbacks = useMemo(() => ({
19009
19045
  onSwipeLeft: swipeLeftEvent ? () => eventBus.emit(`UI:${swipeLeftEvent}`, {}) : void 0,
@@ -19022,8 +19058,11 @@ function CalendarGrid({
19022
19058
  eventBus.emit(`UI:${longPressEvent}`, { date: day.toISOString(), time, ...longPressPayload });
19023
19059
  }, 500);
19024
19060
  }, [longPressEvent, longPressPayload, eventBus]);
19061
+ const renderChip = children ?? renderItem;
19025
19062
  const renderEvent = (event) => {
19026
- const color = event.color;
19063
+ const color = getNestedValue(event, colorField);
19064
+ const label = String(getNestedValue(event, titleField) ?? "");
19065
+ const eventIndex = evs.indexOf(event);
19027
19066
  return /* @__PURE__ */ jsx(
19028
19067
  Box,
19029
19068
  {
@@ -19035,7 +19074,7 @@ function CalendarGrid({
19035
19074
  color ? color : "bg-primary/10 border-primary/30 text-primary"
19036
19075
  ),
19037
19076
  onClick: (e) => handleEventClick(event, e),
19038
- children: /* @__PURE__ */ jsx(Typography, { variant: "small", className: "truncate font-medium", children: event.title })
19077
+ children: renderChip ? renderChip(event, eventIndex) : /* @__PURE__ */ jsx(Typography, { variant: "small", className: "truncate font-medium", children: label })
19039
19078
  },
19040
19079
  event.id
19041
19080
  );
@@ -19119,7 +19158,7 @@ function CalendarGrid({
19119
19158
  ) }),
19120
19159
  visibleDays.map((day) => {
19121
19160
  const slotEvents = evs.filter(
19122
- (ev) => eventInSlot(ev, day, time)
19161
+ (ev) => eventInSlot(ev, day, time, startField)
19123
19162
  );
19124
19163
  const isToday = day.toDateString() === (/* @__PURE__ */ new Date()).toDateString();
19125
19164
  return /* @__PURE__ */ jsx(
@@ -19156,6 +19195,7 @@ var init_CalendarGrid = __esm({
19156
19195
  "components/core/molecules/CalendarGrid.tsx"() {
19157
19196
  "use client";
19158
19197
  init_cn();
19198
+ init_getNestedValue();
19159
19199
  init_Box();
19160
19200
  init_Button();
19161
19201
  init_Stack();
@@ -19172,32 +19212,6 @@ var init_CalendarGrid = __esm({
19172
19212
  CalendarGrid.displayName = "CalendarGrid";
19173
19213
  }
19174
19214
  });
19175
-
19176
- // lib/getNestedValue.ts
19177
- function getNestedValue(obj, path) {
19178
- if (obj === null || obj === void 0 || !path) {
19179
- return void 0;
19180
- }
19181
- if (!path.includes(".")) {
19182
- return obj[path];
19183
- }
19184
- const parts = path.split(".");
19185
- let value = obj;
19186
- for (const part of parts) {
19187
- if (value === null || value === void 0) {
19188
- return void 0;
19189
- }
19190
- if (typeof value !== "object" || Array.isArray(value)) {
19191
- return void 0;
19192
- }
19193
- value = value[part];
19194
- }
19195
- return value;
19196
- }
19197
- var init_getNestedValue = __esm({
19198
- "lib/getNestedValue.ts"() {
19199
- }
19200
- });
19201
19215
  var Pagination;
19202
19216
  var init_Pagination = __esm({
19203
19217
  "components/core/molecules/Pagination.tsx"() {
@@ -21980,7 +21994,7 @@ var init_DashboardLayout = __esm({
21980
21994
  ]
21981
21995
  }
21982
21996
  ),
21983
- user && /* @__PURE__ */ jsxs(Box, { className: "relative", children: [
21997
+ user?.name && /* @__PURE__ */ jsxs(Box, { className: "relative", children: [
21984
21998
  /* @__PURE__ */ jsxs(
21985
21999
  Button,
21986
22000
  {
@@ -45066,6 +45080,96 @@ function VerificationProvider({
45066
45080
  return /* @__PURE__ */ jsx(Fragment, { children });
45067
45081
  }
45068
45082
  VerificationProvider.displayName = "VerificationProvider";
45083
+ var UserContext = createContext(null);
45084
+ function UserProvider({
45085
+ user = null,
45086
+ children
45087
+ }) {
45088
+ const hasRole = useCallback(
45089
+ (role) => {
45090
+ if (!user) return role === "anonymous";
45091
+ return user.role === role;
45092
+ },
45093
+ [user]
45094
+ );
45095
+ const hasPermission = useCallback(
45096
+ (permission) => {
45097
+ if (!user) return false;
45098
+ return user.permissions?.includes(permission) ?? false;
45099
+ },
45100
+ [user]
45101
+ );
45102
+ const hasAnyRole = useCallback(
45103
+ (roles) => {
45104
+ if (!user) return roles.includes("anonymous");
45105
+ return user.role ? roles.includes(user.role) : false;
45106
+ },
45107
+ [user]
45108
+ );
45109
+ const hasAllPermissions = useCallback(
45110
+ (permissions) => {
45111
+ if (!user || !user.permissions) return false;
45112
+ return permissions.every((p) => user.permissions?.includes(p));
45113
+ },
45114
+ [user]
45115
+ );
45116
+ const getUserField = useCallback(
45117
+ (path) => {
45118
+ const viewer = user ?? ANONYMOUS_USER;
45119
+ const [first, ...rest] = path.split(".");
45120
+ if (!first) return void 0;
45121
+ let value = viewer[first];
45122
+ for (const segment of rest) {
45123
+ if (value === null || typeof value !== "object" || Array.isArray(value) || value instanceof Date) {
45124
+ return void 0;
45125
+ }
45126
+ value = value[segment];
45127
+ }
45128
+ return value;
45129
+ },
45130
+ [user]
45131
+ );
45132
+ const contextValue = useMemo(
45133
+ () => ({
45134
+ user,
45135
+ isLoggedIn: user !== null,
45136
+ hasRole,
45137
+ hasPermission,
45138
+ hasAnyRole,
45139
+ hasAllPermissions,
45140
+ getUserField
45141
+ }),
45142
+ [user, hasRole, hasPermission, hasAnyRole, hasAllPermissions, getUserField]
45143
+ );
45144
+ return /* @__PURE__ */ jsx(UserContext.Provider, { value: contextValue, children });
45145
+ }
45146
+ function useUser() {
45147
+ const context = useContext(UserContext);
45148
+ if (!context) {
45149
+ return {
45150
+ user: null,
45151
+ isLoggedIn: false,
45152
+ hasRole: (role) => role === "anonymous",
45153
+ hasPermission: () => false,
45154
+ hasAnyRole: (roles) => roles.includes("anonymous"),
45155
+ hasAllPermissions: () => false,
45156
+ getUserField: () => void 0
45157
+ };
45158
+ }
45159
+ return context;
45160
+ }
45161
+ function useHasRole(role) {
45162
+ const { hasRole } = useUser();
45163
+ return hasRole(role);
45164
+ }
45165
+ function useHasPermission(permission) {
45166
+ const { hasPermission } = useUser();
45167
+ return hasPermission(permission);
45168
+ }
45169
+ function useUserForEvaluation() {
45170
+ const { user, isLoggedIn } = useUser();
45171
+ return isLoggedIn && user ? user : void 0;
45172
+ }
45069
45173
  function OrbitalProvider({
45070
45174
  children,
45071
45175
  themes,
@@ -45077,13 +45181,14 @@ function OrbitalProvider({
45077
45181
  initialData,
45078
45182
  suspense = false,
45079
45183
  verification,
45080
- isolated = false
45184
+ isolated = false,
45185
+ user = null
45081
45186
  }) {
45082
45187
  const suspenseConfig = useMemo(
45083
45188
  () => ({ enabled: suspense }),
45084
45189
  [suspense]
45085
45190
  );
45086
- const inner = /* @__PURE__ */ jsx(EventBusProvider, { debug: debug2, isolated, children: /* @__PURE__ */ jsx(VerificationProvider, { enabled: verification, children: /* @__PURE__ */ jsx(SelectionProvider, { debug: debug2, children: /* @__PURE__ */ jsx(SuspenseConfigProvider, { config: suspenseConfig, children }) }) }) });
45191
+ const inner = /* @__PURE__ */ jsx(EventBusProvider, { debug: debug2, isolated, children: /* @__PURE__ */ jsx(VerificationProvider, { enabled: verification, children: /* @__PURE__ */ jsx(UserProvider, { user, children: /* @__PURE__ */ jsx(SelectionProvider, { debug: debug2, children: /* @__PURE__ */ jsx(SuspenseConfigProvider, { config: suspenseConfig, children }) }) }) }) });
45087
45192
  if (skipTheme) {
45088
45193
  return inner;
45089
45194
  }
@@ -45339,104 +45444,6 @@ var CurrentPagePathProvider = ({
45339
45444
  }) => /* @__PURE__ */ jsx(CurrentPagePathContext.Provider, { value, children });
45340
45445
  CurrentPagePathProvider.displayName = "CurrentPagePathProvider";
45341
45446
  var useCurrentPagePath2 = () => useContext(CurrentPagePathContext);
45342
- var ANONYMOUS_USER = {
45343
- id: "anonymous",
45344
- role: "anonymous",
45345
- permissions: []
45346
- };
45347
- var UserContext = createContext(null);
45348
- function UserProvider({
45349
- user = null,
45350
- children
45351
- }) {
45352
- const hasRole = useCallback(
45353
- (role) => {
45354
- if (!user) return role === "anonymous";
45355
- return user.role === role;
45356
- },
45357
- [user]
45358
- );
45359
- const hasPermission = useCallback(
45360
- (permission) => {
45361
- if (!user) return false;
45362
- return user.permissions?.includes(permission) ?? false;
45363
- },
45364
- [user]
45365
- );
45366
- const hasAnyRole = useCallback(
45367
- (roles) => {
45368
- if (!user) return roles.includes("anonymous");
45369
- return user.role ? roles.includes(user.role) : false;
45370
- },
45371
- [user]
45372
- );
45373
- const hasAllPermissions = useCallback(
45374
- (permissions) => {
45375
- if (!user || !user.permissions) return false;
45376
- return permissions.every((p) => user.permissions?.includes(p));
45377
- },
45378
- [user]
45379
- );
45380
- const getUserField = useCallback(
45381
- (path) => {
45382
- const userData = user ?? ANONYMOUS_USER;
45383
- const parts = path.split(".");
45384
- let value = userData;
45385
- for (const segment of parts) {
45386
- if (value === null || value === void 0) {
45387
- return void 0;
45388
- }
45389
- if (typeof value === "object") {
45390
- value = value[segment];
45391
- } else {
45392
- return void 0;
45393
- }
45394
- }
45395
- return value;
45396
- },
45397
- [user]
45398
- );
45399
- const contextValue = useMemo(
45400
- () => ({
45401
- user,
45402
- isLoggedIn: user !== null,
45403
- hasRole,
45404
- hasPermission,
45405
- hasAnyRole,
45406
- hasAllPermissions,
45407
- getUserField
45408
- }),
45409
- [user, hasRole, hasPermission, hasAnyRole, hasAllPermissions, getUserField]
45410
- );
45411
- return /* @__PURE__ */ jsx(UserContext.Provider, { value: contextValue, children });
45412
- }
45413
- function useUser() {
45414
- const context = useContext(UserContext);
45415
- if (!context) {
45416
- return {
45417
- user: null,
45418
- isLoggedIn: false,
45419
- hasRole: (role) => role === "anonymous",
45420
- hasPermission: () => false,
45421
- hasAnyRole: (roles) => roles.includes("anonymous"),
45422
- hasAllPermissions: () => false,
45423
- getUserField: () => void 0
45424
- };
45425
- }
45426
- return context;
45427
- }
45428
- function useHasRole(role) {
45429
- const { hasRole } = useUser();
45430
- return hasRole(role);
45431
- }
45432
- function useHasPermission(permission) {
45433
- const { hasPermission } = useUser();
45434
- return hasPermission(permission);
45435
- }
45436
- function useUserForEvaluation() {
45437
- const { user, isLoggedIn } = useUser();
45438
- return isLoggedIn && user ? user : void 0;
45439
- }
45440
45447
  var EntitySchemaContext = createContext(null);
45441
45448
  function EntitySchemaProvider({
45442
45449
  entities,
@@ -46152,4 +46159,4 @@ function GameAudioProvider2({
46152
46159
  }
46153
46160
  GameAudioProvider2.displayName = "GameAudioProvider";
46154
46161
 
46155
- export { ANONYMOUS_USER, CurrentPagePathContext, CurrentPagePathProvider, EntitySchemaProvider, EventBusContext2 as EventBusContext, EventBusProvider, GameAudioContext2 as GameAudioContext, GameAudioProvider2 as GameAudioProvider, NavigationProvider2 as NavigationProvider, OfflineModeProvider, OrbitalProvider, OrbitalThemeProvider, SelectionContext, SelectionProvider, ServerBridgeProvider, TraitContext, TraitProvider, TraitScopeProvider3 as TraitScopeProvider, UserContext, UserProvider, VerificationProvider, comparePathSpecificity2 as comparePathSpecificity, extractRouteParams2 as extractRouteParams, findPageByName2 as findPageByName, findPageByPath2 as findPageByPath, getAllPages2 as getAllPages, getDefaultPage2 as getDefaultPage, matchPath2 as matchPath, matchPathAmong2 as matchPathAmong, pathMatches2 as pathMatches, useActivePage2 as useActivePage, useCurrentPagePath2 as useCurrentPagePath, useEntitySchema, useEntitySchemaOptional6 as useEntitySchemaOptional, useGameAudioContext2 as useGameAudioContext, useGameAudioContextOptional2 as useGameAudioContextOptional, useHasPermission, useHasRole, useInitPayload2 as useInitPayload, useNavigateTo2 as useNavigateTo, useNavigation2 as useNavigation, useNavigationId2 as useNavigationId, useNavigationState2 as useNavigationState, useOfflineMode, useOptionalOfflineMode, useSelection, useSelectionOptional, useServerBridge, useTrait, useTraitContext, useTraitScope, useTraitScopeChain2 as useTraitScopeChain, useUser, useUserForEvaluation };
46162
+ export { CurrentPagePathContext, CurrentPagePathProvider, EntitySchemaProvider, EventBusContext2 as EventBusContext, EventBusProvider, GameAudioContext2 as GameAudioContext, GameAudioProvider2 as GameAudioProvider, NavigationProvider2 as NavigationProvider, OfflineModeProvider, OrbitalProvider, OrbitalThemeProvider, SelectionContext, SelectionProvider, ServerBridgeProvider, TraitContext, TraitProvider, TraitScopeProvider3 as TraitScopeProvider, UserContext, UserProvider, VerificationProvider, comparePathSpecificity2 as comparePathSpecificity, extractRouteParams2 as extractRouteParams, findPageByName2 as findPageByName, findPageByPath2 as findPageByPath, getAllPages2 as getAllPages, getDefaultPage2 as getDefaultPage, matchPath2 as matchPath, matchPathAmong2 as matchPathAmong, pathMatches2 as pathMatches, useActivePage2 as useActivePage, useCurrentPagePath2 as useCurrentPagePath, useEntitySchema, useEntitySchemaOptional6 as useEntitySchemaOptional, useGameAudioContext2 as useGameAudioContext, useGameAudioContextOptional2 as useGameAudioContextOptional, useHasPermission, useHasRole, useInitPayload2 as useInitPayload, useNavigateTo2 as useNavigateTo, useNavigation2 as useNavigation, useNavigationId2 as useNavigationId, useNavigationState2 as useNavigationState, useOfflineMode, useOptionalOfflineMode, useSelection, useSelectionOptional, useServerBridge, useTrait, useTraitContext, useTraitScope, useTraitScopeChain2 as useTraitScopeChain, useUser, useUserForEvaluation };