@kne/system-layout 0.2.0-alpha.2 → 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,14 +1,17 @@
1
- import { isValidElement, useContext as useContext$1, createContext, useState, useMemo, useRef, useEffect } from 'react';
2
- import { Flex, Alert, Button, Row, Col } from 'antd';
1
+ import { useRef, useState, useCallback, useMemo, useLayoutEffect, isValidElement, useContext as useContext$1, createContext, useEffect } from 'react';
2
+ import { createPortal } from 'react-dom';
3
+ import { Flex, Alert, Button, Row, Col, Skeleton } from 'antd';
3
4
  import classnames from 'classnames';
4
5
  import localStorage from '@kne/local-storage';
5
6
  import { Image } from '@kne/react-file';
6
- import { jsx, jsxs } from 'react/jsx-runtime';
7
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
8
  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';
@@ -16,6 +19,8 @@ import { createWithIntlProvider, useIntl } from '@kne/react-intl';
16
19
  import SimpleBar from 'simplebar-react';
17
20
  import 'simplebar-react/dist/simplebar.min.css';
18
21
  import ButtonGroup from '@kne/button-group';
22
+ import merge from 'lodash/merge';
23
+ import transform from 'lodash/transform';
19
24
 
20
25
  function _extends() {
21
26
  return _extends = Object.assign ? Object.assign.bind() : function (n) {
@@ -27,7 +32,7 @@ function _extends() {
27
32
  }, _extends.apply(null, arguments);
28
33
  }
29
34
 
30
- var style$3 = {"layout":"_sK89O","has-toolbar":"_gyKfI","menu":"_-LpWn","open":"_G-zuN","layer-menu":"_6TCwG","ai-entry":"_5qnw5","page":"_HnwkM","toolbar":"_h8PAW","page-children":"_OM1Q2","is-mobile":"_udBgQ","menu-inner":"_7wq3X","logo":"_-T-Dc","menu-header":"_LOrmu","logo-img":"_2cRWf","expand-btn-wrapper":"_5D-Oq","expand-btn-bg":"_p4eOE","expand-btn":"_8dzE7","username":"_b7XeQ","user-description":"_U0YTk","menu-list":"_8gqbZ","ai-dialog-window":"_UAJc-","pulse-dialog-window":"_VjIWn","page-dialog-outer":"_I7Anv","page-dialog":"_UhsFd","pulse-page-dialog":"_H7slV","page-window-content":"_2mdNn","is-scroller":"_6gjkS","page-content":"_nyAa2","ai-dialog-window-title":"_33Tja","ai-dialog-window-content":"_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"};
31
36
 
32
37
  const UserCard = ({
33
38
  name,
@@ -35,7 +40,8 @@ const UserCard = ({
35
40
  email,
36
41
  phone,
37
42
  description,
38
- menuOpen
43
+ menuOpen,
44
+ extra
39
45
  }) => {
40
46
  if (!menuOpen) {
41
47
  return /*#__PURE__*/jsx(Image.Avatar, {
@@ -63,13 +69,17 @@ const UserCard = ({
63
69
  }), /*#__PURE__*/jsx("div", {
64
70
  className: classnames('user-description', style$3['user-description']),
65
71
  children: email || phone || description || '-'
66
- })]
72
+ }), extra]
67
73
  })]
68
74
  });
69
75
  };
70
76
 
71
- var style$2 = {"menu-group":"_Rfzv4","menu-item-icon":"_qoDtD","menu-group-split":"_socoO","menu-item":"_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"};
72
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;
73
83
  const Menu = ({
74
84
  className,
75
85
  menuOpen,
@@ -80,94 +90,174 @@ const Menu = ({
80
90
  }) => {
81
91
  const location = useLocation();
82
92
  const navigate = useNavigate();
93
+ const listRef = useRef(null);
94
+ const virtualListRef = useRef(null);
95
+ const [listHeight, setListHeight] = useState(0);
83
96
  const currentPathname = _base ? location.pathname.replace(new RegExp(`^${_base}`), '') : location.pathname;
84
- return /*#__PURE__*/jsx("div", {
85
- className: classnames('menu', className, style$2['menu-list']),
86
- children: items.map((item, index) => {
87
- var _items;
88
- const active = (() => {
89
- if (typeof activeKey === 'string') {
90
- 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;
91
173
  }
92
- if (typeof activeKey === 'function') {
93
- return activeKey(item, {
174
+ onChange && onChange(item, {
175
+ menuOpen,
176
+ base: _base
177
+ });
178
+ if (typeof item.onClick === 'function') {
179
+ item.onClick(item, {
94
180
  menuOpen,
95
- base: _base
181
+ base: _base,
182
+ event: e
96
183
  });
184
+ return;
97
185
  }
98
- if (typeof item.path === 'string') {
99
- return ensureSlash(currentPathname) === ensureSlash(item.path);
186
+ if (item.path) {
187
+ navigate(ensureSlash(`${_base}${item.path}`));
100
188
  }
101
- return false;
102
- })();
103
- const icon = typeof item.icon === 'function' ? item.icon({
104
- menuOpen,
105
- active
106
- }) : item.icon;
107
- const hasGroup = item.group && item.group !== ((_items = items[index - 1]) == null ? void 0 : _items.group);
108
- return /*#__PURE__*/jsxs("div", {
109
- title: item.label,
110
- onClick: e => {
111
- if (active) {
112
- 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
+ });
113
209
  }
114
- onChange && onChange(item, {
115
- menuOpen,
116
- base: _base
117
- });
118
- if (typeof item.onClick === 'function') {
119
- item.onClick(item, {
120
- menuOpen,
121
- base: _base,
122
- 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
123
214
  });
124
- return;
125
215
  }
126
- if (item.path) {
127
- 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
+ }));
128
220
  }
129
- },
130
- children: [hasGroup && menuOpen ? /*#__PURE__*/jsx("div", {
131
- className: classnames('menu-group', style$2['menu-group']),
132
- children: item.groupLabel || item.group
133
- }) : null, hasGroup && !menuOpen ? /*#__PURE__*/jsx("div", {
134
- className: classnames('menu-group-split', style$2['menu-group-split'])
135
- }) : null, /*#__PURE__*/jsxs(Flex, {
136
- className: classnames('menu-item', style$2['menu-item'], {
137
- ['is-active']: active,
138
- ['is-closed']: !menuOpen
139
- }),
140
- align: "center",
141
- gap: 8,
142
- children: [(icon => {
143
- if (typeof icon === 'string') {
144
- return /*#__PURE__*/jsx(Icon, {
145
- className: classnames('menu-item-icon', style$2['menu-item-icon']),
146
- type: icon,
147
- fontClassName: "system"
148
- });
149
- }
150
- if (/*#__PURE__*/isValidElement(icon)) {
151
- return /*#__PURE__*/jsx("span", {
152
- className: classnames('menu-item-icon', style$2['menu-item-icon']),
153
- children: icon
154
- });
155
- }
156
- if (isPlainObject(icon) && typeof icon.type === 'string') {
157
- return /*#__PURE__*/jsx(Icon, _extends({}, icon, {
158
- className: classnames('menu-item-icon', style$2['menu-item-icon'])
159
- }));
160
- }
161
- return null;
162
- })(icon), menuOpen && item.label]
163
- })]
164
- }, item.key || item.path || index);
165
- })
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
166
241
  });
167
242
  };
168
243
 
169
- var style$1 = {"toolbar":"_SLK-0","toolbar-list":"_GTQvM","toolbar-item":"_fAZ3n","toolbar-item-icon":"_qOB9o","toolbar-item-label":"_h48es"};
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"};
170
245
 
246
+ const context = /*#__PURE__*/createContext({});
247
+ const useContext = () => {
248
+ return useContext$1(context);
249
+ };
250
+ const {
251
+ Provider,
252
+ Consumer
253
+ } = context;
254
+
255
+ const resolveTarget = target => {
256
+ if (!target) {
257
+ return null;
258
+ }
259
+ return typeof target === 'function' ? target() : target;
260
+ };
171
261
  const Toolbar = ({
172
262
  show: _show = true,
173
263
  className,
@@ -179,88 +269,225 @@ const Toolbar = ({
179
269
  }) => {
180
270
  const location = useLocation();
181
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();
182
281
  const currentPathname = _base ? location.pathname.replace(new RegExp(`^${_base}`), '') : location.pathname;
183
282
  const toolbarMenu = items.filter(item => item.toolbar);
283
+ const itemRefs = useRef([]);
284
+ const firstRenderRef = useRef(true);
285
+ const [indicator, setIndicator] = useState({
286
+ left: 0,
287
+ width: 0,
288
+ scale: 1,
289
+ visible: false
290
+ });
291
+ const [clicked, setClicked] = useState(false);
292
+ const [scrolling, setScrolling] = useState(false);
293
+ const scrollTimerRef = useRef(null);
294
+ const activeIndex = toolbarMenu.findIndex(item => {
295
+ if (typeof activeKey === 'string') {
296
+ return activeKey === item.key;
297
+ }
298
+ if (typeof activeKey === 'function') {
299
+ return activeKey(item, {
300
+ base: _base
301
+ });
302
+ }
303
+ if (typeof item.path === 'string') {
304
+ return ensureSlash(currentPathname) === ensureSlash(item.path);
305
+ }
306
+ return false;
307
+ });
308
+ const displayIndex = activeIndex >= 0 ? activeIndex : 0;
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;
314
+ useLayoutEffect(() => {
315
+ if (activeIndex < 0) {
316
+ return;
317
+ }
318
+ const item = itemRefs.current[activeIndex];
319
+ const list = listRef.current;
320
+ if (!item || !list) {
321
+ return;
322
+ }
323
+ const itemRect = item.getBoundingClientRect();
324
+ const listRect = list.getBoundingClientRect();
325
+ const newLeft = itemRect.left - listRect.left;
326
+ const newWidth = itemRect.width;
327
+ if (firstRenderRef.current) {
328
+ firstRenderRef.current = false;
329
+ setIndicator({
330
+ left: newLeft,
331
+ width: newWidth,
332
+ scale: 1,
333
+ visible: true
334
+ });
335
+ return;
336
+ }
337
+ setIndicator(prev => _extends({}, prev, {
338
+ scale: 1.15
339
+ }));
340
+ const t1 = setTimeout(() => {
341
+ setIndicator(prev => _extends({}, prev, {
342
+ left: newLeft,
343
+ width: newWidth
344
+ }));
345
+ }, 120);
346
+ const t2 = setTimeout(() => {
347
+ setIndicator(prev => _extends({}, prev, {
348
+ scale: 1
349
+ }));
350
+ }, 380);
351
+ return () => {
352
+ clearTimeout(t1);
353
+ clearTimeout(t2);
354
+ };
355
+ }, [activeIndex, _show, target, useBoundaryMount, useViewportFixed]);
356
+ useEffect(() => {
357
+ const scrollEl = getScrollElement();
358
+ if (!scrollEl || typeof scrollEl.addEventListener !== 'function') {
359
+ return;
360
+ }
361
+ const handleScroll = () => {
362
+ setScrolling(true);
363
+ if (scrollTimerRef.current) {
364
+ clearTimeout(scrollTimerRef.current);
365
+ }
366
+ scrollTimerRef.current = setTimeout(() => {
367
+ setScrolling(false);
368
+ }, 500);
369
+ };
370
+ scrollEl.addEventListener('scroll', handleScroll, {
371
+ passive: true
372
+ });
373
+ return () => {
374
+ scrollEl.removeEventListener('scroll', handleScroll);
375
+ if (scrollTimerRef.current) {
376
+ clearTimeout(scrollTimerRef.current);
377
+ }
378
+ };
379
+ }, [getScrollElement, _show, scrollReady]);
184
380
  if (!_show) {
185
381
  return null;
186
382
  }
187
- return /*#__PURE__*/jsx("div", {
188
- className: classnames('toolbar', style$1['toolbar'], className),
189
- children: /*#__PURE__*/createPortal(/*#__PURE__*/jsx(Flex, {
190
- className: classnames('toolbar-list', style$1['toolbar-list']),
191
- children: toolbarMenu.map((item, index) => {
192
- const active = (() => {
193
- if (typeof activeKey === 'string') {
194
- return activeKey === item.key;
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']),
401
+ style: {
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;
195
426
  }
196
- if (typeof activeKey === 'function') {
197
- return activeKey(item, {
198
- base: _base
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
199
435
  });
436
+ return;
200
437
  }
201
- if (typeof item.path === 'string') {
202
- return ensureSlash(currentPathname) === ensureSlash(item.path);
438
+ if (item.path) {
439
+ navigate(ensureSlash(`${_base}${item.path}`));
203
440
  }
204
- return false;
205
- })();
206
- const icon = typeof item.icon === 'function' ? item.icon({
207
- active
208
- }) : item.icon;
209
- return /*#__PURE__*/jsxs(Flex, {
210
- vertical: true,
211
- flex: 1,
212
- justify: "center",
213
- align: "center",
214
- className: classnames('toolbar-item', style$1['toolbar-item'], {
215
- ['is-active']: active
216
- }),
217
- onClick: e => {
218
- if (active) {
219
- return;
220
- }
221
- onChange && onChange(item, {
222
- base: _base
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"
223
448
  });
224
- if (typeof item.onClick === 'function') {
225
- item.onClick(item, {
226
- menuOpen,
227
- base: _base,
228
- event: e
229
- });
230
- return;
231
- }
232
- if (item.path) {
233
- navigate(ensureSlash(`${_base}${item.path}`));
234
- }
235
- },
236
- children: [(icon => {
237
- if (typeof icon === 'string') {
238
- return /*#__PURE__*/jsx(Icon, {
239
- className: classnames('toolbar-item-icon', style$1['toolbar-item-icon']),
240
- type: icon,
241
- fontClassName: "system"
242
- });
243
- }
244
- if (/*#__PURE__*/isValidElement(icon)) {
245
- return /*#__PURE__*/jsx("span", {
246
- className: classnames('toolbar-item-icon', style$1['toolbar-item-icon']),
247
- children: icon
248
- });
249
- }
250
- if (isPlainObject(icon) && typeof icon.type === 'string') {
251
- return /*#__PURE__*/jsx(Icon, _extends({}, icon, {
252
- className: classnames('toolbar-item-icon', style$1['toolbar-item-icon'])
253
- }));
254
- }
255
- return null;
256
- })(icon), /*#__PURE__*/jsx("div", {
257
- className: classnames('toolbar-item-label', style$1['toolbar-item-label']),
258
- children: item.label
259
- })]
260
- }, item.key || item.path || index);
261
- })
262
- }), target ? typeof target === 'function' ? target() : target : document.body)
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
+ })]
263
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;
264
491
  };
265
492
 
266
493
  const locale$1 = {
@@ -308,19 +535,49 @@ const ErrorBoundary = props => {
308
535
  }));
309
536
  };
310
537
 
311
- const isMobile = () => {
312
- return /iPhone|iPod|Android|ios|iPad/i.test(navigator.userAgent);
538
+ const hasParentResponsiveProvider = parent => {
539
+ return parent.getBoundaryElement !== defaultResponsiveContextValue.getBoundaryElement || parent.getScrollElement !== defaultResponsiveContextValue.getScrollElement;
313
540
  };
314
-
315
- const context = /*#__PURE__*/createContext({});
316
- const useContext = () => {
317
- return useContext$1(context);
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();
563
+ };
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
+ });
318
580
  };
319
- const {
320
- Provider,
321
- Consumer
322
- } = context;
323
-
324
581
  const LayoutMenuOpenKey = 'LAYOUT_MENU_OPEN';
325
582
  const Layout = ({
326
583
  className,
@@ -338,277 +595,444 @@ const Layout = ({
338
595
  children
339
596
  }) => {
340
597
  const localMenuOpen = localStorage.getItem(LayoutMenuOpenKey);
341
- const [menuOpen, setMenuOpen] = useState(typeof localMenuOpen === 'boolean' ? localMenuOpen : true);
598
+ const isMobile = useIsMobile();
599
+ const responsiveContext = useResponsiveContext();
600
+ const deviceIsMobile = typeof isMobileProps === 'boolean' ? isMobileProps : isMobile;
601
+ const useMenuPortal = deviceIsMobile && responsiveContext.mode === 'container';
602
+ const [menuPortalTarget, setMenuPortalTarget] = useState(null);
603
+ const [menuOpen, setMenuOpen] = useState(typeof localMenuOpen === 'boolean' && !deviceIsMobile ? localMenuOpen : !deviceIsMobile);
342
604
  const [toolbarShow, setToolbarShow] = useState(true);
605
+ const [navbarShow, setNavbarShow] = useState(true);
343
606
  const [aiType, setAiType] = useState('closed');
344
- const deviceIsMobile = typeof isMobileProps === 'boolean' ? isMobileProps : isMobile();
607
+ const [scrollReady, setScrollReady] = useState(0);
345
608
  const openScrollbar = typeof openScrollbarProps === 'boolean' ? openScrollbarProps : !deviceIsMobile && !window.__COMPONENTS_CORE_SIMPLE_BAR_DISABLED;
346
609
  const userAvatar = userInfo == null ? void 0 : userInfo.avatar;
347
610
  const contextValue = useMemo(() => {
348
611
  return {
349
612
  setToolbarShow,
613
+ setNavbarShow,
350
614
  setMenuOpen,
351
615
  deviceIsMobile,
616
+ scrollReady,
352
617
  logo: Object.assign({}, logo ? logo : {
353
618
  src: defaultLogo
354
619
  }),
355
620
  userAvatar
356
621
  };
357
- }, [deviceIsMobile, logo, userAvatar]);
622
+ }, [deviceIsMobile, logo, userAvatar, scrollReady]);
358
623
  const topRef = useRef(null);
624
+ const pageRef = useRef(null);
625
+ const layoutBoundaryRef = useRef(null);
626
+ const pageScrollRef = useRef(null);
359
627
  const location = useLocation();
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);
635
+ }
636
+ }, []);
637
+ useEffect(() => {
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]);
360
645
  useEffect(() => {
361
- topRef.current && topRef.current.scrollIntoView();
362
- }, [location]);
363
- return /*#__PURE__*/jsxs(Provider, {
364
- value: contextValue,
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]);
654
+ const userCard = /*#__PURE__*/jsx(UserCard, _extends({
655
+ menuOpen: menuOpen
656
+ }, Object.assign({}, userInfo)));
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,
365
680
  children: [/*#__PURE__*/jsx("div", {
366
- ref: topRef
367
- }), /*#__PURE__*/jsxs("div", {
368
- className: classnames(className, 'layout', style$3['layout'], {
369
- 'is-mobile': deviceIsMobile,
370
- [style$3['is-mobile']]: deviceIsMobile,
371
- 'has-toolbar': toolbarShow,
372
- [style$3['has-toolbar']]: toolbarShow
373
- }),
374
- style: {
375
- '--menu-max-width': _menuMaxWidth,
376
- '--menu-min-width': _menuMinWidth,
377
- '--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
+ });
378
692
  },
379
- children: [deviceIsMobile && /*#__PURE__*/jsx("div", {
380
- className: classnames('layer-menu', style$3['layer-menu'], {
381
- ['open']: menuOpen,
382
- [style$3['open']]: menuOpen
383
- }),
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']),
384
719
  onClick: () => {
385
- setMenuOpen(false);
386
- }
387
- }), /*#__PURE__*/jsxs(Flex, {
388
- children: [/*#__PURE__*/jsxs("div", {
389
- className: classnames('menu', style$3['menu'], {
390
- ['open']: menuOpen,
391
- [style$3['open']]: menuOpen
392
- }),
393
- children: [/*#__PURE__*/jsx("div", {
394
- className: classnames('logo', style$3['logo']),
395
- children: /*#__PURE__*/jsx(Image, _extends({
396
- className: style$3['logo-img']
397
- }, contextValue.logo))
398
- }), /*#__PURE__*/jsx("div", {
399
- className: classnames('expand-btn-wrapper', style$3['expand-btn-wrapper']),
400
- onClick: () => {
401
- setMenuOpen(menuOpen => {
402
- localStorage.setItem(LayoutMenuOpenKey, !menuOpen);
403
- return !menuOpen;
404
- });
405
- },
406
- children: /*#__PURE__*/jsx(ReactComponent, {
407
- className: classnames('expand-btn', style$3['expand-btn'], {
408
- 'is-closed': !menuOpen
409
- })
410
- })
411
- }), /*#__PURE__*/jsxs("div", {
412
- className: classnames('menu-inner', style$3['menu-inner']),
413
- children: [/*#__PURE__*/jsx("div", {
414
- className: classnames('menu-header', style$3['menu-header']),
415
- children: /*#__PURE__*/jsx(ErrorBoundary, {
416
- children: menuHeader ? typeof menuHeader === 'function' ? menuHeader({
417
- menuOpen
418
- }) : menuHeader : /*#__PURE__*/jsx(UserCard, _extends({
419
- menuOpen: menuOpen
420
- }, Object.assign({}, userInfo)))
421
- })
422
- }), /*#__PURE__*/jsx(ErrorBoundary, {
423
- children: /*#__PURE__*/jsx(Menu, _extends({
424
- className: classnames('menu-list', style$3['menu-list']),
425
- menuOpen: menuOpen
426
- }, menu, {
427
- onChange: () => {
428
- deviceIsMobile && setMenuOpen(false);
429
- }
430
- }))
431
- }), _aiDialog && /*#__PURE__*/jsx("div", {
432
- className: classnames('ai-entry', style$3['ai-entry']),
433
- onClick: () => {
434
- setAiType('small');
435
- },
436
- children: /*#__PURE__*/jsx(Icon, {
437
- type: "system-prompt",
438
- colorful: true
439
- })
440
- })]
441
- })]
442
- }), /*#__PURE__*/jsx(Flex, {
443
- flex: 1,
444
- className: classnames('page', style$3['page']),
445
- children: /*#__PURE__*/jsxs(Row, {
446
- className: classnames('page-content', style$3['page-content']),
447
- children: [!deviceIsMobile && _aiDialog && aiType === 'inner' && /*#__PURE__*/jsx(Col, {
448
- span: 8,
449
- className: classnames('page-dialog-outer', style$3['page-dialog-outer']),
450
- children: /*#__PURE__*/jsxs("div", {
451
- className: classnames('page-dialog', style$3['page-dialog']),
452
- children: [/*#__PURE__*/jsxs(Flex, {
453
- className: classnames('ai-dialog-window-title', style$3['ai-dialog-window-title']),
454
- children: [/*#__PURE__*/jsx("div", {
455
- children: _aiDialog.title
456
- }), /*#__PURE__*/jsx(Flex, {
457
- gap: 10,
458
- children: /*#__PURE__*/jsx(Icon, {
459
- className: "btn",
460
- type: "icon-a-Typeclose",
461
- fontClassName: "system",
462
- onClick: () => {
463
- setAiType('closed');
464
- }
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
465
794
  })
466
795
  })]
467
- }), /*#__PURE__*/jsx(ErrorBoundary, {
468
- children: /*#__PURE__*/jsx("div", {
469
- className: classnames('page-window-content', style$3['page-window-content']),
470
- 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
471
813
  })
472
- })]
473
- })
474
- }), /*#__PURE__*/jsx(Col, {
475
- span: !deviceIsMobile && _aiDialog && aiType === 'inner' ? 16 : 24,
476
- children: /*#__PURE__*/jsx(ErrorBoundary, {
477
- children: openScrollbar ? /*#__PURE__*/jsx(SimpleBar, {
478
- className: classnames('page-children', style$3['page-children'], {
479
- ['has-left']: aiType === 'inner'
480
- }),
481
- children: children
482
- }) : /*#__PURE__*/jsx("div", {
483
- className: classnames('page-children', 'is-scroller', style$3['page-children'], style$3['is-scroller'], {
484
- ['has-left']: aiType === 'inner'
485
- }),
486
- children: children
487
814
  })
488
- })
489
- })]
490
- })
491
- }), _aiDialog && aiType === 'small' && /*#__PURE__*/jsxs("div", {
492
- className: classnames('ai-dialog-window', style$3['ai-dialog-window']),
493
- children: [/*#__PURE__*/jsxs(Flex, {
494
- className: classnames('ai-dialog-window-title', style$3['ai-dialog-window-title']),
495
- children: [/*#__PURE__*/jsx("div", {
496
- children: _aiDialog.title
497
- }), /*#__PURE__*/jsxs(Flex, {
498
- gap: 10,
499
- children: [/*#__PURE__*/jsx(Icon, {
500
- className: "btn",
501
- type: "icon-a-Typeopen_in_full",
502
- fontClassName: "system",
503
- onClick: () => {
504
- setAiType('inner');
505
- }
506
- }), /*#__PURE__*/jsx(Icon, {
507
- className: "btn",
508
- type: "icon-a-Typeclose",
509
- fontClassName: "system",
510
- onClick: () => {
511
- setAiType('closed');
512
- }
513
815
  })]
514
- })]
515
- }), /*#__PURE__*/jsx(ErrorBoundary, {
516
- children: /*#__PURE__*/jsx("div", {
517
- className: classnames('ai-dialog-window-content', style$3['ai-dialog-window-content']),
518
- children: _aiDialog.content
519
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
+ })]
520
847
  })]
521
- })]
522
- }), /*#__PURE__*/jsx(Toolbar, _extends({}, menu, {
523
- className: classnames(style$3['toolbar']),
524
- show: toolbarShow,
525
- target: toolbarTarget
526
- }))]
527
- })]
848
+ }), /*#__PURE__*/jsx(Toolbar, _extends({}, menu, {
849
+ className: classnames(style$3['toolbar']),
850
+ show: deviceIsMobile && toolbarShow,
851
+ target: toolbarTarget
852
+ }))]
853
+ })]
854
+ })
528
855
  });
529
856
  };
530
857
 
531
- var style = {"page":"_c1kXt","page-header":"_h-YXH","page-title":"_IOVGr","page-title-extra":"_mKsLu","page-inner":"_wHWje","is-mobile":"_yRZMx","back-icon":"_07Mna"};
858
+ var style = {"page":"kne-system-layout_c1kXt","page-header":"kne-system-layout_h-YXH","is-scrolled":"kne-system-layout_dEXMy","page-title-outer":"kne-system-layout_jhcGo","capsule-click":"kne-system-layout_Ps1FA","page-title-extra":"kne-system-layout_mKsLu","page-title":"kne-system-layout_IOVGr","page-top":"kne-system-layout_Y1y7o","page-inner":"kne-system-layout_wHWje","no-padding":"kne-system-layout_tBnAD","is-mobile":"kne-system-layout_yRZMx","page-loading":"kne-system-layout_vcf3J","page-bottom":"kne-system-layout_vXk1s","back-icon":"kne-system-layout_07Mna"};
532
859
 
860
+ const PageLoading = () => {
861
+ return /*#__PURE__*/jsx(Flex, {
862
+ flex: 1,
863
+ justify: "center",
864
+ children: /*#__PURE__*/jsx("div", {
865
+ className: style['page-loading'],
866
+ children: /*#__PURE__*/jsx(Skeleton, {
867
+ active: true
868
+ })
869
+ })
870
+ });
871
+ };
533
872
  const Page = ({
534
873
  title,
535
874
  extra: _extra = null,
536
875
  back,
537
876
  buttonProps,
538
877
  children,
539
- toolbar: _toolbar = true
878
+ toolbar: _toolbar = true,
879
+ navbar: _navbar = true,
880
+ noPadding
540
881
  }) => {
541
882
  const {
542
883
  setToolbarShow,
884
+ setNavbarShow,
543
885
  setMenuOpen,
544
886
  deviceIsMobile,
545
- userAvatar
887
+ userAvatar,
888
+ scrollReady
546
889
  } = useContext();
890
+ const navigate = useNavigate();
891
+ const getScrollElement = useScrollElement();
892
+ const navbarRef = useRef(null);
893
+ const [isScrolled, setIsScrolled] = useState(false);
547
894
  useEffect(() => {
548
895
  setToolbarShow && setToolbarShow(!!_toolbar);
549
- }, [_toolbar]);
550
- return /*#__PURE__*/jsxs(Flex, {
551
- vertical: true,
552
- gap: 24,
553
- className: classnames('page', style['page'], {
554
- ['is-mobile']: deviceIsMobile,
555
- [style['is-mobile']]: deviceIsMobile
896
+ setNavbarShow && setNavbarShow(!!_navbar);
897
+ }, [_toolbar, _navbar]);
898
+ useEffect(() => {
899
+ if (!deviceIsMobile || !_navbar) {
900
+ return;
901
+ }
902
+ const scrollEl = getScrollElement();
903
+ if (!scrollEl || typeof scrollEl.addEventListener !== 'function') {
904
+ return;
905
+ }
906
+ const handleScroll = () => {
907
+ const threshold = navbarRef.current ? navbarRef.current.offsetHeight : 48;
908
+ setIsScrolled(scrollEl.scrollTop > threshold);
909
+ };
910
+ handleScroll();
911
+ scrollEl.addEventListener('scroll', handleScroll, {
912
+ passive: true
913
+ });
914
+ return () => scrollEl.removeEventListener('scroll', handleScroll);
915
+ }, [deviceIsMobile, _navbar, getScrollElement, scrollReady]);
916
+ const navbarEl = _navbar ? /*#__PURE__*/jsxs(Flex, {
917
+ ref: navbarRef,
918
+ justify: "space-between",
919
+ align: "center",
920
+ gap: 20,
921
+ className: classnames('page-header', style['page-header'], {
922
+ ['is-scrolled']: isScrolled,
923
+ [style['is-scrolled']]: isScrolled
556
924
  }),
557
925
  children: [/*#__PURE__*/jsxs(Flex, {
558
- justify: "space-between",
926
+ className: classnames('page-title-outer', style['page-title-outer']),
559
927
  align: "center",
560
- gap: 20,
561
- className: classnames('page-header', style['page-header']),
562
- children: [/*#__PURE__*/jsxs(Flex, {
563
- className: classnames('page-title-outer', style['page-title-outer']),
564
- align: "center",
565
- gap: 4,
566
- children: [back && /*#__PURE__*/jsx(Button, {
567
- type: "text",
568
- icon: /*#__PURE__*/jsx(Icon, {
569
- className: style['back-icon'],
570
- type: "a-Typearrow_forward_ios",
571
- fontClassName: "system"
572
- })
573
- }), !back && deviceIsMobile && /*#__PURE__*/jsx(Button, {
574
- type: "link",
575
- icon: /*#__PURE__*/jsx(Icon, {
576
- className: style['back-icon'],
577
- type: "a-Typeequal",
578
- fontClassName: "system"
579
- }),
580
- onClick: () => {
581
- setMenuOpen(open => !open);
582
- }
583
- }), /*#__PURE__*/jsx("div", {
584
- className: classnames('page-title', style['page-title']),
585
- children: title
586
- })]
928
+ gap: 4,
929
+ children: [back && /*#__PURE__*/jsx(Button, {
930
+ type: "text",
931
+ icon: /*#__PURE__*/jsx(Icon, {
932
+ className: style['back-icon'],
933
+ type: "a-Typearrow_forward_ios",
934
+ fontClassName: "system"
935
+ }),
936
+ onClick: () => {
937
+ navigate(-1);
938
+ }
939
+ }), !back && deviceIsMobile && /*#__PURE__*/jsx(Button, {
940
+ type: "link",
941
+ icon: /*#__PURE__*/jsx(Icon, {
942
+ className: style['back-icon'],
943
+ type: "a-Typeequal",
944
+ fontClassName: "system"
945
+ }),
946
+ onClick: () => {
947
+ setMenuOpen(open => !open);
948
+ }
587
949
  }), /*#__PURE__*/jsx("div", {
588
- className: classnames('page-title-extra', style['page-title-extra']),
589
- children: _extra ? _extra : deviceIsMobile ? /*#__PURE__*/jsxs(Flex, {
590
- gap: 4,
591
- align: "center",
592
- children: [buttonProps && /*#__PURE__*/jsx(ButtonGroup, _extends({}, Object.assign({}, buttonProps, deviceIsMobile ? {
593
- showLength: 0,
594
- moreType: 'link'
595
- } : {}))), /*#__PURE__*/jsx(Image.Avatar, {
596
- id: userAvatar,
597
- src: userAvatar,
598
- shape: "circle",
599
- size: 30,
600
- alt: "avatar"
601
- })]
602
- }) : buttonProps && /*#__PURE__*/jsx(ButtonGroup, _extends({}, buttonProps))
950
+ className: classnames('page-title', style['page-title']),
951
+ children: title
603
952
  })]
604
953
  }), /*#__PURE__*/jsx("div", {
605
- className: classnames('page-inner', style['page-inner']),
606
- children: children
954
+ className: classnames('page-title-extra', style['page-title-extra']),
955
+ children: _extra ? _extra : deviceIsMobile ? /*#__PURE__*/jsxs(Flex, {
956
+ gap: 4,
957
+ align: "center",
958
+ children: [buttonProps && /*#__PURE__*/jsx(ButtonGroup, _extends({}, Object.assign({}, buttonProps, deviceIsMobile ? {
959
+ showLength: 0,
960
+ moreType: 'link'
961
+ } : {}))), /*#__PURE__*/jsx(Image.Avatar, {
962
+ id: userAvatar,
963
+ src: userAvatar,
964
+ shape: "circle",
965
+ size: 30,
966
+ alt: "avatar"
967
+ })]
968
+ }) : buttonProps && /*#__PURE__*/jsx(ButtonGroup, _extends({}, buttonProps))
607
969
  })]
970
+ }) : null;
971
+ const pageInnerClassNameOrigin = classnames('page-inner', style['page-inner']);
972
+ const pageInnerClassName = classnames(pageInnerClassNameOrigin, {
973
+ ['no-padding']: noPadding,
974
+ [style['no-padding']]: noPadding
608
975
  });
976
+ const render = ({
977
+ children,
978
+ className
979
+ }) => {
980
+ return /*#__PURE__*/jsxs(Fragment, {
981
+ children: [/*#__PURE__*/jsx("div", {
982
+ className: style['page-top']
983
+ }), /*#__PURE__*/jsxs(Flex, {
984
+ vertical: true,
985
+ flex: 1,
986
+ children: [navbarEl, /*#__PURE__*/jsx(Flex, {
987
+ vertical: true,
988
+ flex: 1,
989
+ className: classnames(pageInnerClassNameOrigin, className),
990
+ children: children
991
+ })]
992
+ }), /*#__PURE__*/jsx("div", {
993
+ className: style['page-bottom']
994
+ })]
995
+ });
996
+ };
997
+ return /*#__PURE__*/jsx(Flex, {
998
+ vertical: true,
999
+ flex: 1,
1000
+ className: classnames('page', style['page'], {
1001
+ ['is-mobile']: deviceIsMobile,
1002
+ [style['is-mobile']]: deviceIsMobile
1003
+ }),
1004
+ children: typeof children === 'function' ? children({
1005
+ navbar: navbarEl,
1006
+ className: pageInnerClassName,
1007
+ render,
1008
+ pageLoading: render({
1009
+ children: /*#__PURE__*/jsx(PageLoading, {})
1010
+ })
1011
+ }) : render({
1012
+ children
1013
+ })
1014
+ });
1015
+ };
1016
+ Page.PageLoading = PageLoading;
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
+
1025
+ const transparentBgContainer = {
1026
+ colorBgContainer: 'transparent'
1027
+ };
1028
+ const transparentBgContainerComponents = ['Input', 'InputNumber', 'Card', 'Tree', 'Select', 'DatePicker'];
1029
+ const themeToken = {
1030
+ components: merge({}, transform(transparentBgContainerComponents, (result, component) => {
1031
+ result[component] = transparentBgContainer;
1032
+ }, {}))
609
1033
  };
610
1034
 
611
1035
  import('./index-0916fdba.js');
612
1036
 
613
- export { Layout, Page, Layout as default, isMobile, useContext as useLayoutContext };
1037
+ export { Layout, Page, Layout as default, isMobile, themeToken, useContext as useLayoutContext };
614
1038
  //# sourceMappingURL=index.modern.js.map