musae 0.2.25 → 0.2.26

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,4 @@
1
1
  import React from "react";
2
2
  import type { BenchProps } from "./types";
3
- declare const Bench: ({ children, title, logo, navigations, className, style, trailing, onNavigate, location, defaultExpandedKeys, classNames: { main: mainClassName }, elevation, }: BenchProps) => React.JSX.Element;
3
+ declare const Bench: ({ children, title, logo, navigations, className, style, trailing, onNavigate, location, defaultExpandedKeys, classNames: { main: mainClassName }, elevation, guidance, }: BenchProps) => React.JSX.Element;
4
4
  export default Bench;
@@ -91,13 +91,16 @@ var Bench = function Bench(_ref) {
91
91
  _ref$classNames2 = _ref$classNames === void 0 ? {} : _ref$classNames,
92
92
  mainClassName = _ref$classNames2.main,
93
93
  _ref$elevation = _ref.elevation,
94
- elevation = _ref$elevation === void 0 ? "xsmall" : _ref$elevation;
94
+ elevation = _ref$elevation === void 0 ? "xsmall" : _ref$elevation,
95
+ _ref$guidance = _ref.guidance,
96
+ guidance = _ref$guidance === void 0 ? "top-side" : _ref$guidance;
95
97
  var theme = useTheme();
96
98
  var _logo = useLogo(logo);
97
99
  var _useNavigations = useNavigations({
98
100
  navigations: navigations,
99
101
  onNavigate: onNavigate,
100
- location: location
102
+ location: location,
103
+ guidance: guidance
101
104
  }),
102
105
  navigate = _useNavigations.navigate,
103
106
  topMenuItems = _useNavigations.topMenuItems,
@@ -1,6 +1,6 @@
1
1
  import { type Key } from "react";
2
- import type { BenchProps, Logo, NavigationItem } from "./types";
3
- import { MenuItem } from "../menu";
2
+ import type { BenchProps, Guidance, Logo, NavigationItem } from "./types";
3
+ import type { MenuItem } from "../menu";
4
4
  /**
5
5
  * @description
6
6
  * logo
@@ -10,10 +10,11 @@ export declare const useLogo: (logo?: string | Logo) => Logo | null;
10
10
  * @description
11
11
  * menu
12
12
  */
13
- export declare const useNavigations: ({ navigations, onNavigate, location, }: {
13
+ export declare const useNavigations: ({ navigations, onNavigate, location, guidance, }: {
14
14
  navigations: NavigationItem[];
15
15
  onNavigate: BenchProps["onNavigate"];
16
16
  location?: string;
17
+ guidance: Guidance;
17
18
  }) => {
18
19
  selectedKeys: [(Key | undefined)?, (Key | undefined)?];
19
20
  topMenuItems: MenuItem[];
@@ -22,7 +22,7 @@ var useLogo = function useLogo(logo) {
22
22
  return logo;
23
23
  }, [logo]);
24
24
  };
25
- var _toMenuItem3 = function toMenuItem(_ref, parentKeys, paths) {
25
+ var _toMenuItem3 = function toMenuItem(_ref, parentKeys) {
26
26
  var path = _ref.path,
27
27
  children = _ref.children,
28
28
  item = _objectWithoutProperties(_ref, _excluded);
@@ -31,13 +31,13 @@ var _toMenuItem3 = function toMenuItem(_ref, parentKeys, paths) {
31
31
  var _ref3 = _slicedToArray(_ref2, 2),
32
32
  _menuItems = _ref3[0],
33
33
  _paths = _ref3[1];
34
- var _toMenuItem = _toMenuItem3(child, [].concat(_toConsumableArray(parentKeys), [path]), _paths),
34
+ var _toMenuItem = _toMenuItem3(child, [].concat(_toConsumableArray(parentKeys), [path])),
35
35
  _toMenuItem2 = _slicedToArray(_toMenuItem, 2),
36
36
  menuItem = _toMenuItem2[0],
37
37
  paths = _toMenuItem2[1];
38
38
  _menuItems.push(menuItem);
39
- return [_menuItems, paths];
40
- }, [[], new Map(paths.set(path, parentKeys))]),
39
+ return [_menuItems, new Map([].concat(_toConsumableArray(_paths), _toConsumableArray(paths)))];
40
+ }, [[], new Map([[path, parentKeys]])]),
41
41
  _reduce2 = _slicedToArray(_reduce, 2),
42
42
  _menuItems = _reduce2[0],
43
43
  _paths = _reduce2[1];
@@ -54,7 +54,8 @@ var _toMenuItem3 = function toMenuItem(_ref, parentKeys, paths) {
54
54
  var useNavigations = function useNavigations(_ref4) {
55
55
  var navigations = _ref4.navigations,
56
56
  onNavigate = _ref4.onNavigate,
57
- location = _ref4.location;
57
+ location = _ref4.location,
58
+ guidance = _ref4.guidance;
58
59
  // menu click handler => jump link
59
60
  var navigate = useEvent(function (path) {
60
61
  if (onNavigate) {
@@ -67,22 +68,29 @@ var useNavigations = function useNavigations(_ref4) {
67
68
  var _useMemo = useMemo(function () {
68
69
  return navigations.reduce(function (_ref5, item) {
69
70
  var _ref6 = _slicedToArray(_ref5, 3),
70
- topMenuItems = _ref6[0],
71
- sideNavigations = _ref6[1],
72
- paths = _ref6[2];
73
- var _toMenuItem4 = _toMenuItem3(item, [], paths),
71
+ _topNavigations = _ref6[0],
72
+ _sideNavigations = _ref6[1],
73
+ _paths = _ref6[2];
74
+ var _toMenuItem4 = _toMenuItem3(item, []),
74
75
  _toMenuItem5 = _slicedToArray(_toMenuItem4, 2),
75
76
  _toMenuItem5$ = _toMenuItem5[0],
76
77
  children = _toMenuItem5$.children,
77
78
  _menuItem = _objectWithoutProperties(_toMenuItem5$, _excluded2),
78
- _paths = _toMenuItem5[1];
79
- topMenuItems.set(item.path, _menuItem);
80
- sideNavigations.set(item.path, children);
81
- return [topMenuItems, sideNavigations, _paths];
79
+ ___paths = _toMenuItem5[1];
80
+ var __paths = new Map([].concat(_toConsumableArray(___paths), _toConsumableArray(_paths)));
81
+ if (guidance === "side") {
82
+ _sideNavigations.set(item.path, [_objectSpread(_objectSpread({}, _menuItem), {}, {
83
+ children: children
84
+ })]);
85
+ return [_topNavigations, _sideNavigations, __paths];
86
+ }
87
+ _topNavigations.set(item.path, _menuItem);
88
+ _sideNavigations.set(item.path, children);
89
+ return [_topNavigations, _sideNavigations, __paths];
82
90
  }, [new Map(), new Map(), new Map()]);
83
- }, [navigations]),
91
+ }, [guidance, navigations]),
84
92
  _useMemo2 = _slicedToArray(_useMemo, 3),
85
- topMenuItems = _useMemo2[0],
93
+ topNavigations = _useMemo2[0],
86
94
  sideNavigations = _useMemo2[1],
87
95
  paths = _useMemo2[2];
88
96
  // menu selected keys
@@ -91,18 +99,27 @@ var useNavigations = function useNavigations(_ref4) {
91
99
  if (isUndefined(location)) return [];
92
100
  return [(_paths$get$at = (_paths$get = paths.get(location)) === null || _paths$get === void 0 ? void 0 : _paths$get.at(0)) !== null && _paths$get$at !== void 0 ? _paths$get$at : location, location];
93
101
  }, [location, paths]);
102
+ // side menu
94
103
  var sideMenuItems = useMemo(function () {
95
104
  var _sideNavigations$get;
96
- if (!selectedKeys[0]) {
97
- return [];
105
+ // top menu items is empty, show all in side menu
106
+ if (topNavigations.size === 0) {
107
+ return Array.from(sideNavigations.values()).flatMap(function () {
108
+ var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
109
+ return items;
110
+ }, []);
98
111
  }
112
+ // top-side relation
113
+ if (!selectedKeys[0]) return [];
99
114
  return (_sideNavigations$get = sideNavigations.get(selectedKeys[0])) !== null && _sideNavigations$get !== void 0 ? _sideNavigations$get : [];
100
- }, [sideNavigations, selectedKeys]);
115
+ }, [selectedKeys, sideNavigations, topNavigations]);
116
+ // top menu items
117
+ var topMenuItems = useMemo(function () {
118
+ return Array.from(topNavigations.values());
119
+ }, [topNavigations]);
101
120
  return {
102
121
  selectedKeys: selectedKeys,
103
- topMenuItems: useMemo(function () {
104
- return Array.from(topMenuItems.values());
105
- }, [topMenuItems]),
122
+ topMenuItems: topMenuItems,
106
123
  sideMenuItems: sideMenuItems,
107
124
  navigate: navigate
108
125
  };
@@ -1,6 +1,7 @@
1
1
  import type { Key, ReactNode } from "react";
2
2
  import type { ComponentProps } from "../../types/element";
3
3
  import type { ElevationToken } from "../theme/tokens.stylex";
4
+ export type Guidance = "top-side" | "side";
4
5
  export type Logo = {
5
6
  /**
6
7
  * @description
@@ -81,4 +82,10 @@ export type BenchProps = ComponentProps & {
81
82
  * elevation
82
83
  */
83
84
  elevation?: ElevationToken;
85
+ /**
86
+ * @description
87
+ * guidance
88
+ * @default "top-side"
89
+ */
90
+ guidance?: Guidance;
84
91
  };
@@ -1,4 +1,3 @@
1
1
  import React from "react";
2
- import type { BodyProps } from "./types";
3
- declare const Body: <T>(props: BodyProps) => React.JSX.Element | null;
2
+ declare const Body: <T>() => React.JSX.Element | null;
4
3
  export default Body;
@@ -2,10 +2,11 @@ import React from 'react';
2
2
  import { useTable } from './context.js';
3
3
  import { flexRender } from '@tanstack/react-table';
4
4
  import { props } from '../../node_modules/.pnpm/@stylexjs_stylex@0.7.5/node_modules/@stylexjs/stylex/lib/es/stylex.js';
5
- import { clsx } from '@aiszlab/relax';
5
+ import { isEmpty, clsx } from '@aiszlab/relax';
6
6
  import { typography } from '../theme/theme.js';
7
7
  import { useTheme } from '../theme/hooks.js';
8
8
  import { ColorToken } from '../../utils/colors.js';
9
+ import Empty from '../empty/empty.js';
9
10
 
10
11
  var styles = {
11
12
  cell: function cell(props) {
@@ -62,7 +63,7 @@ var styles = {
62
63
  $$css: true
63
64
  }
64
65
  };
65
- var Body = function Body(props$1) {
66
+ var Body = function Body() {
66
67
  var _useTable = useTable(),
67
68
  table = _useTable.table,
68
69
  bordered = _useTable.bordered;
@@ -71,7 +72,9 @@ var Body = function Body(props$1) {
71
72
  var styled = props(bordered && styles.bordered, typography.body.small, styles.cell({
72
73
  borderColor: theme.colors[ColorToken.OutlineVariant]
73
74
  }));
74
- return /*#__PURE__*/React.createElement("tbody", null, table.getRowModel().rows.map(function (row) {
75
+ var rows = table.getRowModel().rows;
76
+ var _isEmpty = isEmpty(rows);
77
+ return /*#__PURE__*/React.createElement("tbody", null, _isEmpty && (/*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement(Empty, null)))), !_isEmpty && table.getRowModel().rows.map(function (row) {
75
78
  return /*#__PURE__*/React.createElement("tr", {
76
79
  key: row.id
77
80
  }, row.getVisibleCells().map(function (cell) {
@@ -1,2 +1,4 @@
1
1
  import Table from "./table";
2
+ import type { TableProps } from "./types";
2
3
  export { Table };
4
+ export type { TableProps };
@@ -106,11 +106,6 @@ export type ContextValue<T> = {
106
106
  * header props
107
107
  */
108
108
  export type HeaderProps = ComponentProps;
109
- /**
110
- * @description
111
- * body props
112
- */
113
- export type BodyProps = ComponentProps;
114
109
  /**
115
110
  * @description
116
111
  * header cell props
package/dist/index.d.ts CHANGED
@@ -77,3 +77,4 @@ export type { TreeProps } from "./components/tree";
77
77
  export type { TourStep } from "./components/tour";
78
78
  export type { NavigationItem } from "./components/bench";
79
79
  export type { Locale } from "./locale";
80
+ export type { TableProps } from "./components/table";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "musae",
3
- "version": "0.2.25",
3
+ "version": "0.2.26",
4
4
  "description": "musae-ui",
5
5
  "author": "tutu@fantufantu.com",
6
6
  "license": "MIT",
@@ -13,6 +13,7 @@
13
13
  "prepublishOnly": "rm -rf dist && npm run build",
14
14
  "preinstall": "npx @aiszlab/watchdog preinstall",
15
15
  "authors": "zx scripts/contributors.mjs",
16
+ "changesets": "z cs",
16
17
  "version": "z cs version"
17
18
  },
18
19
  "exports": {
@@ -71,7 +72,7 @@
71
72
  "pnpm": ">=9"
72
73
  },
73
74
  "dependencies": {
74
- "@aiszlab/relax": "^1.3.10",
75
+ "@aiszlab/relax": "^1.3.13",
75
76
  "@babel/runtime": "^7.25.6",
76
77
  "@dnd-kit/core": "^6.1.0",
77
78
  "@dnd-kit/modifiers": "^7.0.0",