@sia.soul/sia-react-ui 0.1.105 → 0.1.107

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.
Files changed (45) hide show
  1. package/dist/Button-BiL3Wjsd.d.ts +44 -0
  2. package/dist/Button-O_pNB3SQ.d.cts +44 -0
  3. package/dist/{Select-DmT9pFRW.d.ts → Select-BddM4uXC.d.ts} +4 -42
  4. package/dist/{Select-DQpfyK7I.d.cts → Select-Cf0xz1Tg.d.cts} +4 -42
  5. package/dist/chart.js +5 -3
  6. package/dist/chunk-4TTHKFJ7.js +706 -0
  7. package/dist/chunk-CZ2ITBRW.js +65 -0
  8. package/dist/{chunk-EYB55TC5.js → chunk-D3HXXEEZ.js} +9 -5
  9. package/dist/{chunk-X4OLHWC3.js → chunk-JEDJQ257.js} +11 -7
  10. package/dist/chunk-KY6A5IJH.js +18 -0
  11. package/dist/{chunk-NURPAO7G.js → chunk-MMSYWDTR.js} +9 -5
  12. package/dist/{chunk-PUZWLIIJ.js → chunk-NZMUW5XI.js} +1 -13
  13. package/dist/{chunk-D456SSL3.js → chunk-OJ2WDC66.js} +6 -4
  14. package/dist/{chunk-V6CRVCSB.js → chunk-QV3AP6A2.js} +40 -729
  15. package/dist/chunk-RX242MUO.js +0 -0
  16. package/dist/chunk-SCEHVGKV.js +75 -0
  17. package/dist/{chunk-TUXNOSCT.js → chunk-SO7IJZIR.js} +4 -2
  18. package/dist/{chunk-T3EGAN7O.js → chunk-WD56MJO2.js} +5 -3
  19. package/dist/{core-_1K1jLyH.d.ts → core-Bm-1bOjF.d.ts} +8 -1
  20. package/dist/{core-DF7gei-P.d.cts → core-zpQkbNf_.d.cts} +8 -1
  21. package/dist/core.cjs +3 -1
  22. package/dist/core.css +40 -0
  23. package/dist/core.d.cts +3 -2
  24. package/dist/core.d.ts +3 -2
  25. package/dist/core.js +12 -7
  26. package/dist/game.cjs +2801 -0
  27. package/dist/game.css +8919 -0
  28. package/dist/game.d.cts +416 -0
  29. package/dist/game.d.ts +416 -0
  30. package/dist/game.js +1020 -0
  31. package/dist/index.cjs +5523 -5461
  32. package/dist/index.css +80 -0
  33. package/dist/index.d.cts +51 -10
  34. package/dist/index.d.ts +51 -10
  35. package/dist/index.js +723 -657
  36. package/dist/markdown-editor.js +3 -2
  37. package/dist/rich-text-editor.cjs +3 -1
  38. package/dist/rich-text-editor.js +7 -4
  39. package/dist/{select-date-range-BT71tp7y.d.cts → select-date-range-Cm5o2xPp.d.cts} +1 -1
  40. package/dist/{select-date-range-CFGzoyLs.d.ts → select-date-range-yGDEA1RP.d.ts} +1 -1
  41. package/dist/select-date-range.d.cts +3 -2
  42. package/dist/select-date-range.d.ts +3 -2
  43. package/dist/select-date-range.js +8 -5
  44. package/package.json +9 -3
  45. package/dist/chunk-SJFT5OSX.js +0 -131
@@ -0,0 +1,706 @@
1
+ import {
2
+ TextArea
3
+ } from "./chunk-SCEHVGKV.js";
4
+ import {
5
+ Icon,
6
+ Modal
7
+ } from "./chunk-QV3AP6A2.js";
8
+ import {
9
+ Button
10
+ } from "./chunk-CZ2ITBRW.js";
11
+ import {
12
+ PopupPortal,
13
+ useControlSize,
14
+ useControllableState,
15
+ usePlaceholderMode,
16
+ withTitleTooltip
17
+ } from "./chunk-NZMUW5XI.js";
18
+
19
+ // src/components/Navigation.tsx
20
+ import { useEffect, useId, useLayoutEffect, useMemo, useRef, useState } from "react";
21
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
22
+ import { createElement } from "react";
23
+ function MenuPopup({
24
+ anchorRef,
25
+ open,
26
+ placement,
27
+ menuId,
28
+ theme,
29
+ children,
30
+ onMouseEnter,
31
+ onMouseLeave
32
+ }) {
33
+ const [mounted, setMounted] = useState(open);
34
+ const [fontSize, setFontSize] = useState();
35
+ useLayoutEffect(() => {
36
+ const anchor = anchorRef.current;
37
+ if (!mounted || !anchor) return;
38
+ const syncFontSize = () => setFontSize(getComputedStyle(anchor).fontSize);
39
+ syncFontSize();
40
+ const observer = new ResizeObserver(syncFontSize);
41
+ observer.observe(anchor);
42
+ return () => observer.disconnect();
43
+ });
44
+ useEffect(() => {
45
+ if (open) {
46
+ setMounted(true);
47
+ return void 0;
48
+ }
49
+ const timer = window.setTimeout(() => setMounted(false), 160);
50
+ return () => window.clearTimeout(timer);
51
+ }, [open]);
52
+ return /* @__PURE__ */ jsx(
53
+ PopupPortal,
54
+ {
55
+ anchorRef,
56
+ open: mounted,
57
+ placement,
58
+ offset: 4,
59
+ className: `sia-menu__popup sia-menu--${theme}${open ? " is-open" : " is-closing"}`,
60
+ style: { fontSize },
61
+ "data-sia-menu-owner": menuId,
62
+ onMouseEnter,
63
+ onMouseLeave,
64
+ children: /* @__PURE__ */ jsx("ul", { className: "sia-menu__popup-list", role: "menu", children })
65
+ }
66
+ );
67
+ }
68
+ function MenuEntry({
69
+ item,
70
+ level,
71
+ parents,
72
+ props,
73
+ reserveIcon
74
+ }) {
75
+ const anchorRef = useRef(null);
76
+ const closeTimerRef = useRef(void 0);
77
+ const hasChildren = Boolean(item.children?.length);
78
+ const isOpen = props.open.includes(item.key);
79
+ const isSelected = props.selected.includes(item.key);
80
+ const path = [item.key, ...parents];
81
+ const collapsed = props.inlineCollapsed && level === 0;
82
+ const inlineSubmenu = props.mode === "inline" && !collapsed;
83
+ useEffect(() => () => {
84
+ if (closeTimerRef.current !== void 0) window.clearTimeout(closeTimerRef.current);
85
+ }, []);
86
+ function cancelClose() {
87
+ if (closeTimerRef.current !== void 0) {
88
+ window.clearTimeout(closeTimerRef.current);
89
+ closeTimerRef.current = void 0;
90
+ }
91
+ }
92
+ function scheduleClose() {
93
+ cancelClose();
94
+ closeTimerRef.current = window.setTimeout(() => props.toggle(item.key, false), 100);
95
+ }
96
+ const hover = props.triggerSubMenuAction === "hover" && hasChildren && !inlineSubmenu;
97
+ const submenu = hasChildren ? /* @__PURE__ */ jsx(MenuLevel, { items: item.children ?? [], level: level + 1, parents: [item.key, ...parents], props }) : null;
98
+ const popupPlacement = props.mode === "horizontal" && level === 0 ? "bottom-start" : "right-start";
99
+ return /* @__PURE__ */ jsxs(
100
+ "li",
101
+ {
102
+ className: `sia-menu__entry${isOpen ? " is-open" : ""}${isSelected ? " is-selected" : ""}${item.disabled ? " is-disabled" : ""}${item.danger ? " is-danger" : ""}`,
103
+ onMouseEnter: hover ? () => {
104
+ cancelClose();
105
+ props.toggle(item.key, true);
106
+ } : void 0,
107
+ onMouseLeave: hover ? scheduleClose : void 0,
108
+ children: [
109
+ /* @__PURE__ */ jsxs(
110
+ "button",
111
+ {
112
+ ref: anchorRef,
113
+ type: "button",
114
+ className: "sia-menu__item",
115
+ style: { paddingInlineStart: props.mode === "inline" && !props.inlineCollapsed ? 12 + level * props.inlineIndent : void 0 },
116
+ ...withTitleTooltip({ title: collapsed ? item.title ?? (typeof item.label === "string" ? item.label : void 0) : item.title }),
117
+ disabled: item.disabled,
118
+ "aria-current": isSelected ? "page" : void 0,
119
+ "data-applied": item.applied || void 0,
120
+ "aria-expanded": hasChildren ? isOpen : void 0,
121
+ onClick: (event) => hasChildren ? props.toggle(item.key) : props.select(item, path, event),
122
+ children: [
123
+ reserveIcon ? /* @__PURE__ */ 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,
124
+ item.applied ? /* @__PURE__ */ jsx("span", { className: "sia-menu__applied", role: "img", "aria-label": item.appliedLabel ?? "\u5F53\u524D\u4F7F\u7528", children: /* @__PURE__ */ jsx(Icon, { name: "circle-check", size: 32 }) }) : null,
125
+ !collapsed ? /* @__PURE__ */ jsx("span", { className: "sia-menu__label", children: item.label }) : null,
126
+ !collapsed && item.extra ? /* @__PURE__ */ jsx("span", { className: "sia-menu__extra", children: item.extra }) : null,
127
+ !collapsed && hasChildren ? /* @__PURE__ */ jsx(Icon, { className: "sia-menu__expand-icon", name: "chevron-down", size: 13 }) : null
128
+ ]
129
+ }
130
+ ),
131
+ hasChildren ? inlineSubmenu ? /* @__PURE__ */ jsx("ul", { className: "sia-menu__submenu", role: "menu", "aria-hidden": !isOpen, children: submenu }) : /* @__PURE__ */ jsx(
132
+ MenuPopup,
133
+ {
134
+ anchorRef,
135
+ open: isOpen,
136
+ placement: popupPlacement,
137
+ menuId: props.menuId,
138
+ theme: props.theme,
139
+ onMouseEnter: hover ? cancelClose : void 0,
140
+ onMouseLeave: hover ? scheduleClose : void 0,
141
+ children: submenu
142
+ }
143
+ ) : null
144
+ ]
145
+ }
146
+ );
147
+ }
148
+ function hasMenuIcon(items) {
149
+ return items.some((item) => item.type === "group" ? hasMenuIcon(item.children ?? []) : item.type !== "divider" && Boolean(item.icon));
150
+ }
151
+ function MenuLevel({
152
+ items,
153
+ level,
154
+ parents,
155
+ props,
156
+ reserveIcon = hasMenuIcon(items)
157
+ }) {
158
+ return /* @__PURE__ */ jsx(Fragment, { children: items.map((item, index) => {
159
+ if (item.type === "divider") return /* @__PURE__ */ jsx("li", { className: "sia-menu__divider", role: "separator" }, item.key || `divider-${index}`);
160
+ if (item.type === "group") return /* @__PURE__ */ jsxs("li", { className: "sia-menu__group", children: [
161
+ /* @__PURE__ */ jsx("div", { className: "sia-menu__group-title", children: item.label }),
162
+ /* @__PURE__ */ jsx("ul", { role: "group", children: /* @__PURE__ */ jsx(MenuLevel, { items: item.children ?? [], level: level + 1, parents: [...parents, item.key], props, reserveIcon }) })
163
+ ] }, item.key);
164
+ return /* @__PURE__ */ jsx(MenuEntry, { item, level, parents, props, reserveIcon }, item.key);
165
+ }) });
166
+ }
167
+ function Menu({
168
+ items,
169
+ mode = "vertical",
170
+ theme = "light",
171
+ selectedKeys,
172
+ defaultSelectedKeys = [],
173
+ openKeys,
174
+ defaultOpenKeys = [],
175
+ multiple = false,
176
+ selectable = true,
177
+ inlineCollapsed = false,
178
+ inlineIndent = 20,
179
+ triggerSubMenuAction = "click",
180
+ onClick,
181
+ onSelect,
182
+ onDeselect,
183
+ onOpenChange,
184
+ className = "",
185
+ ...rest
186
+ }) {
187
+ const menuId = useId();
188
+ const rootRef = useRef(null);
189
+ const [selected, setSelected] = useControllableState({ value: selectedKeys, defaultValue: defaultSelectedKeys });
190
+ const [open, setOpen] = useControllableState({ value: openKeys, defaultValue: defaultOpenKeys, onChange: (next) => onOpenChange?.([...next]) });
191
+ useEffect(() => {
192
+ if (mode === "inline" || !open.length) return void 0;
193
+ const closeOutside = (event) => {
194
+ const target = event.target;
195
+ if (rootRef.current?.contains(target)) return;
196
+ const owner = target instanceof Element ? target.closest("[data-sia-menu-owner]")?.getAttribute("data-sia-menu-owner") : null;
197
+ if (owner !== menuId) setOpen([]);
198
+ };
199
+ document.addEventListener("pointerdown", closeOutside);
200
+ return () => document.removeEventListener("pointerdown", closeOutside);
201
+ }, [menuId, mode, open.length, setOpen]);
202
+ function toggle(key, force) {
203
+ const shouldOpen = force ?? !open.includes(key);
204
+ setOpen(shouldOpen ? open.includes(key) ? open : [...open, key] : open.filter((item) => item !== key));
205
+ }
206
+ function select(item, keyPath, domEvent) {
207
+ const info = { key: item.key, keyPath, domEvent, item };
208
+ onClick?.(info);
209
+ if (!selectable) return;
210
+ const exists = selected.includes(item.key);
211
+ const next = multiple ? exists ? selected.filter((key) => key !== item.key) : [...selected, item.key] : [item.key];
212
+ setSelected(next);
213
+ if (exists && multiple) onDeselect?.({ ...info, selectedKeys: [...next] });
214
+ else onSelect?.({ ...info, selectedKeys: [...next] });
215
+ if (mode !== "inline") setOpen([]);
216
+ }
217
+ return /* @__PURE__ */ 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__ */ jsx(MenuLevel, { items, level: 0, parents: [], props: { menuId, mode, theme, multiple, selectable, inlineCollapsed, inlineIndent, triggerSubMenuAction, selected, open, select, toggle } }) });
218
+ }
219
+ function Steps({ items, current = 0, initial = 0, direction = "horizontal", type = "default", size = "default", status = "process", progressDot = false, onChange, className = "", ...props }) {
220
+ return /* @__PURE__ */ jsx("div", { className: `sia-steps sia-steps--${direction} sia-steps--${type} sia-steps--${size} ${className}`.trim(), ...withTitleTooltip(props), children: items.map((item, rawIndex) => {
221
+ const index = rawIndex + initial;
222
+ const itemStatus = item.status ?? (index < current ? "finish" : index === current ? status : "wait");
223
+ const dot = /* @__PURE__ */ jsx("span", { className: "sia-steps__dot" });
224
+ const icon = progressDot ? typeof progressDot === "function" ? progressDot(dot, { index, status: itemStatus, title: item.title, description: item.description }) : dot : item.icon ?? (itemStatus === "finish" ? /* @__PURE__ */ jsx(Icon, { name: "check", size: 15 }) : itemStatus === "error" ? /* @__PURE__ */ jsx(Icon, { name: "close", size: 14 }) : index + 1);
225
+ return /* @__PURE__ */ jsxs("button", { type: "button", className: `sia-steps__item sia-steps__item--${itemStatus}`, disabled: item.disabled || !onChange, onClick: () => onChange?.(index), children: [
226
+ /* @__PURE__ */ jsxs("span", { className: "sia-steps__head", children: [
227
+ /* @__PURE__ */ jsx("span", { className: "sia-steps__icon", children: icon }),
228
+ /* @__PURE__ */ jsx("span", { className: "sia-steps__tail" })
229
+ ] }),
230
+ /* @__PURE__ */ jsxs("span", { className: "sia-steps__content", children: [
231
+ /* @__PURE__ */ jsxs("span", { className: "sia-steps__title", children: [
232
+ item.title,
233
+ item.subTitle ? /* @__PURE__ */ jsx("small", { children: item.subTitle }) : null
234
+ ] }),
235
+ item.description ? /* @__PURE__ */ jsx("span", { className: "sia-steps__description", children: item.description }) : null
236
+ ] })
237
+ ] }, index);
238
+ }) });
239
+ }
240
+ function Segmented({ options, value, defaultValue, variant = "default", shape = "capsule", size: sizeProp, block = false, vertical = false, disabled = false, onChange, className = "", onKeyDown, ...props }) {
241
+ const size = useControlSize(sizeProp);
242
+ const normalized = useMemo(() => options.map((option) => typeof option === "object" ? option : { label: option, value: option }), [options]);
243
+ const [current, setCurrent] = useControllableState({ value, defaultValue: defaultValue ?? normalized[0]?.value, onChange: (next) => next !== void 0 && onChange?.(next) });
244
+ function keyboard(event) {
245
+ onKeyDown?.(event);
246
+ if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(event.key)) return;
247
+ event.preventDefault();
248
+ const enabled = normalized.filter((option) => !option.disabled);
249
+ const index = enabled.findIndex((option) => option.value === current);
250
+ const next = event.key === "ArrowRight" || event.key === "ArrowDown" ? enabled[(index + 1) % enabled.length] : enabled[(index - 1 + enabled.length) % enabled.length];
251
+ if (next) setCurrent(next.value);
252
+ }
253
+ return /* @__PURE__ */ jsx("div", { className: `sia-segmented sia-segmented--${size}${variant === "zigzag" && !vertical && normalized.length === 2 ? ` sia-segmented--zigzag sia-segmented--shape-${shape}` : ""}${block ? " sia-segmented--block" : ""}${vertical ? " sia-segmented--vertical" : ""}${disabled ? " is-disabled" : ""} ${className}`.trim(), role: "radiogroup", onKeyDown: keyboard, ...withTitleTooltip(props), children: normalized.map((option) => /* @__PURE__ */ createElement("button", { type: "button", role: "radio", "aria-checked": option.value === current, ...withTitleTooltip({ title: option.title }), className: option.value === current ? "is-selected" : "", disabled: disabled || option.disabled, key: option.value, onClick: () => setCurrent(option.value) }, option.icon, /* @__PURE__ */ jsx("span", { children: option.label ?? option.value }))) });
254
+ }
255
+
256
+ // src/components/Dropdown.tsx
257
+ import { cloneElement, isValidElement, useEffect as useEffect2, useLayoutEffect as useLayoutEffect2, useRef as useRef2, useState as useState2 } from "react";
258
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
259
+ var placementMap = {
260
+ bottomLeft: "bottom-start",
261
+ bottomRight: "bottom-end",
262
+ topLeft: "top-start",
263
+ topRight: "top-end"
264
+ };
265
+ function DropdownInternal({
266
+ popupAnchorRef,
267
+ menu,
268
+ children,
269
+ trigger = ["hover"],
270
+ placement = "bottomLeft",
271
+ open,
272
+ defaultOpen = false,
273
+ disabled = false,
274
+ showTriggerIcon = true,
275
+ arrow = false,
276
+ autoFocus = false,
277
+ openDelay = 80,
278
+ closeDelay = 120,
279
+ popupClassName = "",
280
+ popupStyle,
281
+ popupRender,
282
+ onOpenChange,
283
+ className = "",
284
+ onClick,
285
+ onMouseEnter,
286
+ onMouseLeave,
287
+ onContextMenu,
288
+ onKeyDown,
289
+ ...props
290
+ }) {
291
+ const rootRef = useRef2(null);
292
+ const contextAnchorRef = useRef2(null);
293
+ const popupRef = useRef2(null);
294
+ const openTimerRef = useRef2(void 0);
295
+ const closeTimerRef = useRef2(void 0);
296
+ const [internalOpen, setInternalOpen] = useState2(defaultOpen);
297
+ const [mounted, setMounted] = useState2(open ?? defaultOpen);
298
+ const [contextPoint, setContextPoint] = useState2();
299
+ const visible = open ?? internalOpen;
300
+ const triggerSet = new Set(trigger);
301
+ const pointAtCenter = typeof arrow === "object" && arrow.pointAtCenter;
302
+ const [triggerFontSize, setTriggerFontSize] = useState2();
303
+ useLayoutEffect2(() => {
304
+ if (!visible || !rootRef.current) return;
305
+ const root = rootRef.current;
306
+ const target = root.querySelector("button, [role='button'], a") ?? (root.firstElementChild !== contextAnchorRef.current ? root.firstElementChild : null) ?? root;
307
+ const syncFontSize = () => setTriggerFontSize(getComputedStyle(target).fontSize);
308
+ syncFontSize();
309
+ const observer = new ResizeObserver(syncFontSize);
310
+ observer.observe(target);
311
+ return () => observer.disconnect();
312
+ });
313
+ function clearTimer(ref) {
314
+ if (ref.current === void 0) return;
315
+ window.clearTimeout(ref.current);
316
+ ref.current = void 0;
317
+ }
318
+ function clearTimers() {
319
+ clearTimer(openTimerRef);
320
+ clearTimer(closeTimerRef);
321
+ }
322
+ function updateOpen(next, source) {
323
+ clearTimers();
324
+ if (next === visible) return;
325
+ if (open === void 0) setInternalOpen(next);
326
+ onOpenChange?.(next, { source });
327
+ }
328
+ function scheduleOpen() {
329
+ clearTimer(closeTimerRef);
330
+ clearTimer(openTimerRef);
331
+ openTimerRef.current = window.setTimeout(() => updateOpen(true, "trigger"), Math.max(0, openDelay));
332
+ }
333
+ function scheduleClose() {
334
+ clearTimer(openTimerRef);
335
+ clearTimer(closeTimerRef);
336
+ closeTimerRef.current = window.setTimeout(() => updateOpen(false, "trigger"), Math.max(0, closeDelay));
337
+ }
338
+ useEffect2(() => {
339
+ if (visible) {
340
+ setMounted(true);
341
+ return void 0;
342
+ }
343
+ const timer = window.setTimeout(() => setMounted(false), 160);
344
+ return () => window.clearTimeout(timer);
345
+ }, [visible]);
346
+ useEffect2(() => {
347
+ if (!visible && !mounted) setContextPoint(void 0);
348
+ }, [mounted, visible]);
349
+ useEffect2(() => () => clearTimers(), []);
350
+ useEffect2(() => {
351
+ if (!visible) return void 0;
352
+ const contextMenuTrigger = triggerSet.has("contextMenu");
353
+ const closeOutside = (event) => {
354
+ const target = event.target;
355
+ if (popupRef.current?.contains(target)) return;
356
+ if (!contextMenuTrigger && rootRef.current?.contains(target)) return;
357
+ const targetOwner = target instanceof Element ? target.closest("[data-sia-menu-owner]")?.getAttribute("data-sia-menu-owner") : null;
358
+ const menuOwner = popupRef.current?.querySelector("[data-sia-menu-owner]")?.getAttribute("data-sia-menu-owner");
359
+ if (menuOwner && targetOwner === menuOwner) return;
360
+ updateOpen(false, "trigger");
361
+ };
362
+ const closeWithEscape = (event) => {
363
+ if (event.key !== "Escape") return;
364
+ updateOpen(false, "trigger");
365
+ rootRef.current?.querySelector("button, a, [tabindex]:not([tabindex='-1'])")?.focus();
366
+ };
367
+ const keepOpenOverNestedMenu = (event) => {
368
+ const target = event.target;
369
+ if (target instanceof Element && target.closest(".sia-menu__popup")) clearTimer(closeTimerRef);
370
+ };
371
+ document.addEventListener("pointerdown", closeOutside);
372
+ document.addEventListener("keydown", closeWithEscape);
373
+ document.addEventListener("pointerover", keepOpenOverNestedMenu);
374
+ return () => {
375
+ document.removeEventListener("pointerdown", closeOutside);
376
+ document.removeEventListener("keydown", closeWithEscape);
377
+ document.removeEventListener("pointerover", keepOpenOverNestedMenu);
378
+ };
379
+ }, [visible]);
380
+ useEffect2(() => {
381
+ if (!visible || !mounted || !autoFocus) return void 0;
382
+ const frame = window.requestAnimationFrame(() => {
383
+ popupRef.current?.querySelector(
384
+ "[data-sia-dropdown-autofocus], input:not(:disabled), textarea:not(:disabled), .sia-menu__item:not(:disabled)"
385
+ )?.focus();
386
+ });
387
+ return () => window.cancelAnimationFrame(frame);
388
+ }, [autoFocus, mounted, visible]);
389
+ function handleMenuClick(info) {
390
+ info.domEvent.stopPropagation();
391
+ menu.onClick?.(info);
392
+ updateOpen(false, "menu");
393
+ }
394
+ function handleClick(event) {
395
+ onClick?.(event);
396
+ if (disabled || !triggerSet.has("click") || event.defaultPrevented) return;
397
+ setContextPoint(void 0);
398
+ updateOpen(!visible, "trigger");
399
+ }
400
+ function handleMouseEnter(event) {
401
+ onMouseEnter?.(event);
402
+ if (!disabled && triggerSet.has("hover")) scheduleOpen();
403
+ }
404
+ function handleMouseLeave(event) {
405
+ onMouseLeave?.(event);
406
+ if (!disabled && triggerSet.has("hover")) scheduleClose();
407
+ }
408
+ function handleContextMenu(event) {
409
+ onContextMenu?.(event);
410
+ if (disabled || !triggerSet.has("contextMenu") || event.defaultPrevented) return;
411
+ event.preventDefault();
412
+ event.stopPropagation();
413
+ setContextPoint({ x: event.clientX, y: event.clientY });
414
+ updateOpen(true, "trigger");
415
+ }
416
+ function handleKeyDown(event) {
417
+ onKeyDown?.(event);
418
+ if (disabled || event.defaultPrevented) return;
419
+ if (event.key === "ArrowDown" && (triggerSet.has("click") || triggerSet.has("hover"))) {
420
+ event.preventDefault();
421
+ setContextPoint(void 0);
422
+ updateOpen(true, "trigger");
423
+ } else if (triggerSet.has("contextMenu") && (event.key === "ContextMenu" || event.shiftKey && event.key === "F10")) {
424
+ event.preventDefault();
425
+ setContextPoint(void 0);
426
+ updateOpen(true, "trigger");
427
+ }
428
+ }
429
+ const menuNode = /* @__PURE__ */ jsx2(
430
+ Menu,
431
+ {
432
+ mode: "vertical",
433
+ theme: menu.theme,
434
+ items: menu.items,
435
+ multiple: menu.multiple,
436
+ selectable: menu.selectable,
437
+ selectedKeys: menu.selectedKeys,
438
+ defaultSelectedKeys: menu.defaultSelectedKeys,
439
+ triggerSubMenuAction: "hover",
440
+ onClick: handleMenuClick,
441
+ onSelect: menu.onSelect,
442
+ onDeselect: menu.onDeselect,
443
+ className: "sia-dropdown__menu"
444
+ }
445
+ );
446
+ const triggerNode = showTriggerIcon && isValidElement(children) && children.type === Button && children.props.children !== void 0 && children.props.children !== null ? cloneElement(children, {}, /* @__PURE__ */ jsxs2("span", { className: "sia-dropdown__trigger-content", children: [
447
+ children.props.children,
448
+ /* @__PURE__ */ jsx2(Icon, { name: "chevron-down", size: 14, className: "sia-dropdown__trigger-icon" })
449
+ ] })) : children;
450
+ return /* @__PURE__ */ jsxs2(
451
+ "span",
452
+ {
453
+ ref: rootRef,
454
+ className: `sia-dropdown${visible ? " is-open" : ""}${disabled ? " is-disabled" : ""} ${className}`.trim(),
455
+ "aria-expanded": visible,
456
+ "aria-haspopup": "menu",
457
+ tabIndex: triggerSet.has("contextMenu") ? 0 : void 0,
458
+ onClick: handleClick,
459
+ onMouseEnter: handleMouseEnter,
460
+ onMouseLeave: handleMouseLeave,
461
+ onContextMenu: handleContextMenu,
462
+ onKeyDown: handleKeyDown,
463
+ ...withTitleTooltip(props),
464
+ children: [
465
+ triggerNode,
466
+ /* @__PURE__ */ jsx2(
467
+ "span",
468
+ {
469
+ ref: contextAnchorRef,
470
+ className: "sia-dropdown__context-anchor",
471
+ style: contextPoint ? { left: contextPoint.x, top: contextPoint.y } : void 0,
472
+ "aria-hidden": "true"
473
+ }
474
+ ),
475
+ /* @__PURE__ */ jsx2(
476
+ PopupPortal,
477
+ {
478
+ ref: popupRef,
479
+ anchorRef: contextPoint ? contextAnchorRef : popupAnchorRef ?? rootRef,
480
+ open: mounted,
481
+ placement: contextPoint ? "bottom-start" : placementMap[placement],
482
+ offset: contextPoint ? 2 : 6,
483
+ className: `sia-dropdown__popup${visible ? " is-open" : " is-closing"}${arrow ? " sia-dropdown__popup--arrow" : ""}${pointAtCenter ? " sia-dropdown__popup--arrow-center" : ""} ${popupClassName}`.trim(),
484
+ style: { fontSize: triggerFontSize, ...popupStyle },
485
+ onMouseEnter: () => {
486
+ clearTimer(closeTimerRef);
487
+ if (!disabled && triggerSet.has("hover")) clearTimer(openTimerRef);
488
+ },
489
+ onMouseLeave: () => {
490
+ if (!disabled && triggerSet.has("hover")) scheduleClose();
491
+ },
492
+ onClick: (event) => event.stopPropagation(),
493
+ children: popupRender ? popupRender(menuNode) : menuNode
494
+ },
495
+ contextPoint ? `context-${contextPoint.x}-${contextPoint.y}` : "trigger"
496
+ )
497
+ ]
498
+ }
499
+ );
500
+ }
501
+ function DropdownRoot(props) {
502
+ return /* @__PURE__ */ jsx2(DropdownInternal, { ...props });
503
+ }
504
+ function DropdownButton({
505
+ children,
506
+ className = "",
507
+ buttonProps,
508
+ onClick,
509
+ disabled,
510
+ buttonDisabled,
511
+ dropdownDisabled,
512
+ trigger = ["click"],
513
+ ...dropdownProps
514
+ }) {
515
+ const groupRef = useRef2(null);
516
+ return /* @__PURE__ */ jsxs2("span", { ref: groupRef, className: `sia-dropdown-button ${className}`.trim(), children: [
517
+ /* @__PURE__ */ jsx2(Button, { ...buttonProps, disabled: disabled || buttonDisabled, onClick, children }),
518
+ /* @__PURE__ */ jsx2(DropdownInternal, { ...dropdownProps, popupAnchorRef: groupRef, disabled: disabled || dropdownDisabled, trigger, showTriggerIcon: false, children: /* @__PURE__ */ jsx2(
519
+ Button,
520
+ {
521
+ ...buttonProps,
522
+ className: `sia-dropdown-button__arrow ${buttonProps?.className ?? ""}`.trim(),
523
+ disabled: disabled || dropdownDisabled,
524
+ icon: /* @__PURE__ */ jsx2(Icon, { name: "chevron-down", size: 14 }),
525
+ "aria-label": "\u5C55\u5F00\u4E0B\u62C9\u83DC\u5355"
526
+ }
527
+ ) })
528
+ ] });
529
+ }
530
+ var Dropdown = Object.assign(DropdownRoot, {
531
+ /** 组合主操作按钮与下拉菜单的按钮组件。 */
532
+ Button: DropdownButton
533
+ });
534
+
535
+ // src/components/Input.tsx
536
+ import { forwardRef, useId as useId2, useRef as useRef3, useState as useState3 } from "react";
537
+ import { Fragment as Fragment2, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
538
+ var Input = forwardRef(function Input2({
539
+ label,
540
+ hint,
541
+ status = "default",
542
+ size: sizeProp,
543
+ prefix,
544
+ suffix,
545
+ allowClear = true,
546
+ onClear,
547
+ showCount = false,
548
+ placeholderMode,
549
+ placeholder,
550
+ className = "",
551
+ id,
552
+ disabled,
553
+ value,
554
+ defaultValue,
555
+ maxLength,
556
+ onChange,
557
+ expandable = false,
558
+ ...props
559
+ }, forwardedRef) {
560
+ const size = useControlSize(sizeProp);
561
+ const fallbackId = useId2();
562
+ const inputId = id ?? fallbackId;
563
+ const localRef = useRef3(null);
564
+ const [uncontrolledValue, setUncontrolledValue] = useState3(() => defaultValue === void 0 ? "" : String(defaultValue));
565
+ const currentText = value !== void 0 ? String(value) : uncontrolledValue;
566
+ const hasValue = currentText.length > 0;
567
+ const [expanded, setExpanded] = useState3(false);
568
+ const [expandedDraft, setExpandedDraft] = useState3("");
569
+ const floatingPlaceholder = usePlaceholderMode(placeholderMode) === "floating" && Boolean(placeholder);
570
+ const hintId = `${inputId}-hint`;
571
+ const describedBy = [props["aria-describedby"], hint ? hintId : null].filter(Boolean).join(" ") || void 0;
572
+ function setRef(node) {
573
+ localRef.current = node;
574
+ if (typeof forwardedRef === "function") forwardedRef(node);
575
+ else if (forwardedRef) forwardedRef.current = node;
576
+ }
577
+ function handleChange(event) {
578
+ if (maxLength !== void 0 && maxLength >= 0 && event.target.value.length > maxLength) {
579
+ const valueSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set;
580
+ valueSetter?.call(event.target, event.target.value.slice(0, maxLength));
581
+ }
582
+ setUncontrolledValue(event.target.value);
583
+ onChange?.(event);
584
+ }
585
+ function clearValue() {
586
+ const input2 = localRef.current;
587
+ if (!input2 || disabled) return;
588
+ const valueSetter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set;
589
+ valueSetter?.call(input2, "");
590
+ input2.dispatchEvent(new Event("input", { bubbles: true }));
591
+ setUncontrolledValue("");
592
+ input2.focus();
593
+ onClear?.();
594
+ }
595
+ function handleControlMouseDown(event) {
596
+ if (disabled || event.defaultPrevented || event.button !== 0) return;
597
+ const target = event.target;
598
+ if (!(target instanceof Element)) return;
599
+ const interactive = target.closest("input, textarea, select, button, a[href], [tabindex], [contenteditable]:not([contenteditable='false']), [role='button'], [role='link']");
600
+ if (interactive && event.currentTarget.contains(interactive) && !interactive.classList.contains("sia-input-control__clear")) return;
601
+ event.preventDefault();
602
+ localRef.current?.focus({ preventScroll: true });
603
+ }
604
+ const input = /* @__PURE__ */ jsx3(
605
+ "input",
606
+ {
607
+ ...withTitleTooltip(props),
608
+ ref: setRef,
609
+ id: inputId,
610
+ className: "sia-input",
611
+ disabled,
612
+ value,
613
+ defaultValue,
614
+ maxLength,
615
+ placeholder,
616
+ "aria-describedby": describedBy,
617
+ "aria-invalid": status === "error" || void 0,
618
+ onChange: handleChange
619
+ }
620
+ );
621
+ const control = /* @__PURE__ */ jsxs3("span", { onMouseDown: handleControlMouseDown, className: `sia-input-control sia-input-control--${size} sia-input-control--${status}${floatingPlaceholder ? " sia-input-control--floating" : ""}${floatingPlaceholder && hasValue ? " is-filled" : ""}${disabled ? " is-disabled" : ""}`, children: [
622
+ prefix ? /* @__PURE__ */ jsx3("span", { className: "sia-input-control__affix", children: prefix }) : null,
623
+ floatingPlaceholder ? /* @__PURE__ */ jsxs3("span", { className: "sia-input-control__input-wrap", children: [
624
+ input,
625
+ /* @__PURE__ */ jsx3("span", { className: "sia-input-control__floating-placeholder", "aria-hidden": "true", children: placeholder })
626
+ ] }) : input,
627
+ allowClear && hasValue && !disabled ? /* @__PURE__ */ jsx3("button", { className: "sia-input-control__clear", type: "button", "aria-label": "\u6E05\u7A7A\u8F93\u5165", onClick: clearValue, children: /* @__PURE__ */ jsx3(Icon, { name: "circle-close", variant: "filled", size: 15 }) }) : null,
628
+ suffix ? /* @__PURE__ */ jsx3("span", { className: "sia-input-control__affix", children: suffix }) : null,
629
+ expandable && !disabled && !props.readOnly && (!props.type || props.type === "text") ? /* @__PURE__ */ jsx3(
630
+ "button",
631
+ {
632
+ type: "button",
633
+ className: "sia-input-control__expand",
634
+ "aria-label": "\u5C55\u5F00\u7F16\u8F91",
635
+ title: "\u5C55\u5F00\u7F16\u8F91",
636
+ onClick: () => {
637
+ if (localRef.current?.matches(":disabled")) return;
638
+ setExpandedDraft(currentText);
639
+ setExpanded(true);
640
+ },
641
+ children: /* @__PURE__ */ jsx3(Icon, { name: "expand", size: 15 })
642
+ }
643
+ ) : null,
644
+ showCount ? /* @__PURE__ */ jsxs3("span", { className: `sia-input-control__count${maxLength !== void 0 && currentText.length >= maxLength ? " is-limit" : ""}`, "aria-live": "polite", children: [
645
+ currentText.length,
646
+ maxLength !== void 0 ? `/${maxLength}` : null
647
+ ] }) : null
648
+ ] });
649
+ const editor = expandable ? /* @__PURE__ */ jsx3(
650
+ Modal,
651
+ {
652
+ open: expanded,
653
+ title: "\u5C55\u5F00\u7F16\u8F91",
654
+ okText: "\u786E\u5B9A",
655
+ cancelText: "\u53D6\u6D88",
656
+ onCancel: () => setExpanded(false),
657
+ afterOpenChange: (open) => {
658
+ if (!open) setExpandedDraft("");
659
+ },
660
+ onOk: () => {
661
+ const target = localRef.current;
662
+ if (!target || target.matches(":disabled") || props.readOnly) return false;
663
+ const normalized = expandedDraft.replace(/\r\n|[\r\n]/g, " ");
664
+ const next = maxLength !== void 0 && maxLength >= 0 ? normalized.slice(0, maxLength) : normalized;
665
+ Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set?.call(target, next);
666
+ target.dispatchEvent(new Event("input", { bubbles: true }));
667
+ setUncontrolledValue(next);
668
+ setExpanded(false);
669
+ },
670
+ children: /* @__PURE__ */ jsx3(
671
+ TextArea,
672
+ {
673
+ "aria-label": "\u5C55\u5F00\u7F16\u8F91\u5185\u5BB9",
674
+ value: expandedDraft,
675
+ onChange: (event) => setExpandedDraft(event.target.value),
676
+ maxLength,
677
+ showCount,
678
+ placeholder,
679
+ rows: 8,
680
+ disabled,
681
+ readOnly: props.readOnly
682
+ }
683
+ )
684
+ }
685
+ ) : null;
686
+ if (!label && !hint) return /* @__PURE__ */ jsxs3(Fragment2, { children: [
687
+ /* @__PURE__ */ jsx3("span", { className: `sia-field ${className}`.trim(), children: control }),
688
+ editor
689
+ ] });
690
+ return /* @__PURE__ */ jsxs3(Fragment2, { children: [
691
+ /* @__PURE__ */ jsxs3("span", { className: `sia-field ${className}`.trim(), children: [
692
+ label ? /* @__PURE__ */ jsx3("label", { className: "sia-field__label", htmlFor: inputId, children: label }) : null,
693
+ control,
694
+ hint ? /* @__PURE__ */ jsx3("span", { id: hintId, className: `sia-field__hint sia-field__hint--${status}`, children: hint }) : null
695
+ ] }),
696
+ editor
697
+ ] });
698
+ });
699
+
700
+ export {
701
+ Menu,
702
+ Steps,
703
+ Segmented,
704
+ Dropdown,
705
+ Input
706
+ };