@kne/system-layout 0.2.0-alpha.16 → 0.2.0-alpha.20

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,4 +1,5 @@
1
- import { isValidElement, useRef, useState, useLayoutEffect, useEffect, useContext as useContext$1, createContext, useMemo } from 'react';
1
+ import { useRef, useState, useCallback, useMemo, useLayoutEffect, isValidElement, useContext as useContext$1, createContext, useEffect } from 'react';
2
+ import { createPortal } from 'react-dom';
2
3
  import { Flex, Alert, Button, Row, Col, Skeleton } from 'antd';
3
4
  import classnames from 'classnames';
4
5
  import localStorage from '@kne/local-storage';
@@ -8,13 +9,14 @@ import { useLocation, useNavigate } from 'react-router-dom';
8
9
  import Icon from '@kne/react-icon';
9
10
  import ensureSlash from '@kne/ensure-slash';
10
11
  import isPlainObject from 'lodash/isPlainObject';
11
- import { createPortal } from 'react-dom';
12
+ import VirtualList from 'rc-virtual-list';
13
+ import { useScrollElement, usePopupContainer, useResponsiveContext, useIsMobile, RESPONSIVE_BOUNDARY_CLASS, RESPONSIVE_CONTAINER_CLASS, RESPONSIVE_SCROLL_CLASS, findResponsiveScroll, getDefaultScrollElement, ResponsiveProvider, defaultResponsiveContextValue, IS_MOBILE_QUERY } from '@kne/responsive-utils';
14
+ export { MOBILE_BREAKPOINT, RESPONSIVE_BOUNDARY_CLASS, RESPONSIVE_CONTAINER_CLASS, RESPONSIVE_SCROLL_CLASS, ResponsiveProvider, MOBILE_BREAKPOINT as mobileBreakpoint, useBreakpoint, useIsMobile, useMediaQuery, usePopupContainer, useResponsiveContext, useScrollElement } from '@kne/responsive-utils';
12
15
  import defaultLogo from './defaultLogo~beHinxEU.svg';
13
16
  import { ReactComponent } from './expand~bdCTnjYJ.svg';
14
17
  import ReactErrorBoundary from '@kne/react-error-boundary';
15
18
  import { createWithIntlProvider, useIntl } from '@kne/react-intl';
16
19
  import SimpleBar from 'simplebar-react';
17
- import throttle from 'lodash/throttle';
18
20
  import 'simplebar-react/dist/simplebar.min.css';
19
21
  import ButtonGroup from '@kne/button-group';
20
22
  import merge from 'lodash/merge';
@@ -30,7 +32,7 @@ function _extends() {
30
32
  }, _extends.apply(null, arguments);
31
33
  }
32
34
 
33
- var style$3 = {"layout":"kne-system-layout_sK89O","has-toolbar":"kne-system-layout_gyKfI","has-navbar":"kne-system-layout_X1wZG","menu":"kne-system-layout_-LpWn","open":"kne-system-layout_G-zuN","layer-menu":"kne-system-layout_6TCwG","ai-entry":"kne-system-layout_5qnw5","page":"kne-system-layout_HnwkM","toolbar":"kne-system-layout_h8PAW","page-children":"kne-system-layout_OM1Q2","is-mobile":"kne-system-layout_udBgQ","menu-inner":"kne-system-layout_7wq3X","logo":"kne-system-layout_-T-Dc","menu-header":"kne-system-layout_LOrmu","logo-img":"kne-system-layout_2cRWf","expand-btn-wrapper":"kne-system-layout_5D-Oq","expand-btn-bg":"kne-system-layout_p4eOE","expand-btn":"kne-system-layout_8dzE7","username":"kne-system-layout_b7XeQ","user-description":"kne-system-layout_U0YTk","menu-list":"kne-system-layout_8gqbZ","ai-dialog-window":"kne-system-layout_UAJc-","pulse-dialog-window":"kne-system-layout_VjIWn","page-dialog-outer":"kne-system-layout_I7Anv","page-dialog":"kne-system-layout_UhsFd","pulse-page-dialog":"kne-system-layout_H7slV","page-window-content":"kne-system-layout_2mdNn","is-scroller":"kne-system-layout_6gjkS","page-content":"kne-system-layout_nyAa2","ai-dialog-window-title":"kne-system-layout_33Tja","ai-dialog-window-content":"kne-system-layout_YmBhl"};
35
+ var style$3 = {"kne-responsive-boundary":"kne-system-layout_VtEb1","kne-responsive-scroll":"kne-system-layout_UMzfg","layout":"kne-system-layout_sK89O","has-toolbar":"kne-system-layout_gyKfI","has-navbar":"kne-system-layout_X1wZG","menu":"kne-system-layout_-LpWn","open":"kne-system-layout_G-zuN","layer-menu":"kne-system-layout_6TCwG","ai-entry":"kne-system-layout_5qnw5","page":"kne-system-layout_HnwkM","page-content":"kne-system-layout_nyAa2","toolbar":"kne-system-layout_h8PAW","page-children":"kne-system-layout_OM1Q2","is-scroller":"kne-system-layout_6gjkS","is-mobile":"kne-system-layout_udBgQ","logo":"kne-system-layout_-T-Dc","menu-header":"kne-system-layout_LOrmu","menu-boundary-overlay":"kne-system-layout_-cMpV","is-portaled":"kne-system-layout_leFsD","logo-img":"kne-system-layout_2cRWf","expand-btn-wrapper":"kne-system-layout_5D-Oq","expand-btn-bg":"kne-system-layout_p4eOE","expand-btn":"kne-system-layout_8dzE7","menu-inner":"kne-system-layout_7wq3X","menu-list":"kne-system-layout_8gqbZ","username":"kne-system-layout_b7XeQ","user-description":"kne-system-layout_U0YTk","ai-dialog-window":"kne-system-layout_UAJc-","pulse-dialog-window":"kne-system-layout_VjIWn","page-dialog-outer":"kne-system-layout_I7Anv","page-dialog":"kne-system-layout_UhsFd","pulse-page-dialog":"kne-system-layout_H7slV","page-window-content":"kne-system-layout_2mdNn","ai-dialog-window-title":"kne-system-layout_33Tja","ai-dialog-window-content":"kne-system-layout_YmBhl"};
34
36
 
35
37
  const UserCard = ({
36
38
  name,
@@ -72,8 +74,12 @@ const UserCard = ({
72
74
  });
73
75
  };
74
76
 
75
- var style$2 = {"menu-group":"kne-system-layout_Rfzv4","menu-item-icon":"kne-system-layout_qoDtD","menu-group-split":"kne-system-layout_socoO","menu-item":"kne-system-layout_Xa-2h"};
77
+ var style$2 = {"menu-list":"kne-system-layout_dVWvr","menu-group":"kne-system-layout_Rfzv4","menu-item-icon":"kne-system-layout_qoDtD","menu-group-split":"kne-system-layout_socoO","menu-item":"kne-system-layout_Xa-2h"};
76
78
 
79
+ const MENU_ITEM_HEIGHT = 52;
80
+ const MENU_GROUP_HEIGHT = 48;
81
+ const MENU_GROUP_SPLIT_HEIGHT = 17;
82
+ const getItemKey = (item, index) => item.key || item.path || index;
77
83
  const Menu = ({
78
84
  className,
79
85
  menuOpen,
@@ -84,94 +90,174 @@ const Menu = ({
84
90
  }) => {
85
91
  const location = useLocation();
86
92
  const navigate = useNavigate();
93
+ const listRef = useRef(null);
94
+ const virtualListRef = useRef(null);
95
+ const [listHeight, setListHeight] = useState(0);
87
96
  const currentPathname = _base ? location.pathname.replace(new RegExp(`^${_base}`), '') : location.pathname;
88
- return /*#__PURE__*/jsx("div", {
89
- className: classnames('menu', className, style$2['menu-list']),
90
- children: items.map((item, index) => {
91
- var _items;
92
- const active = (() => {
93
- if (typeof activeKey === 'string') {
94
- return activeKey === item.key;
97
+ const isItemActive = useCallback(item => {
98
+ if (typeof activeKey === 'string') {
99
+ return activeKey === item.key;
100
+ }
101
+ if (typeof activeKey === 'function') {
102
+ return activeKey(item, {
103
+ menuOpen,
104
+ base: _base
105
+ });
106
+ }
107
+ if (typeof item.path === 'string') {
108
+ return ensureSlash(currentPathname) === ensureSlash(item.path);
109
+ }
110
+ return false;
111
+ }, [activeKey, _base, currentPathname, menuOpen]);
112
+ const getEstimatedItemHeight = useCallback((item, index) => {
113
+ var _items;
114
+ const hasGroup = item.group && item.group !== ((_items = items[index - 1]) == null ? void 0 : _items.group);
115
+ if (!hasGroup) {
116
+ return MENU_ITEM_HEIGHT;
117
+ }
118
+ return MENU_ITEM_HEIGHT + (menuOpen ? MENU_GROUP_HEIGHT : MENU_GROUP_SPLIT_HEIGHT);
119
+ }, [items, menuOpen]);
120
+ const estimatedItemHeight = useMemo(() => {
121
+ if (!items.length) {
122
+ return MENU_ITEM_HEIGHT;
123
+ }
124
+ const total = items.reduce((sum, item, index) => sum + getEstimatedItemHeight(item, index), 0);
125
+ return Math.max(MENU_ITEM_HEIGHT, Math.ceil(total / items.length));
126
+ }, [getEstimatedItemHeight, items]);
127
+ const listData = useMemo(() => items.map((item, index) => ({
128
+ item,
129
+ index,
130
+ key: getItemKey(item, index)
131
+ })), [items]);
132
+ const activeIndex = useMemo(() => listData.findIndex(({
133
+ item
134
+ }) => isItemActive(item)), [isItemActive, listData]);
135
+ useLayoutEffect(() => {
136
+ const el = listRef.current;
137
+ if (!el) {
138
+ return;
139
+ }
140
+ const updateHeight = () => {
141
+ const styles = getComputedStyle(el);
142
+ const paddingY = parseFloat(styles.paddingTop) + parseFloat(styles.paddingBottom);
143
+ setListHeight(el.clientHeight - paddingY);
144
+ };
145
+ updateHeight();
146
+ const observer = new ResizeObserver(updateHeight);
147
+ observer.observe(el);
148
+ return () => observer.disconnect();
149
+ }, []);
150
+ useLayoutEffect(() => {
151
+ var _virtualListRef$curre;
152
+ if (activeIndex < 0 || listHeight <= 0) {
153
+ return;
154
+ }
155
+ (_virtualListRef$curre = virtualListRef.current) == null || _virtualListRef$curre.scrollTo({
156
+ index: activeIndex,
157
+ align: 'auto'
158
+ });
159
+ }, [activeIndex, listHeight, menuOpen, listData.length]);
160
+ const renderMenuItem = (item, index) => {
161
+ var _items2;
162
+ const active = isItemActive(item);
163
+ const icon = typeof item.icon === 'function' ? item.icon({
164
+ menuOpen,
165
+ active
166
+ }) : item.icon;
167
+ const hasGroup = item.group && item.group !== ((_items2 = items[index - 1]) == null ? void 0 : _items2.group);
168
+ return /*#__PURE__*/jsxs("div", {
169
+ title: item.label,
170
+ onClick: e => {
171
+ if (active) {
172
+ return;
95
173
  }
96
- if (typeof activeKey === 'function') {
97
- return activeKey(item, {
174
+ onChange && onChange(item, {
175
+ menuOpen,
176
+ base: _base
177
+ });
178
+ if (typeof item.onClick === 'function') {
179
+ item.onClick(item, {
98
180
  menuOpen,
99
- base: _base
181
+ base: _base,
182
+ event: e
100
183
  });
184
+ return;
101
185
  }
102
- if (typeof item.path === 'string') {
103
- return ensureSlash(currentPathname) === ensureSlash(item.path);
186
+ if (item.path) {
187
+ navigate(ensureSlash(`${_base}${item.path}`));
104
188
  }
105
- return false;
106
- })();
107
- const icon = typeof item.icon === 'function' ? item.icon({
108
- menuOpen,
109
- active
110
- }) : item.icon;
111
- const hasGroup = item.group && item.group !== ((_items = items[index - 1]) == null ? void 0 : _items.group);
112
- return /*#__PURE__*/jsxs("div", {
113
- title: item.label,
114
- onClick: e => {
115
- if (active) {
116
- return;
189
+ },
190
+ children: [hasGroup && menuOpen ? /*#__PURE__*/jsx("div", {
191
+ className: classnames('menu-group', style$2['menu-group']),
192
+ children: item.groupLabel || item.group
193
+ }) : null, hasGroup && !menuOpen ? /*#__PURE__*/jsx("div", {
194
+ className: classnames('menu-group-split', style$2['menu-group-split'])
195
+ }) : null, /*#__PURE__*/jsxs(Flex, {
196
+ className: classnames('menu-item', style$2['menu-item'], {
197
+ ['is-active']: active,
198
+ ['is-closed']: !menuOpen
199
+ }),
200
+ align: "center",
201
+ gap: 8,
202
+ children: [(icon => {
203
+ if (typeof icon === 'string') {
204
+ return /*#__PURE__*/jsx(Icon, {
205
+ className: classnames('menu-item-icon', style$2['menu-item-icon']),
206
+ type: icon,
207
+ fontClassName: "system"
208
+ });
117
209
  }
118
- onChange && onChange(item, {
119
- menuOpen,
120
- base: _base
121
- });
122
- if (typeof item.onClick === 'function') {
123
- item.onClick(item, {
124
- menuOpen,
125
- base: _base,
126
- event: e
210
+ if (/*#__PURE__*/isValidElement(icon)) {
211
+ return /*#__PURE__*/jsx("span", {
212
+ className: classnames('menu-item-icon', style$2['menu-item-icon']),
213
+ children: icon
127
214
  });
128
- return;
129
215
  }
130
- if (item.path) {
131
- navigate(ensureSlash(`${_base}${item.path}`));
216
+ if (isPlainObject(icon) && typeof icon.type === 'string') {
217
+ return /*#__PURE__*/jsx(Icon, _extends({}, icon, {
218
+ className: classnames('menu-item-icon', style$2['menu-item-icon'])
219
+ }));
132
220
  }
133
- },
134
- children: [hasGroup && menuOpen ? /*#__PURE__*/jsx("div", {
135
- className: classnames('menu-group', style$2['menu-group']),
136
- children: item.groupLabel || item.group
137
- }) : null, hasGroup && !menuOpen ? /*#__PURE__*/jsx("div", {
138
- className: classnames('menu-group-split', style$2['menu-group-split'])
139
- }) : null, /*#__PURE__*/jsxs(Flex, {
140
- className: classnames('menu-item', style$2['menu-item'], {
141
- ['is-active']: active,
142
- ['is-closed']: !menuOpen
143
- }),
144
- align: "center",
145
- gap: 8,
146
- children: [(icon => {
147
- if (typeof icon === 'string') {
148
- return /*#__PURE__*/jsx(Icon, {
149
- className: classnames('menu-item-icon', style$2['menu-item-icon']),
150
- type: icon,
151
- fontClassName: "system"
152
- });
153
- }
154
- if (/*#__PURE__*/isValidElement(icon)) {
155
- return /*#__PURE__*/jsx("span", {
156
- className: classnames('menu-item-icon', style$2['menu-item-icon']),
157
- children: icon
158
- });
159
- }
160
- if (isPlainObject(icon) && typeof icon.type === 'string') {
161
- return /*#__PURE__*/jsx(Icon, _extends({}, icon, {
162
- className: classnames('menu-item-icon', style$2['menu-item-icon'])
163
- }));
164
- }
165
- return null;
166
- })(icon), menuOpen && item.label]
167
- })]
168
- }, item.key || item.path || index);
169
- })
221
+ return null;
222
+ })(icon), menuOpen && item.label]
223
+ })]
224
+ }, getItemKey(item, index));
225
+ };
226
+ return /*#__PURE__*/jsx("div", {
227
+ ref: listRef,
228
+ className: classnames('menu', className, style$2['menu-list']),
229
+ children: listHeight > 0 ? /*#__PURE__*/jsx(VirtualList, {
230
+ ref: virtualListRef,
231
+ data: listData,
232
+ height: listHeight,
233
+ itemHeight: estimatedItemHeight,
234
+ itemKey: "key",
235
+ virtual: listData.length > 0,
236
+ children: ({
237
+ item,
238
+ index
239
+ }) => renderMenuItem(item, index)
240
+ }) : null
170
241
  });
171
242
  };
172
243
 
173
- var style$1 = {"toolbar":"kne-system-layout_SLK-0","toolbar-list":"kne-system-layout_GTQvM","toolbar-item":"kne-system-layout_fAZ3n","toolbar-item-icon":"kne-system-layout_qOB9o","is-hidden":"kne-system-layout_ss5zk","toolbar-item-label":"kne-system-layout_h48es","toolbar-indicator":"kne-system-layout_1s-bc","toolbar-click":"kne-system-layout_Ys3yu"};
244
+ var style$1 = {"toolbar":"kne-system-layout_SLK-0","toolbar-inline":"kne-system-layout_RgKpk","toolbar-boundary-overlay":"kne-system-layout_VEMgn","toolbar-list":"kne-system-layout_GTQvM","is-viewport":"kne-system-layout_c6f0m","is-boundary":"kne-system-layout_3ctCY","toolbar-item":"kne-system-layout_fAZ3n","toolbar-item-icon":"kne-system-layout_qOB9o","is-hidden":"kne-system-layout_ss5zk","toolbar-item-label":"kne-system-layout_h48es","toolbar-indicator":"kne-system-layout_1s-bc","toolbar-click":"kne-system-layout_Ys3yu"};
245
+
246
+ const context = /*#__PURE__*/createContext({});
247
+ const useContext = () => {
248
+ return useContext$1(context);
249
+ };
250
+ const {
251
+ Provider,
252
+ Consumer
253
+ } = context;
174
254
 
255
+ const resolveTarget = target => {
256
+ if (!target) {
257
+ return null;
258
+ }
259
+ return typeof target === 'function' ? target() : target;
260
+ };
175
261
  const Toolbar = ({
176
262
  show: _show = true,
177
263
  className,
@@ -183,6 +269,15 @@ const Toolbar = ({
183
269
  }) => {
184
270
  const location = useLocation();
185
271
  const navigate = useNavigate();
272
+ const getScrollElement = useScrollElement();
273
+ const getBoundaryElement = usePopupContainer();
274
+ const {
275
+ mode
276
+ } = useResponsiveContext();
277
+ const isMobile = useIsMobile();
278
+ const {
279
+ scrollReady
280
+ } = useContext();
186
281
  const currentPathname = _base ? location.pathname.replace(new RegExp(`^${_base}`), '') : location.pathname;
187
282
  const toolbarMenu = items.filter(item => item.toolbar);
188
283
  const itemRefs = useRef([]);
@@ -212,6 +307,10 @@ const Toolbar = ({
212
307
  });
213
308
  const displayIndex = activeIndex >= 0 ? activeIndex : 0;
214
309
  const listRef = useRef(null);
310
+ const explicitTarget = resolveTarget(target);
311
+ const useBoundaryMount = isMobile && mode === 'container' && !explicitTarget;
312
+ const useViewportFixed = isMobile && mode !== 'container' && !explicitTarget;
313
+ const boundaryTarget = useBoundaryMount ? getBoundaryElement() : null;
215
314
  useLayoutEffect(() => {
216
315
  if (activeIndex < 0) {
217
316
  return;
@@ -235,21 +334,15 @@ const Toolbar = ({
235
334
  });
236
335
  return;
237
336
  }
238
-
239
- // Phase 1: scale up
240
337
  setIndicator(prev => _extends({}, prev, {
241
338
  scale: 1.15
242
339
  }));
243
-
244
- // Phase 2: move
245
340
  const t1 = setTimeout(() => {
246
341
  setIndicator(prev => _extends({}, prev, {
247
342
  left: newLeft,
248
343
  width: newWidth
249
344
  }));
250
345
  }, 120);
251
-
252
- // Phase 3: scale down
253
346
  const t2 = setTimeout(() => {
254
347
  setIndicator(prev => _extends({}, prev, {
255
348
  scale: 1
@@ -259,10 +352,10 @@ const Toolbar = ({
259
352
  clearTimeout(t1);
260
353
  clearTimeout(t2);
261
354
  };
262
- }, [activeIndex, _show, target]);
263
- const resolvedTarget = target ? typeof target === 'function' ? target() : target : null;
355
+ }, [activeIndex, _show, target, useBoundaryMount, useViewportFixed]);
264
356
  useEffect(() => {
265
- if (!resolvedTarget) {
357
+ const scrollEl = getScrollElement();
358
+ if (!scrollEl || typeof scrollEl.addEventListener !== 'function') {
266
359
  return;
267
360
  }
268
361
  const handleScroll = () => {
@@ -274,114 +367,127 @@ const Toolbar = ({
274
367
  setScrolling(false);
275
368
  }, 500);
276
369
  };
277
- window.addEventListener('scroll', handleScroll, {
370
+ scrollEl.addEventListener('scroll', handleScroll, {
278
371
  passive: true
279
372
  });
280
- document.addEventListener('scroll', handleScroll, {
281
- passive: true,
282
- capture: true
283
- });
284
373
  return () => {
285
- window.removeEventListener('scroll', handleScroll);
286
- document.removeEventListener('scroll', handleScroll, {
287
- capture: true
288
- });
374
+ scrollEl.removeEventListener('scroll', handleScroll);
289
375
  if (scrollTimerRef.current) {
290
376
  clearTimeout(scrollTimerRef.current);
291
377
  }
292
378
  };
293
- }, [resolvedTarget]);
379
+ }, [getScrollElement, _show, scrollReady]);
294
380
  if (!_show) {
295
381
  return null;
296
382
  }
297
- return /*#__PURE__*/jsx("div", {
298
- className: classnames('toolbar', style$1['toolbar'], className),
299
- children: /*#__PURE__*/createPortal(/*#__PURE__*/jsxs(Flex, {
300
- ref: listRef,
301
- className: classnames('toolbar-list', style$1['toolbar-list'], {
302
- ['is-clicked']: clicked,
303
- ['is-scrolling']: scrolling
304
- }),
383
+ const toolbarList = /*#__PURE__*/jsxs(Flex, {
384
+ ref: listRef,
385
+ className: classnames('toolbar-list', style$1['toolbar-list'], {
386
+ ['is-clicked']: clicked,
387
+ ['is-scrolling']: scrolling,
388
+ [style$1['is-boundary']]: useBoundaryMount,
389
+ [style$1['is-viewport']]: useViewportFixed
390
+ }),
391
+ style: {
392
+ '--toolbar-count': toolbarMenu.length || 1
393
+ },
394
+ onAnimationEnd: () => {
395
+ if (clicked) {
396
+ setClicked(false);
397
+ }
398
+ },
399
+ children: [indicator.visible && /*#__PURE__*/jsx("div", {
400
+ className: classnames('toolbar-indicator', style$1['toolbar-indicator']),
305
401
  style: {
306
- '--toolbar-count': toolbarMenu.length || 1
307
- },
308
- onAnimationEnd: () => {
309
- if (clicked) {
310
- setClicked(false);
311
- }
312
- },
313
- children: [indicator.visible && /*#__PURE__*/jsx("div", {
314
- className: classnames('toolbar-indicator', style$1['toolbar-indicator']),
315
- style: {
316
- left: `${indicator.left}px`,
317
- width: `${indicator.width}px`,
318
- transform: `scale(${indicator.scale})`
319
- }
320
- }), toolbarMenu.map((item, index) => {
321
- const active = index === activeIndex;
322
- const icon = typeof item.icon === 'function' ? item.icon({
323
- active
324
- }) : item.icon;
325
- return /*#__PURE__*/jsxs(Flex, {
326
- ref: el => {
327
- itemRefs.current[index] = el;
328
- },
329
- vertical: true,
330
- flex: 1,
331
- justify: "center",
332
- align: "center",
333
- className: classnames('toolbar-item', style$1['toolbar-item'], {
334
- ['is-active']: active,
335
- [style$1['is-hidden']]: scrolling && index !== displayIndex
336
- }),
337
- onClick: e => {
338
- if (active) {
339
- return;
340
- }
341
- setClicked(true);
342
- onChange && onChange(item, {
343
- base: _base
402
+ left: `${indicator.left}px`,
403
+ width: `${indicator.width}px`,
404
+ transform: `scale(${indicator.scale})`
405
+ }
406
+ }), toolbarMenu.map((item, index) => {
407
+ const active = index === activeIndex;
408
+ const icon = typeof item.icon === 'function' ? item.icon({
409
+ active
410
+ }) : item.icon;
411
+ return /*#__PURE__*/jsxs(Flex, {
412
+ ref: el => {
413
+ itemRefs.current[index] = el;
414
+ },
415
+ vertical: true,
416
+ flex: 1,
417
+ justify: "center",
418
+ align: "center",
419
+ className: classnames('toolbar-item', style$1['toolbar-item'], {
420
+ ['is-active']: active,
421
+ [style$1['is-hidden']]: scrolling && index !== displayIndex
422
+ }),
423
+ onClick: e => {
424
+ if (active) {
425
+ return;
426
+ }
427
+ setClicked(true);
428
+ onChange && onChange(item, {
429
+ base: _base
430
+ });
431
+ if (typeof item.onClick === 'function') {
432
+ item.onClick(item, {
433
+ base: _base,
434
+ event: e
344
435
  });
345
- if (typeof item.onClick === 'function') {
346
- item.onClick(item, {
347
- menuOpen,
348
- base: _base,
349
- event: e
350
- });
351
- return;
352
- }
353
- if (item.path) {
354
- navigate(ensureSlash(`${_base}${item.path}`));
355
- }
356
- },
357
- children: [(icon => {
358
- if (typeof icon === 'string') {
359
- return /*#__PURE__*/jsx(Icon, {
360
- className: classnames('toolbar-item-icon', style$1['toolbar-item-icon']),
361
- type: icon,
362
- fontClassName: "system"
363
- });
364
- }
365
- if (/*#__PURE__*/isValidElement(icon)) {
366
- return /*#__PURE__*/jsx("span", {
367
- className: classnames('toolbar-item-icon', style$1['toolbar-item-icon']),
368
- children: icon
369
- });
370
- }
371
- if (isPlainObject(icon) && typeof icon.type === 'string') {
372
- return /*#__PURE__*/jsx(Icon, _extends({}, icon, {
373
- className: classnames('toolbar-item-icon', style$1['toolbar-item-icon'])
374
- }));
375
- }
376
- return null;
377
- })(icon), /*#__PURE__*/jsx("div", {
378
- className: classnames('toolbar-item-label', style$1['toolbar-item-label']),
379
- children: item.label
380
- })]
381
- }, item.key || item.path || index);
382
- })]
383
- }), resolvedTarget || document.body)
436
+ return;
437
+ }
438
+ if (item.path) {
439
+ navigate(ensureSlash(`${_base}${item.path}`));
440
+ }
441
+ },
442
+ children: [(icon => {
443
+ if (typeof icon === 'string') {
444
+ return /*#__PURE__*/jsx(Icon, {
445
+ className: classnames('toolbar-item-icon', style$1['toolbar-item-icon']),
446
+ type: icon,
447
+ fontClassName: "system"
448
+ });
449
+ }
450
+ if (/*#__PURE__*/isValidElement(icon)) {
451
+ return /*#__PURE__*/jsx("span", {
452
+ className: classnames('toolbar-item-icon', style$1['toolbar-item-icon']),
453
+ children: icon
454
+ });
455
+ }
456
+ if (isPlainObject(icon) && typeof icon.type === 'string') {
457
+ return /*#__PURE__*/jsx(Icon, _extends({}, icon, {
458
+ className: classnames('toolbar-item-icon', style$1['toolbar-item-icon'])
459
+ }));
460
+ }
461
+ return null;
462
+ })(icon), /*#__PURE__*/jsx("div", {
463
+ className: classnames('toolbar-item-label', style$1['toolbar-item-label']),
464
+ children: item.label
465
+ })]
466
+ }, item.key || item.path || index);
467
+ })]
384
468
  });
469
+ if (useBoundaryMount && boundaryTarget) {
470
+ return /*#__PURE__*/jsx("div", {
471
+ className: classnames('toolbar', style$1['toolbar'], className),
472
+ children: /*#__PURE__*/createPortal(/*#__PURE__*/jsx("div", {
473
+ className: classnames('toolbar-boundary-overlay', style$1['toolbar-boundary-overlay']),
474
+ children: toolbarList
475
+ }), boundaryTarget)
476
+ });
477
+ }
478
+ if (useViewportFixed) {
479
+ return /*#__PURE__*/jsx("div", {
480
+ className: classnames('toolbar', style$1['toolbar'], style$1['toolbar-inline'], className),
481
+ children: toolbarList
482
+ });
483
+ }
484
+ if (explicitTarget) {
485
+ return /*#__PURE__*/jsx("div", {
486
+ className: classnames('toolbar', style$1['toolbar'], className),
487
+ children: /*#__PURE__*/createPortal(toolbarList, explicitTarget)
488
+ });
489
+ }
490
+ return null;
385
491
  };
386
492
 
387
493
  const locale$1 = {
@@ -429,33 +535,49 @@ const ErrorBoundary = props => {
429
535
  }));
430
536
  };
431
537
 
432
- const context = /*#__PURE__*/createContext({});
433
- const useContext = () => {
434
- return useContext$1(context);
538
+ const hasParentResponsiveProvider = parent => {
539
+ return parent.getBoundaryElement !== defaultResponsiveContextValue.getBoundaryElement || parent.getScrollElement !== defaultResponsiveContextValue.getScrollElement;
435
540
  };
436
- const {
437
- Provider,
438
- Consumer
439
- } = context;
440
-
441
- const isMobile = () => {
442
- return /iPhone|iPod|Android|ios|iPad/i.test(navigator.userAgent) || window.innerWidth < 768;
541
+ const resolvePageScrollElement = (pageScrollRef, openScrollbar, deviceIsMobile) => {
542
+ if (deviceIsMobile && !openScrollbar) {
543
+ const _anchor = pageScrollRef.current;
544
+ if (_anchor && _anchor.parentElement) {
545
+ const parentScroll = findResponsiveScroll(_anchor.parentElement);
546
+ if (parentScroll) {
547
+ return parentScroll;
548
+ }
549
+ }
550
+ return getDefaultScrollElement();
551
+ }
552
+ const anchor = pageScrollRef.current;
553
+ if (anchor && typeof anchor.getScrollElement === 'function') {
554
+ return anchor.getScrollElement();
555
+ }
556
+ if (anchor && anchor.nodeType === 1 && openScrollbar) {
557
+ const wrapper = anchor.querySelector('.simplebar-content-wrapper');
558
+ if (wrapper) {
559
+ return wrapper;
560
+ }
561
+ }
562
+ return findResponsiveScroll(anchor) || getDefaultScrollElement();
443
563
  };
444
-
445
- const useIsMobile = () => {
446
- const [isMobile$1, setIsMobile] = useState(() => isMobile());
447
- useEffect(() => {
448
- const handler = throttle(() => {
449
- setIsMobile(isMobile());
450
- }, 500);
451
- window.addEventListener('resize', handler);
452
- return () => {
453
- window.removeEventListener('resize', handler);
454
- };
455
- }, []);
456
- return isMobile$1;
564
+ const LayoutResponsiveScope = ({
565
+ boundaryRef,
566
+ scrollRef,
567
+ getScrollElement,
568
+ children
569
+ }) => {
570
+ const parent = useResponsiveContext();
571
+ if (hasParentResponsiveProvider(parent)) {
572
+ return children;
573
+ }
574
+ return /*#__PURE__*/jsx(ResponsiveProvider, {
575
+ boundaryRef: boundaryRef,
576
+ scrollRef: scrollRef,
577
+ getScrollElement: getScrollElement,
578
+ children: children
579
+ });
457
580
  };
458
-
459
581
  const LayoutMenuOpenKey = 'LAYOUT_MENU_OPEN';
460
582
  const Layout = ({
461
583
  className,
@@ -474,11 +596,15 @@ const Layout = ({
474
596
  }) => {
475
597
  const localMenuOpen = localStorage.getItem(LayoutMenuOpenKey);
476
598
  const isMobile = useIsMobile();
599
+ const responsiveContext = useResponsiveContext();
477
600
  const deviceIsMobile = typeof isMobileProps === 'boolean' ? isMobileProps : isMobile;
601
+ const useMenuPortal = deviceIsMobile && responsiveContext.mode === 'container';
602
+ const [menuPortalTarget, setMenuPortalTarget] = useState(null);
478
603
  const [menuOpen, setMenuOpen] = useState(typeof localMenuOpen === 'boolean' && !deviceIsMobile ? localMenuOpen : !deviceIsMobile);
479
604
  const [toolbarShow, setToolbarShow] = useState(true);
480
605
  const [navbarShow, setNavbarShow] = useState(true);
481
606
  const [aiType, setAiType] = useState('closed');
607
+ const [scrollReady, setScrollReady] = useState(0);
482
608
  const openScrollbar = typeof openScrollbarProps === 'boolean' ? openScrollbarProps : !deviceIsMobile && !window.__COMPONENTS_CORE_SIMPLE_BAR_DISABLED;
483
609
  const userAvatar = userInfo == null ? void 0 : userInfo.avatar;
484
610
  const contextValue = useMemo(() => {
@@ -487,194 +613,245 @@ const Layout = ({
487
613
  setNavbarShow,
488
614
  setMenuOpen,
489
615
  deviceIsMobile,
616
+ scrollReady,
490
617
  logo: Object.assign({}, logo ? logo : {
491
618
  src: defaultLogo
492
619
  }),
493
620
  userAvatar
494
621
  };
495
- }, [deviceIsMobile, logo, userAvatar]);
622
+ }, [deviceIsMobile, logo, userAvatar, scrollReady]);
496
623
  const topRef = useRef(null);
497
624
  const pageRef = useRef(null);
498
- const [computedToolbarTarget, setComputedToolbarTarget] = useState(toolbarTarget || null);
625
+ const layoutBoundaryRef = useRef(null);
626
+ const pageScrollRef = useRef(null);
499
627
  const location = useLocation();
500
- useLayoutEffect(() => {
501
- if (!toolbarTarget) {
502
- setComputedToolbarTarget(document.body);
628
+ const getPageScrollElement = useCallback(() => {
629
+ return resolvePageScrollElement(pageScrollRef, openScrollbar, deviceIsMobile);
630
+ }, [openScrollbar, deviceIsMobile]);
631
+ const handlePageScrollRef = useCallback(node => {
632
+ pageScrollRef.current = node;
633
+ if (node) {
634
+ setScrollReady(version => version + 1);
503
635
  }
504
- }, [toolbarTarget]);
636
+ }, []);
505
637
  useEffect(() => {
506
- topRef.current && topRef.current.scrollIntoView();
507
- }, [location]);
638
+ if (!useMenuPortal) {
639
+ setMenuPortalTarget(null);
640
+ return;
641
+ }
642
+ const target = typeof responsiveContext.getBoundaryElement === 'function' ? responsiveContext.getBoundaryElement() : null;
643
+ setMenuPortalTarget(target || null);
644
+ }, [useMenuPortal, responsiveContext, scrollReady]);
645
+ useEffect(() => {
646
+ var _topRef$current;
647
+ const scrollEl = getPageScrollElement();
648
+ if (scrollEl && typeof scrollEl.scrollTo === 'function') {
649
+ scrollEl.scrollTo(0, 0);
650
+ return;
651
+ }
652
+ (_topRef$current = topRef.current) == null || _topRef$current.scrollIntoView();
653
+ }, [location, getPageScrollElement]);
508
654
  const userCard = /*#__PURE__*/jsx(UserCard, _extends({
509
655
  menuOpen: menuOpen
510
656
  }, Object.assign({}, userInfo)));
511
- return /*#__PURE__*/jsxs(Provider, {
512
- value: contextValue,
657
+ const menuPortalVars = useMenuPortal ? {
658
+ '--menu-max-width': _menuMaxWidth,
659
+ '--menu-min-width': _menuMinWidth,
660
+ '--background': _background
661
+ } : undefined;
662
+ const layerMenuNode = deviceIsMobile ? /*#__PURE__*/jsx("div", {
663
+ className: classnames('layer-menu', style$3['layer-menu'], {
664
+ ['open']: menuOpen,
665
+ [style$3['open']]: menuOpen,
666
+ [style$3['is-portaled']]: useMenuPortal
667
+ }),
668
+ style: menuPortalVars,
669
+ onClick: () => {
670
+ setMenuOpen(false);
671
+ }
672
+ }) : null;
673
+ const menuNode = /*#__PURE__*/jsxs("div", {
674
+ className: classnames('menu', style$3['menu'], {
675
+ ['open']: menuOpen,
676
+ [style$3['open']]: menuOpen,
677
+ [style$3['is-portaled']]: useMenuPortal
678
+ }),
679
+ style: menuPortalVars,
513
680
  children: [/*#__PURE__*/jsx("div", {
514
- ref: topRef
515
- }), /*#__PURE__*/jsxs("div", {
516
- className: classnames(className, 'layout', style$3['layout'], {
517
- 'is-mobile': deviceIsMobile,
518
- [style$3['is-mobile']]: deviceIsMobile,
519
- 'has-toolbar': deviceIsMobile && toolbarShow,
520
- [style$3['has-toolbar']]: deviceIsMobile && toolbarShow,
521
- 'has-navbar': deviceIsMobile && navbarShow,
522
- [style$3['has-navbar']]: deviceIsMobile && navbarShow
523
- }),
524
- style: {
525
- '--menu-max-width': _menuMaxWidth,
526
- '--menu-min-width': _menuMinWidth,
527
- '--background': _background
681
+ className: classnames('logo', style$3['logo']),
682
+ children: /*#__PURE__*/jsx(Image, _extends({
683
+ className: style$3['logo-img']
684
+ }, contextValue.logo))
685
+ }), /*#__PURE__*/jsx("div", {
686
+ className: classnames('expand-btn-wrapper', style$3['expand-btn-wrapper']),
687
+ onClick: () => {
688
+ setMenuOpen(menuOpen => {
689
+ localStorage.setItem(LayoutMenuOpenKey, !menuOpen);
690
+ return !menuOpen;
691
+ });
528
692
  },
529
- children: [deviceIsMobile && /*#__PURE__*/jsx("div", {
530
- className: classnames('layer-menu', style$3['layer-menu'], {
531
- ['open']: menuOpen,
532
- [style$3['open']]: menuOpen
533
- }),
693
+ children: /*#__PURE__*/jsx(ReactComponent, {
694
+ className: classnames('expand-btn', style$3['expand-btn'], {
695
+ 'is-closed': !menuOpen
696
+ })
697
+ })
698
+ }), /*#__PURE__*/jsxs("div", {
699
+ className: classnames('menu-inner', style$3['menu-inner']),
700
+ children: [/*#__PURE__*/jsx("div", {
701
+ className: classnames('menu-header', style$3['menu-header']),
702
+ children: /*#__PURE__*/jsx(ErrorBoundary, {
703
+ children: menuHeader ? typeof menuHeader === 'function' ? menuHeader({
704
+ menuOpen,
705
+ userCard
706
+ }) : menuHeader : userCard
707
+ })
708
+ }), /*#__PURE__*/jsx(ErrorBoundary, {
709
+ children: /*#__PURE__*/jsx(Menu, _extends({
710
+ className: classnames('menu-list', style$3['menu-list']),
711
+ menuOpen: menuOpen
712
+ }, menu, {
713
+ onChange: () => {
714
+ deviceIsMobile && setMenuOpen(false);
715
+ }
716
+ }))
717
+ }), _aiDialog && /*#__PURE__*/jsx("div", {
718
+ className: classnames('ai-entry', style$3['ai-entry']),
534
719
  onClick: () => {
535
- setMenuOpen(false);
536
- }
537
- }), /*#__PURE__*/jsxs(Flex, {
538
- children: [/*#__PURE__*/jsxs("div", {
539
- className: classnames('menu', style$3['menu'], {
540
- ['open']: menuOpen,
541
- [style$3['open']]: menuOpen
542
- }),
543
- children: [/*#__PURE__*/jsx("div", {
544
- className: classnames('logo', style$3['logo']),
545
- children: /*#__PURE__*/jsx(Image, _extends({
546
- className: style$3['logo-img']
547
- }, contextValue.logo))
548
- }), /*#__PURE__*/jsx("div", {
549
- className: classnames('expand-btn-wrapper', style$3['expand-btn-wrapper']),
550
- onClick: () => {
551
- setMenuOpen(menuOpen => {
552
- localStorage.setItem(LayoutMenuOpenKey, !menuOpen);
553
- return !menuOpen;
554
- });
555
- },
556
- children: /*#__PURE__*/jsx(ReactComponent, {
557
- className: classnames('expand-btn', style$3['expand-btn'], {
558
- 'is-closed': !menuOpen
559
- })
560
- })
561
- }), /*#__PURE__*/jsxs("div", {
562
- className: classnames('menu-inner', style$3['menu-inner']),
563
- children: [/*#__PURE__*/jsx("div", {
564
- className: classnames('menu-header', style$3['menu-header']),
565
- children: /*#__PURE__*/jsx(ErrorBoundary, {
566
- children: menuHeader ? typeof menuHeader === 'function' ? menuHeader({
567
- menuOpen,
568
- userCard
569
- }) : menuHeader : userCard
570
- })
571
- }), /*#__PURE__*/jsx(ErrorBoundary, {
572
- children: /*#__PURE__*/jsx(Menu, _extends({
573
- className: classnames('menu-list', style$3['menu-list']),
574
- menuOpen: menuOpen
575
- }, menu, {
576
- onChange: () => {
577
- deviceIsMobile && setMenuOpen(false);
578
- }
579
- }))
580
- }), _aiDialog && /*#__PURE__*/jsx("div", {
581
- className: classnames('ai-entry', style$3['ai-entry']),
582
- onClick: () => {
583
- setAiType('small');
584
- },
585
- children: /*#__PURE__*/jsx(Icon, {
586
- type: "system-prompt",
587
- colorful: true
588
- })
589
- })]
590
- })]
591
- }), /*#__PURE__*/jsx(Flex, {
592
- flex: 1,
593
- ref: pageRef,
594
- className: classnames('page', style$3['page']),
595
- children: /*#__PURE__*/jsxs(Row, {
596
- className: classnames('page-content', style$3['page-content']),
597
- children: [!deviceIsMobile && _aiDialog && aiType === 'inner' && /*#__PURE__*/jsx(Col, {
598
- span: 8,
599
- className: classnames('page-dialog-outer', style$3['page-dialog-outer']),
600
- children: /*#__PURE__*/jsxs("div", {
601
- className: classnames('page-dialog', style$3['page-dialog']),
602
- children: [/*#__PURE__*/jsxs(Flex, {
603
- className: classnames('ai-dialog-window-title', style$3['ai-dialog-window-title']),
604
- children: [/*#__PURE__*/jsx("div", {
605
- children: _aiDialog.title
606
- }), /*#__PURE__*/jsx(Flex, {
607
- gap: 10,
608
- children: /*#__PURE__*/jsx(Icon, {
609
- className: "btn",
610
- type: "icon-a-Typeclose",
611
- fontClassName: "system",
612
- onClick: () => {
613
- setAiType('closed');
614
- }
720
+ setAiType('small');
721
+ },
722
+ children: /*#__PURE__*/jsx(Icon, {
723
+ type: "system-prompt",
724
+ colorful: true
725
+ })
726
+ })]
727
+ })]
728
+ });
729
+ const portalMenu = useMenuPortal && menuPortalTarget;
730
+ return /*#__PURE__*/jsx(LayoutResponsiveScope, {
731
+ boundaryRef: layoutBoundaryRef,
732
+ scrollRef: pageScrollRef,
733
+ getScrollElement: getPageScrollElement,
734
+ children: /*#__PURE__*/jsxs(Provider, {
735
+ value: contextValue,
736
+ children: [/*#__PURE__*/jsx("div", {
737
+ ref: topRef
738
+ }), /*#__PURE__*/jsxs("div", {
739
+ ref: layoutBoundaryRef,
740
+ className: classnames(className, 'layout', style$3['layout'], RESPONSIVE_BOUNDARY_CLASS, {
741
+ 'is-mobile': deviceIsMobile,
742
+ [style$3['is-mobile']]: deviceIsMobile,
743
+ 'has-toolbar': deviceIsMobile && toolbarShow,
744
+ [style$3['has-toolbar']]: deviceIsMobile && toolbarShow,
745
+ 'has-navbar': deviceIsMobile && navbarShow,
746
+ [style$3['has-navbar']]: deviceIsMobile && navbarShow
747
+ }),
748
+ style: {
749
+ '--menu-max-width': _menuMaxWidth,
750
+ '--menu-min-width': _menuMinWidth,
751
+ '--background': _background
752
+ },
753
+ children: [!portalMenu && layerMenuNode, /*#__PURE__*/jsxs(Flex, {
754
+ style: {
755
+ flex: 1,
756
+ minHeight: 0,
757
+ width: '100%',
758
+ height: 0
759
+ },
760
+ children: [!portalMenu && menuNode, portalMenu && /*#__PURE__*/createPortal(/*#__PURE__*/jsxs("div", {
761
+ className: classnames(style$3['menu-boundary-overlay']),
762
+ style: menuPortalVars,
763
+ children: [layerMenuNode, menuNode]
764
+ }), menuPortalTarget), /*#__PURE__*/jsx(Flex, {
765
+ flex: 1,
766
+ ref: pageRef,
767
+ className: classnames('page', style$3['page']),
768
+ children: /*#__PURE__*/jsxs(Row, {
769
+ className: classnames('page-content', style$3['page-content']),
770
+ children: [!deviceIsMobile && _aiDialog && aiType === 'inner' && /*#__PURE__*/jsx(Col, {
771
+ span: 8,
772
+ className: classnames('page-dialog-outer', style$3['page-dialog-outer']),
773
+ children: /*#__PURE__*/jsxs("div", {
774
+ className: classnames('page-dialog', style$3['page-dialog']),
775
+ children: [/*#__PURE__*/jsxs(Flex, {
776
+ className: classnames('ai-dialog-window-title', style$3['ai-dialog-window-title']),
777
+ children: [/*#__PURE__*/jsx("div", {
778
+ children: _aiDialog.title
779
+ }), /*#__PURE__*/jsx(Flex, {
780
+ gap: 10,
781
+ children: /*#__PURE__*/jsx(Icon, {
782
+ className: "btn",
783
+ type: "icon-a-Typeclose",
784
+ fontClassName: "system",
785
+ onClick: () => {
786
+ setAiType('closed');
787
+ }
788
+ })
789
+ })]
790
+ }), /*#__PURE__*/jsx(ErrorBoundary, {
791
+ children: /*#__PURE__*/jsx("div", {
792
+ className: classnames('page-window-content', style$3['page-window-content']),
793
+ children: _aiDialog.content
615
794
  })
616
795
  })]
617
- }), /*#__PURE__*/jsx(ErrorBoundary, {
618
- children: /*#__PURE__*/jsx("div", {
619
- className: classnames('page-window-content', style$3['page-window-content']),
620
- children: _aiDialog.content
796
+ })
797
+ }), /*#__PURE__*/jsx(Col, {
798
+ span: !deviceIsMobile && _aiDialog && aiType === 'inner' ? 16 : 24,
799
+ className: RESPONSIVE_CONTAINER_CLASS,
800
+ children: /*#__PURE__*/jsx(ErrorBoundary, {
801
+ children: openScrollbar ? /*#__PURE__*/jsx(SimpleBar, {
802
+ ref: handlePageScrollRef,
803
+ className: classnames('page-children', style$3['page-children'], RESPONSIVE_SCROLL_CLASS, {
804
+ ['has-left']: aiType === 'inner'
805
+ }),
806
+ children: children
807
+ }) : /*#__PURE__*/jsx("div", {
808
+ ref: handlePageScrollRef,
809
+ className: classnames('page-children', style$3['page-children'], !deviceIsMobile && 'is-scroller', !deviceIsMobile && style$3['is-scroller'], !deviceIsMobile && RESPONSIVE_SCROLL_CLASS, {
810
+ ['has-left']: aiType === 'inner'
811
+ }),
812
+ children: children
621
813
  })
622
- })]
623
- })
624
- }), /*#__PURE__*/jsx(Col, {
625
- span: !deviceIsMobile && _aiDialog && aiType === 'inner' ? 16 : 24,
626
- children: /*#__PURE__*/jsx(ErrorBoundary, {
627
- children: openScrollbar ? /*#__PURE__*/jsx(SimpleBar, {
628
- className: classnames('page-children', style$3['page-children'], {
629
- ['has-left']: aiType === 'inner'
630
- }),
631
- children: children
632
- }) : /*#__PURE__*/jsx("div", {
633
- className: classnames('page-children', 'is-scroller', style$3['page-children'], style$3['is-scroller'], {
634
- ['has-left']: aiType === 'inner'
635
- }),
636
- children: children
637
814
  })
638
- })
639
- })]
640
- })
641
- }), _aiDialog && aiType === 'small' && /*#__PURE__*/jsxs("div", {
642
- className: classnames('ai-dialog-window', style$3['ai-dialog-window']),
643
- children: [/*#__PURE__*/jsxs(Flex, {
644
- className: classnames('ai-dialog-window-title', style$3['ai-dialog-window-title']),
645
- children: [/*#__PURE__*/jsx("div", {
646
- children: _aiDialog.title
647
- }), /*#__PURE__*/jsxs(Flex, {
648
- gap: 10,
649
- children: [/*#__PURE__*/jsx(Icon, {
650
- className: "btn",
651
- type: "icon-a-Typeopen_in_full",
652
- fontClassName: "system",
653
- onClick: () => {
654
- setAiType('inner');
655
- }
656
- }), /*#__PURE__*/jsx(Icon, {
657
- className: "btn",
658
- type: "icon-a-Typeclose",
659
- fontClassName: "system",
660
- onClick: () => {
661
- setAiType('closed');
662
- }
663
815
  })]
664
- })]
665
- }), /*#__PURE__*/jsx(ErrorBoundary, {
666
- children: /*#__PURE__*/jsx("div", {
667
- className: classnames('ai-dialog-window-content', style$3['ai-dialog-window-content']),
668
- children: _aiDialog.content
669
816
  })
817
+ }), _aiDialog && aiType === 'small' && /*#__PURE__*/jsxs("div", {
818
+ className: classnames('ai-dialog-window', style$3['ai-dialog-window']),
819
+ children: [/*#__PURE__*/jsxs(Flex, {
820
+ className: classnames('ai-dialog-window-title', style$3['ai-dialog-window-title']),
821
+ children: [/*#__PURE__*/jsx("div", {
822
+ children: _aiDialog.title
823
+ }), /*#__PURE__*/jsxs(Flex, {
824
+ gap: 10,
825
+ children: [/*#__PURE__*/jsx(Icon, {
826
+ className: "btn",
827
+ type: "icon-a-Typeopen_in_full",
828
+ fontClassName: "system",
829
+ onClick: () => {
830
+ setAiType('inner');
831
+ }
832
+ }), /*#__PURE__*/jsx(Icon, {
833
+ className: "btn",
834
+ type: "icon-a-Typeclose",
835
+ fontClassName: "system",
836
+ onClick: () => {
837
+ setAiType('closed');
838
+ }
839
+ })]
840
+ })]
841
+ }), /*#__PURE__*/jsx(ErrorBoundary, {
842
+ children: /*#__PURE__*/jsx("div", {
843
+ className: classnames('ai-dialog-window-content', style$3['ai-dialog-window-content']),
844
+ children: _aiDialog.content
845
+ })
846
+ })]
670
847
  })]
671
- })]
672
- }), /*#__PURE__*/jsx(Toolbar, _extends({}, menu, {
673
- className: classnames(style$3['toolbar']),
674
- show: deviceIsMobile && toolbarShow,
675
- target: computedToolbarTarget
676
- }))]
677
- })]
848
+ }), /*#__PURE__*/jsx(Toolbar, _extends({}, menu, {
849
+ className: classnames(style$3['toolbar']),
850
+ show: deviceIsMobile && toolbarShow,
851
+ target: toolbarTarget
852
+ }))]
853
+ })]
854
+ })
678
855
  });
679
856
  };
680
857
 
@@ -707,9 +884,11 @@ const Page = ({
707
884
  setNavbarShow,
708
885
  setMenuOpen,
709
886
  deviceIsMobile,
710
- userAvatar
887
+ userAvatar,
888
+ scrollReady
711
889
  } = useContext();
712
890
  const navigate = useNavigate();
891
+ const getScrollElement = useScrollElement();
713
892
  const navbarRef = useRef(null);
714
893
  const [isScrolled, setIsScrolled] = useState(false);
715
894
  useEffect(() => {
@@ -720,16 +899,20 @@ const Page = ({
720
899
  if (!deviceIsMobile || !_navbar) {
721
900
  return;
722
901
  }
902
+ const scrollEl = getScrollElement();
903
+ if (!scrollEl || typeof scrollEl.addEventListener !== 'function') {
904
+ return;
905
+ }
723
906
  const handleScroll = () => {
724
907
  const threshold = navbarRef.current ? navbarRef.current.offsetHeight : 48;
725
- setIsScrolled(window.scrollY > threshold);
908
+ setIsScrolled(scrollEl.scrollTop > threshold);
726
909
  };
727
910
  handleScroll();
728
- window.addEventListener('scroll', handleScroll, {
911
+ scrollEl.addEventListener('scroll', handleScroll, {
729
912
  passive: true
730
913
  });
731
- return () => window.removeEventListener('scroll', handleScroll);
732
- }, [deviceIsMobile, _navbar]);
914
+ return () => scrollEl.removeEventListener('scroll', handleScroll);
915
+ }, [deviceIsMobile, _navbar, getScrollElement, scrollReady]);
733
916
  const navbarEl = _navbar ? /*#__PURE__*/jsxs(Flex, {
734
917
  ref: navbarRef,
735
918
  justify: "space-between",
@@ -832,6 +1015,13 @@ const Page = ({
832
1015
  };
833
1016
  Page.PageLoading = PageLoading;
834
1017
 
1018
+ const isMobile = () => {
1019
+ if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
1020
+ return false;
1021
+ }
1022
+ return window.matchMedia(IS_MOBILE_QUERY).matches;
1023
+ };
1024
+
835
1025
  const transparentBgContainer = {
836
1026
  colorBgContainer: 'transparent'
837
1027
  };
@@ -844,5 +1034,5 @@ const themeToken = {
844
1034
 
845
1035
  import('./index-0916fdba.js');
846
1036
 
847
- export { Layout, Page, Layout as default, isMobile, themeToken, useIsMobile, useContext as useLayoutContext };
1037
+ export { Layout, Page, Layout as default, isMobile, themeToken, useContext as useLayoutContext };
848
1038
  //# sourceMappingURL=index.modern.js.map