@robert-stackflow/oneui 0.4.0 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.4.2 — 2026-10-29
4
+
5
+ - 图标、Emoji 和符号目录改用可被构建工具识别的异步 JSON 导入,修复 npm 包在 Vite 开发预打包后资源相对路径失效的问题;生产构建继续按需加载。
6
+ - Card 新增 `description` 与无正文模式,标题和正文使用一致的横向间距,避免只含概览和操作时产生空白正文。
7
+ - 独立 tarball 消费测试增加开发模式预打包下的三套完整目录加载验证。
8
+
9
+ ## 0.4.1 — 2026-10-29
10
+
11
+ - Dialog、Drawer 统一处理普通关闭和条件卸载后的焦点恢复,兼容 StrictMode、嵌套与替换弹窗,不抢夺其他弹窗的焦点。
12
+ - 新增 `returnFocus` 引用,可为异步打开的弹窗明确指定关闭后返回的控件。
13
+ - 修复 FormField 在卸载失焦时访问已清空引用的运行错误,避免 StrictMode 模拟清理触发额外失焦。
14
+ - Pagination 新增 `compact`、`size="small"` 和 `className`;紧凑排列、尺寸及窄屏换行由组件管理,宿主不再依赖内部 DOM 覆盖样式。
15
+ - 增加独立构建包的双主题、深浅色、1280/390/320px 焦点和分页交互验证。
16
+
3
17
  ## 0.4.0 — 2026-10-29
4
18
 
5
19
  - 新增 AccountItem、PasskeyItem、SessionItem,统一账户设备列表的图标、元数据、操作按钮和移动布局;业务与日期格式由宿主负责。
package/README.md CHANGED
@@ -57,6 +57,21 @@ export function App() {
57
57
 
58
58
  以上 API 从 0.2.0 起提供。
59
59
 
60
+ ## 概览卡片与内置目录(0.4.2)
61
+
62
+ `Card` 可通过 `title`、`description`、`action` 组合概览与操作;省略 `children` 时不会渲染空白正文。图标选择器不传 `options` 即使用库内置的完整目录;`valuePrefix="lucide:"` 可保留宿主保存值的前缀。图标、Emoji 和符号资源均由组件库按需加载,支持 Vite 的开发预打包与生产构建,宿主无需维护另一套选项或资源加载器。
63
+
64
+ ## 弹窗焦点与分页(0.4.1)
65
+
66
+ `Dialog` 和 `Drawer` 在普通关闭、条件卸载时都会恢复触发控件的焦点,支持 StrictMode 和嵌套弹窗。异步打开导致触发按钮在加载期间失焦时,可传入 `returnFocus={triggerRef}` 明确返回位置;已卸载、禁用或位于其他模态层之外的目标不会被聚焦。
67
+
68
+ `Pagination` 的 `total` 是总条数,`pageSize` 是每页条数。`compact` 移除外层留白并在窄屏重排页码、统计和跳转,`size="small"` 使用当前主题的小尺寸控件;正常和紧凑模式均支持长页码列表换行。宿主可通过 `className` 调整外层位置。
69
+
70
+ ```tsx
71
+ <Pagination compact size="small" page={page} pageSize={10}
72
+ total={records.total} onPageChange={setPage} />
73
+ ```
74
+
60
75
  ## 层级选择、补全与标签
61
76
 
62
77
  - `TreeSelect variant="category"` 在原有树选择交互上增加图标底块、子项数量与层级连线;默认 `variant="tree"` 保留简洁样式。两种样式均支持搜索、父子联动、多选、禁用、异步加载及键盘操作。`HierarchyOption.count` 可单独提供数量。
@@ -1,8 +1,9 @@
1
1
  import type { ReactNode } from "react";
2
- export declare function Card({ title, action, children, className, onClick, }: {
2
+ export declare function Card({ title, description, action, children, className, onClick, }: {
3
3
  title?: string;
4
+ description?: ReactNode;
4
5
  action?: ReactNode;
5
- children: ReactNode;
6
+ children?: ReactNode;
6
7
  className?: string;
7
8
  onClick?(): void;
8
9
  }): import("react").JSX.Element;
@@ -2,27 +2,33 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import s from "./Card.module.css";
3
3
  function Card({
4
4
  title,
5
+ description,
5
6
  action,
6
7
  children,
7
8
  className = "",
8
9
  onClick
9
10
  }) {
11
+ const hasBody = children != null && children !== false;
12
+ const classes = `${s.card} ${!hasBody ? s.headerOnly : ""} ${className}`;
10
13
  const content = /* @__PURE__ */ jsxs(Fragment, { children: [
11
- (title || action) && /* @__PURE__ */ jsxs("header", { className: s.header, children: [
12
- /* @__PURE__ */ jsx("h2", { children: title }),
14
+ (title || description || action) && /* @__PURE__ */ jsxs("header", { className: s.header, children: [
15
+ /* @__PURE__ */ jsxs("div", { className: s.heading, children: [
16
+ title && /* @__PURE__ */ jsx("h2", { children: title }),
17
+ description && /* @__PURE__ */ jsx("div", { className: s.description, children: description })
18
+ ] }),
13
19
  action
14
20
  ] }),
15
- /* @__PURE__ */ jsx("div", { className: s.body, "data-card-body": true, children })
21
+ hasBody && /* @__PURE__ */ jsx("div", { className: s.body, "data-card-body": true, children })
16
22
  ] });
17
23
  return onClick ? /* @__PURE__ */ jsx(
18
24
  "button",
19
25
  {
20
26
  type: "button",
21
- className: `${s.card} ${s.interactive} ${className}`,
27
+ className: `${classes} ${s.interactive}`,
22
28
  onClick,
23
29
  children: content
24
30
  }
25
- ) : /* @__PURE__ */ jsx("section", { className: s.card + " " + className, children: content });
31
+ ) : /* @__PURE__ */ jsx("section", { className: classes, children: content });
26
32
  }
27
33
  export {
28
34
  Card
@@ -29,7 +29,24 @@
29
29
  align-items: center;
30
30
  justify-content: space-between;
31
31
  gap: 12px;
32
- padding: 20px 24px 0;
32
+ flex-wrap: wrap;
33
+ padding: 20px var(--card-space) 0;
34
+ }
35
+ .heading {
36
+ flex: 1;
37
+ min-width: 0;
38
+ }
39
+ .heading h2 {
40
+ color: var(--fg);
41
+ }
42
+ .description {
43
+ margin-top: 6px;
44
+ color: var(--muted);
45
+ font-size: 13px;
46
+ line-height: 1.65;
47
+ }
48
+ .headerOnly .header {
49
+ padding-bottom: var(--card-space);
33
50
  }
34
51
  .body {
35
52
  padding: var(--card-space);
@@ -44,4 +61,7 @@
44
61
  .body {
45
62
  padding: 18px;
46
63
  }
64
+ .headerOnly .header {
65
+ padding-bottom: 18px;
66
+ }
47
67
  }
@@ -1,5 +1,5 @@
1
- import { type ReactNode } from "react";
2
- export declare function Dialog({ open: requestedOpen, onClose, title, children, footer, wide, size, role, descriptionId, busy, variant, }: {
1
+ import { type ReactNode, type RefObject } from "react";
2
+ export declare function Dialog({ open: requestedOpen, onClose, title, children, footer, wide, size, role, descriptionId, busy, variant, returnFocus, }: {
3
3
  open: boolean;
4
4
  onClose(): void;
5
5
  title: string;
@@ -11,4 +11,6 @@ export declare function Dialog({ open: requestedOpen, onClose, title, children,
11
11
  descriptionId?: string;
12
12
  busy?: boolean;
13
13
  variant?: "default" | "message" | "confirm" | "form";
14
+ /** Trigger to focus after closing, including surfaces opened asynchronously. */
15
+ returnFocus?: RefObject<HTMLElement | null>;
14
16
  }): import("react").ReactPortal;
@@ -13,6 +13,7 @@ import { surfaceMotion, cancelMotion } from "./motion.js";
13
13
  import s from "./Dialog.module.css";
14
14
  import { FieldContext } from "./field.js";
15
15
  import { useModalScrollLock } from "./useModalScrollLock.js";
16
+ import { useModalFocus } from "./useModalFocus.js";
16
17
  import {
17
18
  SurfacePortalContext,
18
19
  useSurfaceHost,
@@ -29,12 +30,13 @@ function Dialog({
29
30
  role = "dialog",
30
31
  descriptionId,
31
32
  busy = false,
32
- variant = "default"
33
+ variant = "default",
34
+ returnFocus
33
35
  }) {
34
36
  const owner = useSurfacePortal(), open = requestedOpen && owner?.active !== false;
35
37
  const { ref, host, setRef } = useSurfaceHost();
36
38
  const titleId = useId();
37
- const previousFocus = useRef(null);
39
+ const { rememberFocus, restoreFocus } = useModalFocus(ref, returnFocus);
38
40
  const [closing, setClosing] = useState(false);
39
41
  useModalScrollLock(open || closing);
40
42
  const opened = useRef(open);
@@ -55,7 +57,7 @@ function Dialog({
55
57
  element.inert = false;
56
58
  setClosing(false);
57
59
  if (!element.open) {
58
- previousFocus.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
60
+ rememberFocus();
59
61
  element.showModal();
60
62
  element.querySelector(
61
63
  "[data-dialog-initial-focus]:not(:disabled)"
@@ -74,14 +76,10 @@ function Dialog({
74
76
  void surfaceMotion(element, "exit", "0 4px").then((done) => {
75
77
  if (!done || opened.current) return;
76
78
  element.close();
77
- const modal = [
78
- ...document.querySelectorAll("dialog:modal")
79
- ].at(-1);
80
- if (previousFocus.current?.isConnected && (!modal || modal.contains(previousFocus.current)))
81
- previousFocus.current.focus({ preventScroll: true });
79
+ restoreFocus();
82
80
  setClosing(false);
83
81
  });
84
- }, [open]);
82
+ }, [open, rememberFocus, restoreFocus]);
85
83
  const backdropDown = useRef(false);
86
84
  const outside = (event) => {
87
85
  const rect = event.currentTarget.getBoundingClientRect();
@@ -13,6 +13,7 @@ export type DrawerProps = {
13
13
  closeOnEscape?: boolean;
14
14
  closeOnBackdrop?: boolean;
15
15
  initialFocus?: RefObject<HTMLElement | null>;
16
+ returnFocus?: RefObject<HTMLElement | null>;
16
17
  className?: string;
17
18
  };
18
- export declare function Drawer({ open: requestedOpen, onClose, title, description, children, footer, placement, size, closable, closeOnEscape, closeOnBackdrop, initialFocus, className, }: DrawerProps): import("react").ReactPortal;
19
+ export declare function Drawer({ open: requestedOpen, onClose, title, description, children, footer, placement, size, closable, closeOnEscape, closeOnBackdrop, initialFocus, returnFocus, className, }: DrawerProps): import("react").ReactPortal;
@@ -11,6 +11,7 @@ import { X } from "lucide-react";
11
11
  import { IconButton } from "./IconButton.js";
12
12
  import { FieldContext } from "./field.js";
13
13
  import { useModalScrollLock } from "./useModalScrollLock.js";
14
+ import { useModalFocus } from "./useModalFocus.js";
14
15
  import { cancelMotion, surfaceMotion } from "./motion.js";
15
16
  import s from "./Drawer.module.css";
16
17
  import {
@@ -37,11 +38,13 @@ function Drawer({
37
38
  closeOnEscape = true,
38
39
  closeOnBackdrop = true,
39
40
  initialFocus,
41
+ returnFocus,
40
42
  className = ""
41
43
  }) {
42
44
  const owner = useSurfacePortal(), open = requestedOpen && owner?.active !== false;
43
45
  const { ref, host, setRef } = useSurfaceHost();
44
- const previousFocus = useRef(null), opened = useRef(open), backdropDown = useRef(false), titleId = useId(), descriptionId = useId();
46
+ const { rememberFocus, restoreFocus } = useModalFocus(ref, returnFocus);
47
+ const opened = useRef(open), backdropDown = useRef(false), titleId = useId(), descriptionId = useId();
45
48
  const [closing, setClosing] = useState(false);
46
49
  useModalScrollLock(open || closing);
47
50
  opened.current = open;
@@ -52,7 +55,6 @@ function Drawer({
52
55
  const node = ref.current;
53
56
  return () => {
54
57
  cancelMotion(node);
55
- if (node.open) node.close();
56
58
  };
57
59
  }, []);
58
60
  useLayoutEffect(() => {
@@ -63,7 +65,7 @@ function Drawer({
63
65
  const justOpened = !node.open;
64
66
  const body = node.querySelector("[data-drawer-body]");
65
67
  if (justOpened) {
66
- previousFocus.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
68
+ rememberFocus();
67
69
  node.showModal();
68
70
  if (body) body.scrollTop = 0;
69
71
  }
@@ -83,15 +85,10 @@ function Drawer({
83
85
  void surfaceMotion(node, "exit", offsets[placement]).then((done) => {
84
86
  if (!done || opened.current) return;
85
87
  node.close();
86
- const focus = previousFocus.current;
87
- const modal = [
88
- ...document.querySelectorAll("dialog:modal")
89
- ].at(-1);
90
- if (focus?.isConnected && (!modal || modal.contains(focus)))
91
- focus.focus({ preventScroll: true });
88
+ restoreFocus();
92
89
  setClosing(false);
93
90
  });
94
- }, [open, placement, initialFocus]);
91
+ }, [open, placement, initialFocus, rememberFocus, restoreFocus]);
95
92
  const outside = (event) => {
96
93
  const rect = event.currentTarget.getBoundingClientRect();
97
94
  return event.target === event.currentTarget && (event.clientX < rect.left || event.clientX > rect.right || event.clientY < rect.top || event.clientY > rect.bottom);
@@ -2,7 +2,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import { useUIConfig } from "./UIProvider.js";
3
3
  import { FieldMessages } from "./FieldMessages.js";
4
4
  import { Spinner } from "./Spinner.js";
5
- import { useContext, useRef } from "react";
5
+ import { useContext } from "react";
6
6
  import { FieldContext, useFieldControl } from "./field.js";
7
7
  import { FieldLabel } from "./FieldLabel.js";
8
8
  import s from "./FormField.module.css";
@@ -18,7 +18,7 @@ function FormField({
18
18
  ...options
19
19
  }) {
20
20
  const config = useUIConfig(), inherited = useContext(FormLayoutContext);
21
- const field = useFieldControl(options), root = useRef(null);
21
+ const field = useFieldControl(options);
22
22
  const showLabel = !!field.label || pending, layout = showLabel ? suppliedLayout ?? inherited.layout ?? "stacked" : "stacked", labelWidth = suppliedLabelWidth ?? inherited.labelWidth;
23
23
  const label = showLabel ? /* @__PURE__ */ jsxs("div", { className: s.labelRow, children: [
24
24
  field.label && /* @__PURE__ */ jsx(
@@ -37,7 +37,6 @@ function FormField({
37
37
  return /* @__PURE__ */ jsx(FieldContext, { value: field, children: /* @__PURE__ */ jsx(
38
38
  "div",
39
39
  {
40
- ref: root,
41
40
  className: s.field,
42
41
  "data-invalid": !!field.error,
43
42
  "data-disabled": field.disabled || void 0,
@@ -46,7 +45,8 @@ function FormField({
46
45
  "--field-label-width": typeof labelWidth === "number" ? labelWidth + "px" : labelWidth
47
46
  },
48
47
  onBlur: (event) => {
49
- const next = event.relatedTarget, node = root.current;
48
+ const next = event.relatedTarget, node = event.currentTarget;
49
+ if (!node.isConnected) return;
50
50
  if (next && node.contains(next)) return;
51
51
  const portals = [...node.querySelectorAll("[aria-controls]")].map(
52
52
  (control) => document.getElementById(
@@ -1,5 +1,5 @@
1
1
  import { type ReactNode } from "react";
2
- export declare function Pagination({ page, pageSize, total, onPageChange, onPageSizeChange, pageSizes, summary, resetPageOnSizeChange, }: {
2
+ export declare function Pagination({ page, pageSize, total, onPageChange, onPageSizeChange, pageSizes, summary, resetPageOnSizeChange, compact, size: controlSize, className, }: {
3
3
  page: number;
4
4
  pageSize: number;
5
5
  total: number;
@@ -8,4 +8,8 @@ export declare function Pagination({ page, pageSize, total, onPageChange, onPage
8
8
  pageSizes?: number[];
9
9
  summary?: ReactNode;
10
10
  resetPageOnSizeChange?: boolean;
11
+ /** Removes outer spacing and groups controls for dialogs and dense toolbars. */
12
+ compact?: boolean;
13
+ size?: "default" | "small";
14
+ className?: string;
11
15
  }): import("react").JSX.Element;
@@ -18,7 +18,10 @@ function Pagination({
18
18
  onPageSizeChange,
19
19
  pageSizes = [5, 10, 20, 50],
20
20
  summary,
21
- resetPageOnSizeChange = true
21
+ resetPageOnSizeChange = true,
22
+ compact = false,
23
+ size: controlSize = "default",
24
+ className = ""
22
25
  }) {
23
26
  const size = Math.max(1, pageSize), pages = Math.max(1, Math.ceil(total / size)), current = Math.min(pages, Math.max(1, page)), id = useId(), [draft, setDraft] = useState(String(current));
24
27
  useEffect(() => setDraft(String(current)), [current]);
@@ -41,119 +44,126 @@ function Pagination({
41
44
  pages
42
45
  ])
43
46
  ].sort((a, b) => a - b);
44
- return /* @__PURE__ */ jsxs("nav", { className: s.pagination, "aria-label": "\u5206\u9875", children: [
45
- /* @__PURE__ */ jsxs("span", { className: s.summary, children: [
46
- total ? (current - 1) * size + 1 + "\u2013" + Math.min(current * size, total) : 0,
47
- " ",
48
- "/ ",
49
- total,
50
- " \u9879",
51
- summary
52
- ] }),
53
- /* @__PURE__ */ jsxs("div", { className: s.controls, children: [
54
- onPageSizeChange && /* @__PURE__ */ jsx(
55
- Select,
56
- {
57
- label: "\u6BCF\u9875\u6761\u6570",
58
- value: String(size),
59
- onChange: (v) => {
60
- onPageSizeChange(Number(v));
61
- if (resetPageOnSizeChange) onPageChange(1);
62
- },
63
- options: [.../* @__PURE__ */ new Set([...pageSizes, size])].sort((a, b) => a - b).map((n) => ({ value: String(n), label: n + " / \u9875" }))
64
- }
65
- ),
66
- /* @__PURE__ */ jsxs("div", { className: s.pages, children: [
67
- /* @__PURE__ */ jsx(
68
- Button,
69
- {
70
- className: s.arrow,
71
- "aria-label": "\u7B2C\u4E00\u9875",
72
- disabled: current === 1,
73
- onClick: () => onPageChange(1),
74
- children: /* @__PURE__ */ jsx(ChevronsLeft, {})
75
- }
76
- ),
77
- /* @__PURE__ */ jsx(
78
- Button,
79
- {
80
- className: s.arrow,
81
- "aria-label": "\u4E0A\u4E00\u9875",
82
- disabled: current === 1,
83
- onClick: () => onPageChange(current - 1),
84
- children: /* @__PURE__ */ jsx(ChevronLeft, {})
85
- }
86
- ),
87
- visible.map((n, i) => /* @__PURE__ */ jsxs("span", { className: s.number, children: [
88
- i > 0 && n - visible[i - 1] > 1 && /* @__PURE__ */ jsx("span", { className: s.ellipsis, children: "\u2026" }),
89
- /* @__PURE__ */ jsx(
90
- Button,
47
+ return /* @__PURE__ */ jsxs(
48
+ "nav",
49
+ {
50
+ className: `${s.pagination} ${compact ? s.compact : ""} ${controlSize === "small" ? s.small : ""} ${className}`,
51
+ "aria-label": "\u5206\u9875",
52
+ children: [
53
+ /* @__PURE__ */ jsxs("span", { className: s.summary, children: [
54
+ total ? (current - 1) * size + 1 + "\u2013" + Math.min(current * size, total) : 0,
55
+ " ",
56
+ "/ ",
57
+ total,
58
+ " \u9879",
59
+ summary
60
+ ] }),
61
+ /* @__PURE__ */ jsxs("div", { className: s.controls, children: [
62
+ onPageSizeChange && /* @__PURE__ */ jsx(
63
+ Select,
91
64
  {
92
- className: s.page,
93
- "aria-label": "\u7B2C " + n + " \u9875",
94
- "aria-current": n === current ? "page" : void 0,
95
- variant: n === current ? "primary" : "ghost",
96
- onClick: () => onPageChange(n),
97
- children: n
65
+ label: "\u6BCF\u9875\u6761\u6570",
66
+ value: String(size),
67
+ onChange: (v) => {
68
+ onPageSizeChange(Number(v));
69
+ if (resetPageOnSizeChange) onPageChange(1);
70
+ },
71
+ options: [.../* @__PURE__ */ new Set([...pageSizes, size])].sort((a, b) => a - b).map((n) => ({ value: String(n), label: n + " / \u9875" }))
98
72
  }
99
- )
100
- ] }, n)),
101
- /* @__PURE__ */ jsx(
102
- Button,
103
- {
104
- className: s.arrow,
105
- "aria-label": "\u4E0B\u4E00\u9875",
106
- disabled: current === pages,
107
- onClick: () => onPageChange(current + 1),
108
- children: /* @__PURE__ */ jsx(ChevronRight, {})
109
- }
110
- ),
111
- /* @__PURE__ */ jsx(
112
- Button,
113
- {
114
- className: s.arrow,
115
- "aria-label": "\u6700\u540E\u4E00\u9875",
116
- disabled: current === pages,
117
- onClick: () => onPageChange(pages),
118
- children: /* @__PURE__ */ jsx(ChevronsRight, {})
119
- }
120
- )
121
- ] }),
122
- /* @__PURE__ */ jsxs(
123
- "form",
124
- {
125
- className: s.jump,
126
- onSubmit: (e) => {
127
- e.preventDefault();
128
- jump();
129
- },
130
- children: [
131
- /* @__PURE__ */ jsx("label", { htmlFor: id, children: "\u8DF3\u81F3" }),
73
+ ),
74
+ /* @__PURE__ */ jsxs("div", { className: s.pages, children: [
132
75
  /* @__PURE__ */ jsx(
133
- "input",
76
+ Button,
134
77
  {
135
- id,
136
- className: control.surface,
137
- "aria-label": "\u8DF3\u8F6C\u9875\u7801",
138
- "aria-description": "\u8F93\u5165\u9875\u7801\u540E\u6309\u56DE\u8F66\u786E\u8BA4",
139
- inputMode: "numeric",
140
- value: draft,
141
- onChange: (e) => setDraft(e.target.value),
142
- onBlur: jump,
143
- onKeyDown: (e) => {
144
- if (e.key === "Escape") {
145
- e.preventDefault();
146
- setDraft(String(current));
147
- }
78
+ className: s.arrow,
79
+ "aria-label": "\u7B2C\u4E00\u9875",
80
+ disabled: current === 1,
81
+ onClick: () => onPageChange(1),
82
+ children: /* @__PURE__ */ jsx(ChevronsLeft, {})
83
+ }
84
+ ),
85
+ /* @__PURE__ */ jsx(
86
+ Button,
87
+ {
88
+ className: s.arrow,
89
+ "aria-label": "\u4E0A\u4E00\u9875",
90
+ disabled: current === 1,
91
+ onClick: () => onPageChange(current - 1),
92
+ children: /* @__PURE__ */ jsx(ChevronLeft, {})
93
+ }
94
+ ),
95
+ visible.map((n, i) => /* @__PURE__ */ jsxs("span", { className: s.number, children: [
96
+ i > 0 && n - visible[i - 1] > 1 && /* @__PURE__ */ jsx("span", { className: s.ellipsis, children: "\u2026" }),
97
+ /* @__PURE__ */ jsx(
98
+ Button,
99
+ {
100
+ className: s.page,
101
+ "aria-label": "\u7B2C " + n + " \u9875",
102
+ "aria-current": n === current ? "page" : void 0,
103
+ variant: n === current ? "primary" : "ghost",
104
+ onClick: () => onPageChange(n),
105
+ children: n
148
106
  }
107
+ )
108
+ ] }, n)),
109
+ /* @__PURE__ */ jsx(
110
+ Button,
111
+ {
112
+ className: s.arrow,
113
+ "aria-label": "\u4E0B\u4E00\u9875",
114
+ disabled: current === pages,
115
+ onClick: () => onPageChange(current + 1),
116
+ children: /* @__PURE__ */ jsx(ChevronRight, {})
149
117
  }
150
118
  ),
151
- /* @__PURE__ */ jsx("span", { children: "\u9875" })
152
- ]
153
- }
154
- )
155
- ] })
156
- ] });
119
+ /* @__PURE__ */ jsx(
120
+ Button,
121
+ {
122
+ className: s.arrow,
123
+ "aria-label": "\u6700\u540E\u4E00\u9875",
124
+ disabled: current === pages,
125
+ onClick: () => onPageChange(pages),
126
+ children: /* @__PURE__ */ jsx(ChevronsRight, {})
127
+ }
128
+ )
129
+ ] }),
130
+ /* @__PURE__ */ jsxs(
131
+ "form",
132
+ {
133
+ className: s.jump,
134
+ onSubmit: (e) => {
135
+ e.preventDefault();
136
+ jump();
137
+ },
138
+ children: [
139
+ /* @__PURE__ */ jsx("label", { htmlFor: id, children: "\u8DF3\u81F3" }),
140
+ /* @__PURE__ */ jsx(
141
+ "input",
142
+ {
143
+ id,
144
+ className: control.surface,
145
+ "aria-label": "\u8DF3\u8F6C\u9875\u7801",
146
+ "aria-description": "\u8F93\u5165\u9875\u7801\u540E\u6309\u56DE\u8F66\u786E\u8BA4",
147
+ inputMode: "numeric",
148
+ value: draft,
149
+ onChange: (e) => setDraft(e.target.value),
150
+ onBlur: jump,
151
+ onKeyDown: (e) => {
152
+ if (e.key === "Escape") {
153
+ e.preventDefault();
154
+ setDraft(String(current));
155
+ }
156
+ }
157
+ }
158
+ ),
159
+ /* @__PURE__ */ jsx("span", { children: "\u9875" })
160
+ ]
161
+ }
162
+ )
163
+ ] })
164
+ ]
165
+ }
166
+ );
157
167
  }
158
168
  export {
159
169
  Pagination
@@ -1,4 +1,6 @@
1
1
  .pagination {
2
+ min-width: 0;
3
+ max-width: 100%;
2
4
  display: flex;
3
5
  align-items: center;
4
6
  justify-content: space-between;
@@ -12,6 +14,8 @@
12
14
  font-size: 12px;
13
15
  }
14
16
  .controls {
17
+ min-width: 0;
18
+ max-width: 100%;
15
19
  display: flex;
16
20
  align-items: center;
17
21
  gap: 16px;
@@ -27,6 +31,16 @@
27
31
  gap: 4px;
28
32
  align-items: center;
29
33
  }
34
+ .pages {
35
+ flex-wrap: wrap;
36
+ }
37
+ .compact {
38
+ width: 100%;
39
+ padding: 0;
40
+ }
41
+ .small {
42
+ --control-height: var(--control-small);
43
+ }
30
44
  .pages .arrow,
31
45
  .pages .page {
32
46
  height: var(--control-height);
@@ -67,4 +81,29 @@
67
81
  .pages {
68
82
  gap: 2px;
69
83
  }
84
+ .compact {
85
+ display: grid;
86
+ grid-template-columns: minmax(0, 1fr) auto;
87
+ gap: 8px;
88
+ }
89
+ .compact .controls {
90
+ display: contents;
91
+ }
92
+ .compact .pages {
93
+ grid-column: 1 / -1;
94
+ grid-row: 1;
95
+ justify-content: center;
96
+ }
97
+ .compact .summary {
98
+ grid-column: 1;
99
+ grid-row: 2;
100
+ }
101
+ .compact .jump {
102
+ grid-column: 2;
103
+ grid-row: 2;
104
+ }
105
+ .compact .controls > [role="combobox"] {
106
+ grid-column: 1 / -1;
107
+ grid-row: 3;
108
+ }
70
109
  }
@@ -1,14 +1,9 @@
1
1
  import { useEffect, useState } from "react";
2
- const emojiUrl = new URL("../assets/emoji.json", import.meta.url).href;
3
- const symbolsUrl = new URL("../assets/symbols.json", import.meta.url).href;
4
2
  import metadata from "../assets/character-metadata.json";
5
3
  const cache = {}, pending = {};
6
4
  const labels = metadata.groups, aliases = metadata.aliases;
7
5
  function load(kind) {
8
- return pending[kind] ||= fetch(kind === "emoji" ? emojiUrl : symbolsUrl).then((r) => {
9
- if (!r.ok) throw Error("\u5B57\u7B26\u52A0\u8F7D\u5931\u8D25");
10
- return r.json();
11
- }).then((rows) => {
6
+ return pending[kind] ||= (kind === "emoji" ? import("../assets/emoji.json") : import("../assets/symbols.json")).then(({ default: rows }) => rows).then((rows) => {
12
7
  const groups = /* @__PURE__ */ new Map();
13
8
  for (const [glyph, title, group, detail] of rows) {
14
9
  if (!glyph.trim()) continue;
@@ -1,12 +1,8 @@
1
1
  import { useEffect, useState } from "react";
2
- const url = new URL("../assets/icon-catalog.json", import.meta.url).href;
3
2
  let cache;
4
3
  let pending;
5
4
  function loadCatalog() {
6
- return pending ||= fetch(url).then((r) => {
7
- if (!r.ok) throw Error("\u56FE\u6807\u52A0\u8F7D\u5931\u8D25");
8
- return r.json();
9
- }).then((data) => cache = data).catch((e) => {
5
+ return pending ||= import("../assets/icon-catalog.json").then(({ default: data }) => cache = data).catch((e) => {
10
6
  pending = void 0;
11
7
  throw e;
12
8
  });
@@ -0,0 +1,6 @@
1
+ import { type RefObject } from "react";
2
+ /** Shared lifecycle for animated closure and conditionally mounted surfaces. */
3
+ export declare function useModalFocus(ref: RefObject<HTMLDialogElement | null>, returnFocus?: RefObject<HTMLElement | null>): {
4
+ rememberFocus: () => void;
5
+ restoreFocus: () => void;
6
+ };
@@ -0,0 +1,35 @@
1
+ import { useCallback, useEffect, useRef } from "react";
2
+ function useModalFocus(ref, returnFocus) {
3
+ const previous = useRef(null);
4
+ const requested = useRef(returnFocus);
5
+ const mounted = useRef(false);
6
+ requested.current = returnFocus;
7
+ const rememberFocus = useCallback(() => {
8
+ const active = document.activeElement;
9
+ if (active instanceof HTMLElement && active !== document.body && !ref.current?.contains(active))
10
+ previous.current = active;
11
+ }, [ref]);
12
+ const restoreFocus = useCallback(() => {
13
+ const target = requested.current?.current || previous.current;
14
+ const modal = [...document.querySelectorAll("dialog:modal")].at(-1);
15
+ if (target?.isConnected && !target.matches(":disabled") && !target.closest("[inert]") && (!modal || modal.contains(target)))
16
+ target.focus({ preventScroll: true });
17
+ }, []);
18
+ useEffect(() => {
19
+ mounted.current = true;
20
+ const node = ref.current;
21
+ return () => {
22
+ mounted.current = false;
23
+ if (!node?.open) return;
24
+ requestAnimationFrame(() => {
25
+ if (mounted.current) return;
26
+ if (node.open) node.close();
27
+ restoreFocus();
28
+ });
29
+ };
30
+ }, [ref, restoreFocus]);
31
+ return { rememberFocus, restoreFocus };
32
+ }
33
+ export {
34
+ useModalFocus
35
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robert-stackflow/oneui",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "description": "OneUI React components, application shell and portable visual themes",
5
5
  "type": "module",
6
6
  "sideEffects": [