@sia.soul/sia-react-ui 0.1.114 → 0.1.116

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.
@@ -1675,12 +1675,13 @@ function MenuEntry({
1675
1675
  ...withTitleTooltip({ title: collapsed ? item.title ?? (typeof item.label === "string" ? item.label : void 0) : item.title }),
1676
1676
  disabled: item.disabled,
1677
1677
  "aria-current": isSelected ? "page" : void 0,
1678
+ "data-menu-key": item.key,
1678
1679
  "data-applied": item.applied || void 0,
1679
1680
  "aria-expanded": hasChildren ? isOpen : void 0,
1680
1681
  onClick: (event) => hasChildren ? props.toggle(item.key) : props.select(item, path, event),
1681
1682
  children: [
1682
1683
  reserveIcon ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "sia-menu__icon", style: item.iconSize ? { width: item.iconSize, height: item.iconSize, flexBasis: item.iconSize } : void 0, "aria-hidden": !item.icon || void 0, children: item.icon }) : null,
1683
- item.applied ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "sia-menu__applied", role: "img", "aria-label": item.appliedLabel ?? "\u5F53\u524D\u4F7F\u7528", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "circle-check", size: 32 }) }) : null,
1684
+ item.applied ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "sia-menu__applied", role: "img", "aria-label": item.appliedLabel ?? "\u5F53\u524D\u4F7F\u7528", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { name: "circle-check", variant: "filled", size: 32 }) }) : null,
1684
1685
  !collapsed ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "sia-menu__label", children: item.label }) : null,
1685
1686
  !collapsed && item.extra ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "sia-menu__extra", children: item.extra }) : null,
1686
1687
  !collapsed && hasChildren ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(Icon, { className: "sia-menu__expand-icon", name: "chevron-down", size: 13 }) : null
@@ -1726,8 +1727,10 @@ function MenuLevel({
1726
1727
  function Menu({
1727
1728
  items,
1728
1729
  mode = "vertical",
1730
+ gridColumns = 2,
1729
1731
  theme = "light",
1730
1732
  selectedKeys,
1733
+ autoScrollSelected = false,
1731
1734
  defaultSelectedKeys = [],
1732
1735
  openKeys,
1733
1736
  defaultOpenKeys = [],
@@ -1741,12 +1744,37 @@ function Menu({
1741
1744
  onDeselect,
1742
1745
  onOpenChange,
1743
1746
  className = "",
1747
+ style,
1744
1748
  ...rest
1745
1749
  }) {
1746
1750
  const menuId = (0, import_react6.useId)();
1747
1751
  const rootRef = (0, import_react6.useRef)(null);
1748
1752
  const [selected, setSelected] = useControllableState({ value: selectedKeys, defaultValue: defaultSelectedKeys });
1749
1753
  const [open, setOpen] = useControllableState({ value: openKeys, defaultValue: defaultOpenKeys, onChange: (next) => onOpenChange?.([...next]) });
1754
+ const revealedKey = (0, import_react6.useRef)();
1755
+ const firstSelected = selected[0];
1756
+ (0, import_react6.useLayoutEffect)(() => {
1757
+ if (!autoScrollSelected || firstSelected === void 0) {
1758
+ revealedKey.current = void 0;
1759
+ return;
1760
+ }
1761
+ const root = rootRef.current;
1762
+ if (!root || revealedKey.current === firstSelected || mode === "horizontal") return;
1763
+ const reveal = () => {
1764
+ if (revealedKey.current === firstSelected || root.clientHeight === 0) return;
1765
+ const target = Array.from(root.querySelectorAll(".sia-menu__item")).find((element) => element.dataset.menuKey === firstSelected && element.getBoundingClientRect().height > 0);
1766
+ if (!target) return;
1767
+ const bounds = root.getBoundingClientRect(), item = target.getBoundingClientRect();
1768
+ const top = bounds.top + root.clientTop, bottom = top + root.clientHeight;
1769
+ if (item.top < top || item.bottom > bottom)
1770
+ root.scrollTop += item.top - top - Math.max(0, (root.clientHeight - item.height) / 2);
1771
+ revealedKey.current = firstSelected;
1772
+ };
1773
+ reveal();
1774
+ const observer = new ResizeObserver(reveal);
1775
+ observer.observe(root);
1776
+ return () => observer.disconnect();
1777
+ }, [autoScrollSelected, firstSelected, items, mode]);
1750
1778
  (0, import_react6.useEffect)(() => {
1751
1779
  if (mode === "inline" || !open.length) return void 0;
1752
1780
  const closeOutside = (event) => {
@@ -1773,7 +1801,8 @@ function Menu({
1773
1801
  else onSelect?.({ ...info, selectedKeys: [...next] });
1774
1802
  if (mode !== "inline") setOpen([]);
1775
1803
  }
1776
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { ref: rootRef, className: `sia-menu sia-menu--${mode} sia-menu--${theme}${inlineCollapsed ? " sia-menu--collapsed" : ""} ${className}`.trim(), role: "menu", ...withTitleTooltip(rest), "data-sia-menu-owner": menuId, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MenuLevel, { items, level: 0, parents: [], props: { menuId, mode, theme, multiple, selectable, inlineCollapsed, inlineIndent, triggerSubMenuAction, selected, open, select, toggle } }) });
1804
+ const gridStyle = mode === "grid" ? { "--sia-menu-grid-columns": gridColumns === "auto" ? "repeat(auto-fill, minmax(88px, 1fr))" : `repeat(${Number.isFinite(gridColumns) ? Math.max(1, Math.floor(Number(gridColumns))) : 2}, minmax(0, 1fr))` } : {};
1805
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("ul", { ref: rootRef, className: `sia-menu sia-menu--${mode} sia-menu--${theme}${inlineCollapsed ? " sia-menu--collapsed" : ""} ${className}`.trim(), role: "menu", ...withTitleTooltip(rest), style: { ...gridStyle, ...style }, "data-sia-menu-owner": menuId, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MenuLevel, { items, level: 0, parents: [], props: { menuId, mode, theme, multiple, selectable, inlineCollapsed, inlineIndent, triggerSubMenuAction, selected, open, select, toggle } }) });
1777
1806
  }
1778
1807
 
1779
1808
  // src/components/Dropdown.tsx
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  RichTextContent,
3
3
  RichTextEditor
4
- } from "./chunk-6CII5JCT.js";
5
- import "./chunk-IOVN3QL7.js";
4
+ } from "./chunk-CVIFJLW6.js";
5
+ import "./chunk-SATXB6X4.js";
6
6
  import "./chunk-SCEHVGKV.js";
7
7
  import "./chunk-XY7CXJS6.js";
8
8
  import "./chunk-CZ2ITBRW.js";
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { InputHTMLAttributes, ReactNode, HTMLAttributes, CSSProperties } from 'react';
3
3
  import { I as InputPlaceholderMode, C as ControlSize, a as ControlStatus } from './shared-Bx4B28Wh.js';
4
- import { S as SelectOption, j as SelectValue } from './Select-BddM4uXC.js';
4
+ import { S as SelectOption, j as SelectValue } from './Select-vjX7B63I.js';
5
5
 
6
6
  /** 日期选择附带的时间选择配置。 */
7
7
  type DatePickerShowTime = boolean | {
@@ -1,7 +1,7 @@
1
1
  import * as react from 'react';
2
2
  import { InputHTMLAttributes, ReactNode, HTMLAttributes, CSSProperties } from 'react';
3
3
  import { I as InputPlaceholderMode, C as ControlSize, a as ControlStatus } from './shared-Bx4B28Wh.cjs';
4
- import { S as SelectOption, j as SelectValue } from './Select-Cf0xz1Tg.cjs';
4
+ import { S as SelectOption, j as SelectValue } from './Select-BAFXKVZB.cjs';
5
5
 
6
6
  /** 日期选择附带的时间选择配置。 */
7
7
  type DatePickerShowTime = boolean | {
@@ -4196,8 +4196,15 @@ var Select = (0, import_react18.forwardRef)(function Select2({
4196
4196
  function clearSelection() {
4197
4197
  setCurrentValue(multiple ? [] : null);
4198
4198
  }
4199
+ function handleDropdownEscape(event) {
4200
+ if (event.key !== "Escape" || !open || popupMode !== "dropdown") return false;
4201
+ event.preventDefault();
4202
+ event.stopPropagation();
4203
+ closeDropdown();
4204
+ return true;
4205
+ }
4199
4206
  function handleInteractionKeyDown(event, fromSearch = false) {
4200
- if (popupMode === "modal" && open) return;
4207
+ if (handleDropdownEscape(event) || popupMode === "modal" && open) return;
4201
4208
  if (event.key === "ArrowDown" || event.key === "ArrowUp") {
4202
4209
  event.preventDefault();
4203
4210
  if (!open) openDropdown();
@@ -4302,7 +4309,7 @@ var Select = (0, import_react18.forwardRef)(function Select2({
4302
4309
  }
4303
4310
  ),
4304
4311
  allowClear && hasValue && !disabled && !loading ? /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("button", { className: "sia-select__clear", type: "button", "aria-label": "\u6E05\u7A7A\u9009\u62E9", onClick: clearValue, children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Icon, { name: "circle-close", variant: "filled", size: 15 }) }) : null,
4305
- /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(PopupPortal, { ref: popupRef, anchorRef: rootRef, open: open && popupMode === "dropdown", style: { fontSize: dropdownFontSize }, className: `sia-select__dropdown${filteredOptions.length === 0 && !canSubmitInput ? " sia-select__dropdown--empty" : ""}`, children: [
4312
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(PopupPortal, { ref: popupRef, onKeyDown: handleDropdownEscape, anchorRef: rootRef, open: open && popupMode === "dropdown", style: { fontSize: dropdownFontSize }, className: `sia-select__dropdown${filteredOptions.length === 0 && !canSubmitInput ? " sia-select__dropdown--empty" : ""}`, children: [
4306
4313
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FloatingScrollbarProvider, { targetRef: listRef }),
4307
4314
  showSearch || allowInput ? /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)("label", { className: "sia-select__search", children: [
4308
4315
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Icon, { name: "search", size: 15 }),
@@ -1,5 +1,5 @@
1
- export { S as SelectDateRange, i as SelectDateRangeProps, j as SelectDateRangeValue } from './select-date-range-Cm5o2xPp.cjs';
1
+ export { S as SelectDateRange, i as SelectDateRangeProps, j as SelectDateRangeValue } from './select-date-range-CIiI0F5o.cjs';
2
2
  import 'react';
3
3
  import './shared-Bx4B28Wh.cjs';
4
- import './Select-Cf0xz1Tg.cjs';
4
+ import './Select-BAFXKVZB.cjs';
5
5
  import './Button-O_pNB3SQ.cjs';
@@ -1,5 +1,5 @@
1
- export { S as SelectDateRange, i as SelectDateRangeProps, j as SelectDateRangeValue } from './select-date-range-yGDEA1RP.js';
1
+ export { S as SelectDateRange, i as SelectDateRangeProps, j as SelectDateRangeValue } from './select-date-range-C9jlUrCX.js';
2
2
  import 'react';
3
3
  import './shared-Bx4B28Wh.js';
4
- import './Select-BddM4uXC.js';
4
+ import './Select-vjX7B63I.js';
5
5
  import './Button-BiL3Wjsd.js';
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  SelectDateRange
3
- } from "./chunk-NKENBSLP.js";
4
- import "./chunk-7KNHBJZX.js";
5
- import "./chunk-IOVN3QL7.js";
3
+ } from "./chunk-MKCU5S77.js";
4
+ import "./chunk-7PPE6DJO.js";
5
+ import "./chunk-SATXB6X4.js";
6
6
  import "./chunk-SCEHVGKV.js";
7
7
  import "./chunk-XY7CXJS6.js";
8
8
  import "./chunk-CZ2ITBRW.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sia.soul/sia-react-ui",
3
- "version": "0.1.114",
3
+ "version": "0.1.116",
4
4
  "description": "Sia Design components and tokens for React",
5
5
  "publishConfig": {
6
6
  "access": "public",