@copilotz/chat-ui 0.1.26 → 0.1.28

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.cjs CHANGED
@@ -2784,11 +2784,12 @@ var ChatUserContextProvider = ({ children, initial }) => {
2784
2784
  }));
2785
2785
  (0, import_react4.useEffect)(() => {
2786
2786
  if (!initial) return;
2787
- setCtx((prev) => ({
2788
- ...prev,
2789
- ...initial,
2790
- updatedAt: Date.now()
2791
- }));
2787
+ setCtx((prev) => {
2788
+ const keys = Object.keys(initial);
2789
+ const hasChanges = keys.some((k) => prev[k] !== initial[k]);
2790
+ if (!hasChanges) return prev;
2791
+ return { ...prev, ...initial, updatedAt: Date.now() };
2792
+ });
2792
2793
  }, [initial]);
2793
2794
  const setPartial = (0, import_react4.useCallback)((next) => {
2794
2795
  setCtx((prev) => {
@@ -4112,6 +4113,25 @@ var ChatUI = ({
4112
4113
  const closeSidebar = (0, import_react7.useCallback)(() => {
4113
4114
  setState((prev) => ({ ...prev, showSidebar: false }));
4114
4115
  }, []);
4116
+ const handleCustomComponentToggle = (0, import_react7.useCallback)(() => {
4117
+ setState((prev) => ({ ...prev, showSidebar: !prev.showSidebar }));
4118
+ }, []);
4119
+ const sidebarUser = (0, import_react7.useMemo)(() => user ? {
4120
+ id: user.id,
4121
+ name: user.name,
4122
+ email: user.email,
4123
+ avatar: user.avatar
4124
+ } : null, [user?.id, user?.name, user?.email, user?.avatar]);
4125
+ const handleViewProfile = (0, import_react7.useCallback)(() => {
4126
+ setIsUserProfileOpen(true);
4127
+ callbacks.onViewProfile?.();
4128
+ }, [callbacks.onViewProfile]);
4129
+ const sidebarUserMenuCallbacks = (0, import_react7.useMemo)(() => ({
4130
+ onViewProfile: handleViewProfile,
4131
+ onOpenSettings: callbacks.onOpenSettings,
4132
+ onThemeChange: callbacks.onThemeChange,
4133
+ onLogout: callbacks.onLogout
4134
+ }), [handleViewProfile, callbacks.onOpenSettings, callbacks.onThemeChange, callbacks.onLogout]);
4115
4135
  const renderCustomComponent = (0, import_react7.useCallback)(() => {
4116
4136
  const component = config?.customComponent?.component;
4117
4137
  if (!component) return null;
@@ -4247,21 +4267,8 @@ var ChatUI = ({
4247
4267
  onRenameThread: handleRenameThread,
4248
4268
  onDeleteThread: handleDeleteThread,
4249
4269
  onArchiveThread: handleArchiveThread,
4250
- user: user ? {
4251
- id: user.id,
4252
- name: user.name,
4253
- email: user.email,
4254
- avatar: user.avatar
4255
- } : null,
4256
- userMenuCallbacks: {
4257
- onViewProfile: () => {
4258
- setIsUserProfileOpen(true);
4259
- callbacks.onViewProfile?.();
4260
- },
4261
- onOpenSettings: callbacks.onOpenSettings,
4262
- onThemeChange: callbacks.onThemeChange,
4263
- onLogout: callbacks.onLogout
4264
- },
4270
+ user: sidebarUser,
4271
+ userMenuCallbacks: sidebarUserMenuCallbacks,
4265
4272
  currentTheme: config.ui.theme === "auto" ? "system" : config.ui.theme,
4266
4273
  showThemeOptions: !!callbacks.onThemeChange
4267
4274
  }
@@ -4273,7 +4280,7 @@ var ChatUI = ({
4273
4280
  config,
4274
4281
  currentThreadTitle: threads.find((t) => t.id === state.selectedThreadId)?.title,
4275
4282
  isMobile,
4276
- onCustomComponentToggle: () => setState((prev) => ({ ...prev, showSidebar: !prev.showSidebar })),
4283
+ onCustomComponentToggle: handleCustomComponentToggle,
4277
4284
  onNewThread: handleCreateThread,
4278
4285
  showCustomComponentButton: !!config?.customComponent?.component,
4279
4286
  showAgentSelector: shouldShowAgentSelector,