@sia.soul/sia-react-ui 0.1.23 → 0.1.25
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/dist/{Select-BoVx-D0D.d.ts → Select-O_yY51vc.d.ts} +4 -2
- package/dist/{Select-BO3VyE2n.d.cts → Select-W_xpkpOW.d.cts} +4 -2
- package/dist/chart.cjs +1401 -1160
- package/dist/chart.css +21 -0
- package/dist/chart.js +4 -4
- package/dist/{chunk-KLI65JVD.js → chunk-27ZYAKII.js} +68 -186
- package/dist/{chunk-TZGUBGA4.js → chunk-IYNS423D.js} +4 -3
- package/dist/{chunk-GM47DAAN.js → chunk-IYO2JSGQ.js} +8 -7
- package/dist/{chunk-QJ4OQNQ4.js → chunk-PXHBIRQW.js} +4 -3
- package/dist/{chunk-VX2JECOU.js → chunk-QCBKT5FV.js} +20 -16
- package/dist/chunk-RAO3JHDL.js +284 -0
- package/dist/{chunk-RWGSZW32.js → chunk-RWODH2LW.js} +7 -6
- package/dist/{chunk-OKP4DIQH.js → chunk-TZROBD65.js} +29 -26
- package/dist/{chunk-NPB33IXJ.js → chunk-W52CNNWW.js} +349 -278
- package/dist/{chunk-YT6E3X2K.js → chunk-YQDHCORW.js} +4 -3
- package/dist/{core-Cqgl6Z7h.d.ts → core-BOzLwiXG.d.ts} +44 -5
- package/dist/{core-DF0pknX6.d.cts → core-tbb9ZiBY.d.cts} +44 -5
- package/dist/core.cjs +1637 -1443
- package/dist/core.css +53 -0
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.js +8 -6
- package/dist/index.cjs +3797 -3583
- package/dist/index.css +53 -0
- package/dist/index.d.cts +36 -17
- package/dist/index.d.ts +36 -17
- package/dist/index.js +104 -83
- package/dist/markdown-editor.cjs +269 -28
- package/dist/markdown-editor.css +20 -0
- package/dist/markdown-editor.js +2 -2
- package/dist/rich-text-editor.cjs +1156 -1031
- package/dist/rich-text-editor.css +20 -0
- package/dist/rich-text-editor.js +4 -4
- package/dist/{select-date-range-a6nzK7Wu.d.ts → select-date-range-BjqFUeU6.d.ts} +1 -1
- package/dist/{select-date-range-IOe6MMqu.d.cts → select-date-range-C9w8z3G8.d.cts} +1 -1
- package/dist/select-date-range.cjs +1188 -1059
- package/dist/select-date-range.css +20 -0
- package/dist/select-date-range.d.cts +2 -2
- package/dist/select-date-range.d.ts +2 -2
- package/dist/select-date-range.js +5 -5
- package/package.json +2 -2
- package/dist/chunk-3VJ4CZDQ.js +0 -43
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Dropdown,
|
|
3
3
|
Icon,
|
|
4
|
-
Input
|
|
5
|
-
|
|
6
|
-
} from "./chunk-KLI65JVD.js";
|
|
4
|
+
Input
|
|
5
|
+
} from "./chunk-27ZYAKII.js";
|
|
7
6
|
import {
|
|
8
7
|
Button
|
|
9
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-IYNS423D.js";
|
|
10
9
|
import {
|
|
11
10
|
ControlSizeContext,
|
|
11
|
+
PopupPortal,
|
|
12
12
|
useControlSize,
|
|
13
13
|
useControllableState,
|
|
14
|
-
useFloatingPlaceholder
|
|
15
|
-
|
|
14
|
+
useFloatingPlaceholder,
|
|
15
|
+
withTitleTooltip
|
|
16
|
+
} from "./chunk-RAO3JHDL.js";
|
|
16
17
|
|
|
17
18
|
// src/components/Checkbox.tsx
|
|
18
19
|
import { createContext, forwardRef, useContext, useEffect, useId, useMemo, useRef } from "react";
|
|
@@ -37,7 +38,7 @@ var CheckboxRoot = forwardRef(function Checkbox({ value, size: sizeProp, indeter
|
|
|
37
38
|
/* @__PURE__ */ jsx(
|
|
38
39
|
"input",
|
|
39
40
|
{
|
|
40
|
-
...props,
|
|
41
|
+
...withTitleTooltip(props),
|
|
41
42
|
ref: setRef,
|
|
42
43
|
id: props.id ?? fallbackId,
|
|
43
44
|
className: "sia-checkbox__input",
|
|
@@ -289,7 +290,7 @@ function Popover({ title, content, trigger = "click", overlayClassName = "", ...
|
|
|
289
290
|
function Timeline({ items = [], mode = "left", pending = false, pendingDot, reverse = false, className = "", ...props }) {
|
|
290
291
|
const values = [...items, ...pending ? [{ children: pending === true ? "\u52A0\u8F7D\u4E2D..." : pending, dot: pendingDot ?? /* @__PURE__ */ jsx2(Icon, { name: "loader", className: "sia-spin-icon" }) }] : []];
|
|
291
292
|
if (reverse) values.reverse();
|
|
292
|
-
return /* @__PURE__ */ jsx2("ul", { className: `sia-timeline sia-timeline--${mode} ${className}`.trim(), ...props, children: values.map((item, index) => {
|
|
293
|
+
return /* @__PURE__ */ jsx2("ul", { className: `sia-timeline sia-timeline--${mode} ${className}`.trim(), ...withTitleTooltip(props), children: values.map((item, index) => {
|
|
293
294
|
const position = item.position ?? (mode === "alternate" ? index % 2 ? "right" : "left" : mode);
|
|
294
295
|
return /* @__PURE__ */ jsxs2("li", { className: `sia-timeline__item sia-timeline__item--${position}`, children: [
|
|
295
296
|
item.label ? /* @__PURE__ */ jsx2("span", { className: "sia-timeline__label", children: item.label }) : null,
|
|
@@ -478,7 +479,7 @@ function Tree({
|
|
|
478
479
|
/* @__PURE__ */ jsx2(
|
|
479
480
|
"div",
|
|
480
481
|
{
|
|
481
|
-
...rowProps,
|
|
482
|
+
...withTitleTooltip(rowProps),
|
|
482
483
|
className: `sia-tree__row${blockNode ? " sia-tree__row--block" : ""}${sticky ? " sia-tree__row--sticky" : ""} ${rowClassName}`.trim(),
|
|
483
484
|
style: {
|
|
484
485
|
...rowStyle,
|
|
@@ -538,7 +539,7 @@ function Tree({
|
|
|
538
539
|
] }, node.key);
|
|
539
540
|
});
|
|
540
541
|
}
|
|
541
|
-
return /* @__PURE__ */ jsx2("div", { className: `sia-tree${showLine ? " sia-tree--line" : ""}${stickyAncestors ? " sia-tree--sticky-ancestors" : ""} ${className}`.trim(), role: "tree", "aria-multiselectable": multiple || void 0, ...props, children: render(treeData) });
|
|
542
|
+
return /* @__PURE__ */ jsx2("div", { className: `sia-tree${showLine ? " sia-tree--line" : ""}${stickyAncestors ? " sia-tree--sticky-ancestors" : ""} ${className}`.trim(), role: "tree", "aria-multiselectable": multiple || void 0, ...withTitleTooltip(props), children: render(treeData) });
|
|
542
543
|
}
|
|
543
544
|
|
|
544
545
|
// src/components/Modal.tsx
|
|
@@ -653,6 +654,7 @@ var ModalRoot = forwardRef2(function Modal({
|
|
|
653
654
|
keyboard = true,
|
|
654
655
|
centered = false,
|
|
655
656
|
width = 520,
|
|
657
|
+
height,
|
|
656
658
|
zIndex = 1e3,
|
|
657
659
|
getContainer,
|
|
658
660
|
onOk,
|
|
@@ -728,6 +730,7 @@ var ModalRoot = forwardRef2(function Modal({
|
|
|
728
730
|
useOverlayLifecycle(rendered, localRef, requestClose, keyboard);
|
|
729
731
|
if (!rendered) return null;
|
|
730
732
|
const mergedStyle = {
|
|
733
|
+
...height !== void 0 ? { display: "flex", flexDirection: "column", height, maxHeight: "calc(100dvh - 48px)" } : {},
|
|
731
734
|
...style,
|
|
732
735
|
"--sia-modal-width": typeof width === "number" ? `${width}px` : width
|
|
733
736
|
};
|
|
@@ -755,17 +758,17 @@ var ModalRoot = forwardRef2(function Modal({
|
|
|
755
758
|
"aria-modal": "true",
|
|
756
759
|
"aria-labelledby": title ? titleId : void 0,
|
|
757
760
|
tabIndex: -1,
|
|
758
|
-
...props,
|
|
761
|
+
...withTitleTooltip(props),
|
|
759
762
|
children: [
|
|
760
|
-
/* @__PURE__ */ jsxs3("div", { className: "sia-modal__header", children: [
|
|
763
|
+
/* @__PURE__ */ jsxs3("div", { className: "sia-modal__header", style: height !== void 0 ? { flexShrink: 0 } : void 0, children: [
|
|
761
764
|
/* @__PURE__ */ jsxs3("div", { className: "sia-modal__heading", children: [
|
|
762
765
|
typeIcons[type] ? /* @__PURE__ */ jsx3("span", { className: "sia-modal__type-icon", "aria-hidden": "true", children: typeIcons[type] }) : null,
|
|
763
766
|
title ? /* @__PURE__ */ jsx3("strong", { id: titleId, children: title }) : null
|
|
764
767
|
] }),
|
|
765
768
|
closable ? /* @__PURE__ */ jsx3("button", { type: "button", className: "sia-modal__close", "aria-label": "\u5173\u95ED\u5BF9\u8BDD\u6846", onClick: requestClose, children: /* @__PURE__ */ jsx3(Icon, { name: "close", size: 17 }) }) : null
|
|
766
769
|
] }),
|
|
767
|
-
children !== void 0 ? /* @__PURE__ */ jsx3("div", { className: "sia-modal__body", children }) : null,
|
|
768
|
-
footer !== null ? /* @__PURE__ */ jsxs3("div", { className: "sia-modal__footer", children: [
|
|
770
|
+
children !== void 0 ? /* @__PURE__ */ jsx3("div", { className: "sia-modal__body", style: height !== void 0 ? { flex: 1, minHeight: 0, overflow: "auto" } : void 0, children }) : null,
|
|
771
|
+
footer !== null ? /* @__PURE__ */ jsxs3("div", { className: "sia-modal__footer", style: height !== void 0 ? { flexShrink: 0 } : void 0, children: [
|
|
769
772
|
footer === void 0 && footerExtra != null ? /* @__PURE__ */ jsx3("div", { style: { marginRight: "auto" }, children: footerExtra }) : null,
|
|
770
773
|
footer ?? defaultFooter
|
|
771
774
|
] }) : null
|
|
@@ -1543,9 +1546,10 @@ var Select = forwardRef3(function Select2({
|
|
|
1543
1546
|
}
|
|
1544
1547
|
});
|
|
1545
1548
|
const selectedValues = useMemo4(() => {
|
|
1549
|
+
if (currentValue == null || currentValue === "" && !options.some((option) => option.value === "")) return [];
|
|
1546
1550
|
if (mode === "multiple") return Array.isArray(currentValue) ? currentValue : currentValue === null ? [] : [currentValue];
|
|
1547
1551
|
return Array.isArray(currentValue) ? currentValue.slice(0, 1) : currentValue === null ? [] : [currentValue];
|
|
1548
|
-
}, [currentValue, mode]);
|
|
1552
|
+
}, [currentValue, mode, options]);
|
|
1549
1553
|
const selectedValueSet = useMemo4(() => new Set(selectedValues), [selectedValues]);
|
|
1550
1554
|
const availableOptions = useMemo4(() => {
|
|
1551
1555
|
if (!allowInput) return options;
|
|
@@ -1762,7 +1766,7 @@ var Select = forwardRef3(function Select2({
|
|
|
1762
1766
|
/* @__PURE__ */ jsxs6(
|
|
1763
1767
|
"button",
|
|
1764
1768
|
{
|
|
1765
|
-
...props,
|
|
1769
|
+
...withTitleTooltip(props),
|
|
1766
1770
|
ref: forwardedRef,
|
|
1767
1771
|
className: `sia-select__trigger${floating.className}`,
|
|
1768
1772
|
id: selectId,
|
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
// src/components/titleTooltip.tsx
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
var documents = /* @__PURE__ */ new WeakSet();
|
|
5
|
+
function withTitleTooltip(props) {
|
|
6
|
+
if (!props || typeof props !== "object" || !("title" in props)) return props;
|
|
7
|
+
const { title, ...rest } = props;
|
|
8
|
+
if (typeof document !== "undefined") installTitleTooltips(document);
|
|
9
|
+
return { ...rest, "data-sia-title": title == null ? void 0 : String(title) };
|
|
10
|
+
}
|
|
11
|
+
function installTitleTooltips(doc) {
|
|
12
|
+
if (documents.has(doc)) return;
|
|
13
|
+
documents.add(doc);
|
|
14
|
+
let hovered = null;
|
|
15
|
+
let focused = null;
|
|
16
|
+
let active = null;
|
|
17
|
+
let pending = null;
|
|
18
|
+
let timer;
|
|
19
|
+
let root;
|
|
20
|
+
let observer;
|
|
21
|
+
let tooltipId = "";
|
|
22
|
+
const candidate = (target) => {
|
|
23
|
+
if (!(target instanceof Element)) return null;
|
|
24
|
+
const element = target.closest("[data-sia-title]");
|
|
25
|
+
return element?.getAttribute("data-sia-title") && !element.closest(".sia-floating") ? element : null;
|
|
26
|
+
};
|
|
27
|
+
const hasExplicitTooltip = (target) => target instanceof Element && Boolean(target.closest(".sia-floating"));
|
|
28
|
+
const hide = () => {
|
|
29
|
+
clearTimeout(timer);
|
|
30
|
+
pending = null;
|
|
31
|
+
observer?.disconnect();
|
|
32
|
+
observer = void 0;
|
|
33
|
+
if (active) {
|
|
34
|
+
const ids = (active.getAttribute("aria-describedby") ?? "").split(/\s+/).filter((id) => id && id !== tooltipId);
|
|
35
|
+
if (ids.length) active.setAttribute("aria-describedby", ids.join(" "));
|
|
36
|
+
else active.removeAttribute("aria-describedby");
|
|
37
|
+
}
|
|
38
|
+
active = null;
|
|
39
|
+
root?.render(null);
|
|
40
|
+
};
|
|
41
|
+
const render = () => {
|
|
42
|
+
const text = active?.getAttribute("data-sia-title");
|
|
43
|
+
if (!active?.isConnected || !text) {
|
|
44
|
+
hide();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
if (!root) {
|
|
48
|
+
const host = doc.createElement("div");
|
|
49
|
+
host.setAttribute("data-sia-title-tooltip-host", "");
|
|
50
|
+
doc.body.append(host);
|
|
51
|
+
root = createRoot(host);
|
|
52
|
+
tooltipId = `sia-title-tooltip-${Math.random().toString(36).slice(2)}`;
|
|
53
|
+
}
|
|
54
|
+
const ids = new Set((active.getAttribute("aria-describedby") ?? "").split(/\s+/).filter(Boolean));
|
|
55
|
+
ids.add(tooltipId);
|
|
56
|
+
active.setAttribute("aria-describedby", [...ids].join(" "));
|
|
57
|
+
root.render(/* @__PURE__ */ jsx(
|
|
58
|
+
PopupPortal,
|
|
59
|
+
{
|
|
60
|
+
anchorRef: { current: active },
|
|
61
|
+
placement: "top-start",
|
|
62
|
+
id: tooltipId,
|
|
63
|
+
role: "tooltip",
|
|
64
|
+
className: "sia-title-tooltip",
|
|
65
|
+
children: text
|
|
66
|
+
}
|
|
67
|
+
));
|
|
68
|
+
};
|
|
69
|
+
const show = (element) => {
|
|
70
|
+
if (!element && !active && !pending) return;
|
|
71
|
+
if (element && (element === active || element === pending)) return;
|
|
72
|
+
hide();
|
|
73
|
+
if (!element) return;
|
|
74
|
+
pending = element;
|
|
75
|
+
timer = setTimeout(() => {
|
|
76
|
+
pending = null;
|
|
77
|
+
if (!element.isConnected) return;
|
|
78
|
+
active = element;
|
|
79
|
+
render();
|
|
80
|
+
if (!active) return;
|
|
81
|
+
observer = new MutationObserver(() => {
|
|
82
|
+
if (!active?.isConnected) hide();
|
|
83
|
+
else if (active.getAttribute("data-sia-title") !== doc.getElementById(tooltipId)?.textContent) render();
|
|
84
|
+
});
|
|
85
|
+
observer.observe(doc.body, { childList: true, subtree: true, attributes: true, attributeFilter: ["data-sia-title"] });
|
|
86
|
+
}, 600);
|
|
87
|
+
};
|
|
88
|
+
doc.addEventListener("pointerover", (event) => {
|
|
89
|
+
if (event.pointerType === "touch") return;
|
|
90
|
+
hovered = candidate(event.target);
|
|
91
|
+
if (hasExplicitTooltip(event.target)) hide();
|
|
92
|
+
else show(hovered ?? focused);
|
|
93
|
+
}, true);
|
|
94
|
+
doc.addEventListener("pointermove", (event) => {
|
|
95
|
+
if (event.pointerType === "touch" || event.buttons) return;
|
|
96
|
+
hovered = candidate(event.target);
|
|
97
|
+
if (!hasExplicitTooltip(event.target)) show(hovered ?? focused);
|
|
98
|
+
}, true);
|
|
99
|
+
doc.addEventListener("pointerout", (event) => {
|
|
100
|
+
if (event.pointerType === "touch") return;
|
|
101
|
+
hovered = candidate(event.relatedTarget);
|
|
102
|
+
if (hasExplicitTooltip(event.relatedTarget)) hide();
|
|
103
|
+
else show(hovered ?? focused);
|
|
104
|
+
}, true);
|
|
105
|
+
doc.addEventListener("focusin", (event) => {
|
|
106
|
+
focused = candidate(event.target);
|
|
107
|
+
if (hasExplicitTooltip(event.target)) hide();
|
|
108
|
+
else show(focused ?? hovered);
|
|
109
|
+
}, true);
|
|
110
|
+
doc.addEventListener("focusout", (event) => {
|
|
111
|
+
focused = candidate(event.relatedTarget);
|
|
112
|
+
show(hovered ?? focused);
|
|
113
|
+
}, true);
|
|
114
|
+
doc.addEventListener("pointerdown", hide, true);
|
|
115
|
+
doc.addEventListener("keydown", (event) => {
|
|
116
|
+
if (event.key === "Escape") hide();
|
|
117
|
+
}, true);
|
|
118
|
+
doc.addEventListener("scroll", hide, true);
|
|
119
|
+
doc.defaultView?.addEventListener("blur", () => {
|
|
120
|
+
hovered = focused = null;
|
|
121
|
+
hide();
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// src/components/PopupPortal.tsx
|
|
126
|
+
import { forwardRef, useLayoutEffect, useRef, useState } from "react";
|
|
127
|
+
import { createPortal } from "react-dom";
|
|
128
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
129
|
+
function setForwardedRef(ref, value) {
|
|
130
|
+
if (typeof ref === "function") ref(value);
|
|
131
|
+
else if (ref) ref.current = value;
|
|
132
|
+
}
|
|
133
|
+
function clamp(value, min, max) {
|
|
134
|
+
return Math.min(Math.max(value, min), Math.max(min, max));
|
|
135
|
+
}
|
|
136
|
+
var PopupPortal = forwardRef(function PopupPortal2({
|
|
137
|
+
anchorRef,
|
|
138
|
+
open = true,
|
|
139
|
+
placement = "bottom-start",
|
|
140
|
+
offset = 6,
|
|
141
|
+
viewportPadding = 8,
|
|
142
|
+
className = "",
|
|
143
|
+
style,
|
|
144
|
+
children,
|
|
145
|
+
...props
|
|
146
|
+
}, forwardedRef) {
|
|
147
|
+
const popupRef = useRef(null);
|
|
148
|
+
const [position, setPosition] = useState();
|
|
149
|
+
useLayoutEffect(() => {
|
|
150
|
+
if (!open || typeof document === "undefined") {
|
|
151
|
+
setPosition(void 0);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const update = () => {
|
|
155
|
+
const anchor = anchorRef.current;
|
|
156
|
+
const popup = popupRef.current;
|
|
157
|
+
if (!anchor || !popup) return;
|
|
158
|
+
const anchorRect = anchor.getBoundingClientRect();
|
|
159
|
+
const popupRect = popup.getBoundingClientRect();
|
|
160
|
+
const viewportWidth = document.documentElement.clientWidth;
|
|
161
|
+
const viewportHeight = document.documentElement.clientHeight;
|
|
162
|
+
let resolvedPlacement = placement;
|
|
163
|
+
const availableBelow = Math.max(0, viewportHeight - viewportPadding - anchorRect.bottom - offset);
|
|
164
|
+
const availableAbove = Math.max(0, anchorRect.top - offset - viewportPadding);
|
|
165
|
+
const availableRight = Math.max(0, viewportWidth - viewportPadding - anchorRect.right - offset);
|
|
166
|
+
const availableLeft = Math.max(0, anchorRect.left - offset - viewportPadding);
|
|
167
|
+
const horizontalSide = placement.startsWith("right") || placement.startsWith("left");
|
|
168
|
+
if (horizontalSide) {
|
|
169
|
+
const prefersRight = placement.startsWith("right");
|
|
170
|
+
const fitsRight = popupRect.width <= availableRight;
|
|
171
|
+
const fitsLeft = popupRect.width <= availableLeft;
|
|
172
|
+
if (prefersRight && !fitsRight && (fitsLeft || availableLeft > availableRight)) {
|
|
173
|
+
resolvedPlacement = placement.replace("right", "left");
|
|
174
|
+
} else if (!prefersRight && !fitsLeft && (fitsRight || availableRight > availableLeft)) {
|
|
175
|
+
resolvedPlacement = placement.replace("left", "right");
|
|
176
|
+
}
|
|
177
|
+
} else {
|
|
178
|
+
const prefersBottom = placement.startsWith("bottom");
|
|
179
|
+
const fitsBelow = popupRect.height <= availableBelow;
|
|
180
|
+
const fitsAbove = popupRect.height <= availableAbove;
|
|
181
|
+
if (prefersBottom && !fitsBelow && (fitsAbove || availableAbove > availableBelow)) {
|
|
182
|
+
resolvedPlacement = placement.replace("bottom", "top");
|
|
183
|
+
} else if (!prefersBottom && !fitsAbove && (fitsBelow || availableBelow > availableAbove)) {
|
|
184
|
+
resolvedPlacement = placement.replace("top", "bottom");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const resolvedHorizontalSide = resolvedPlacement.startsWith("right") || resolvedPlacement.startsWith("left");
|
|
188
|
+
const top = resolvedHorizontalSide ? resolvedPlacement.endsWith("end") ? anchorRect.bottom - popupRect.height : anchorRect.top : resolvedPlacement.startsWith("bottom") ? anchorRect.bottom + offset : anchorRect.top - popupRect.height - offset;
|
|
189
|
+
const availableHeight = resolvedHorizontalSide ? Math.max(0, viewportHeight - viewportPadding * 2) : resolvedPlacement.startsWith("bottom") ? availableBelow : availableAbove;
|
|
190
|
+
const alignedLeft = resolvedHorizontalSide ? resolvedPlacement.startsWith("right") ? anchorRect.right + offset : anchorRect.left - popupRect.width - offset : resolvedPlacement.endsWith("end") ? anchorRect.right - popupRect.width : anchorRect.left;
|
|
191
|
+
const next = {
|
|
192
|
+
top: clamp(top, viewportPadding, viewportHeight - popupRect.height - viewportPadding),
|
|
193
|
+
left: clamp(alignedLeft, viewportPadding, viewportWidth - popupRect.width - viewportPadding),
|
|
194
|
+
anchorWidth: anchorRect.width,
|
|
195
|
+
availableHeight,
|
|
196
|
+
placement: resolvedPlacement
|
|
197
|
+
};
|
|
198
|
+
setPosition((current) => current && current.top === next.top && current.left === next.left && current.anchorWidth === next.anchorWidth && current.availableHeight === next.availableHeight && current.placement === next.placement ? current : next);
|
|
199
|
+
};
|
|
200
|
+
update();
|
|
201
|
+
window.addEventListener("resize", update);
|
|
202
|
+
window.addEventListener("scroll", update, true);
|
|
203
|
+
const observer = new ResizeObserver(update);
|
|
204
|
+
if (anchorRef.current) observer.observe(anchorRef.current);
|
|
205
|
+
if (popupRef.current) observer.observe(popupRef.current);
|
|
206
|
+
return () => {
|
|
207
|
+
window.removeEventListener("resize", update);
|
|
208
|
+
window.removeEventListener("scroll", update, true);
|
|
209
|
+
observer.disconnect();
|
|
210
|
+
};
|
|
211
|
+
}, [anchorRef, offset, open, placement, viewportPadding]);
|
|
212
|
+
if (!open || typeof document === "undefined") return null;
|
|
213
|
+
return createPortal(
|
|
214
|
+
/* @__PURE__ */ jsx2(
|
|
215
|
+
"div",
|
|
216
|
+
{
|
|
217
|
+
ref: (node) => {
|
|
218
|
+
popupRef.current = node;
|
|
219
|
+
setForwardedRef(forwardedRef, node);
|
|
220
|
+
},
|
|
221
|
+
className: `sia-popup-portal ${className}`.trim(),
|
|
222
|
+
"data-sia-popup-layer": "",
|
|
223
|
+
"data-placement": position?.placement ?? placement,
|
|
224
|
+
style: {
|
|
225
|
+
...style,
|
|
226
|
+
"--sia-popup-anchor-width": `${position?.anchorWidth ?? anchorRef.current?.getBoundingClientRect().width ?? 0}px`,
|
|
227
|
+
"--sia-popup-available-height": position ? `${position.availableHeight}px` : void 0,
|
|
228
|
+
top: position?.top ?? 0,
|
|
229
|
+
left: position?.left ?? 0,
|
|
230
|
+
visibility: position ? "visible" : "hidden"
|
|
231
|
+
},
|
|
232
|
+
...withTitleTooltip(props),
|
|
233
|
+
children
|
|
234
|
+
}
|
|
235
|
+
),
|
|
236
|
+
document.body
|
|
237
|
+
);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// src/components/shared.ts
|
|
241
|
+
import { createContext, useCallback, useContext, useState as useState2 } from "react";
|
|
242
|
+
var ControlSizeContext = createContext("medium");
|
|
243
|
+
function useControlSize(size) {
|
|
244
|
+
const inherited = useContext(ControlSizeContext);
|
|
245
|
+
return size ?? inherited;
|
|
246
|
+
}
|
|
247
|
+
var PlaceholderModeContext = createContext("default");
|
|
248
|
+
function usePlaceholderMode(mode) {
|
|
249
|
+
const inherited = useContext(PlaceholderModeContext);
|
|
250
|
+
return mode ?? inherited;
|
|
251
|
+
}
|
|
252
|
+
function useControllableState({ value, defaultValue, onChange }) {
|
|
253
|
+
const [internalValue, setInternalValue] = useState2(defaultValue);
|
|
254
|
+
const controlled = value !== void 0;
|
|
255
|
+
const currentValue = controlled ? value : internalValue;
|
|
256
|
+
const setValue = useCallback((nextValue) => {
|
|
257
|
+
if (Object.is(currentValue, nextValue)) return;
|
|
258
|
+
if (!controlled) setInternalValue(nextValue);
|
|
259
|
+
onChange?.(nextValue);
|
|
260
|
+
}, [controlled, currentValue, onChange]);
|
|
261
|
+
return [currentValue, setValue];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// src/components/FloatingPlaceholder.tsx
|
|
265
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
266
|
+
function useFloatingPlaceholder({ mode, placeholder, filled, active = false }) {
|
|
267
|
+
const enabled = usePlaceholderMode(mode) === "floating" && Boolean(placeholder);
|
|
268
|
+
return {
|
|
269
|
+
enabled,
|
|
270
|
+
className: enabled ? ` sia-placeholder-floating${filled ? " sia-placeholder-floating--filled" : ""}${active ? " sia-placeholder-floating--active" : ""}` : "",
|
|
271
|
+
label: enabled ? /* @__PURE__ */ jsx3("span", { className: "sia-floating-placeholder", "aria-hidden": "true", children: placeholder }) : null
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
export {
|
|
276
|
+
PopupPortal,
|
|
277
|
+
withTitleTooltip,
|
|
278
|
+
ControlSizeContext,
|
|
279
|
+
useControlSize,
|
|
280
|
+
PlaceholderModeContext,
|
|
281
|
+
usePlaceholderMode,
|
|
282
|
+
useControllableState,
|
|
283
|
+
useFloatingPlaceholder
|
|
284
|
+
};
|
|
@@ -2,13 +2,14 @@ import {
|
|
|
2
2
|
Dropdown,
|
|
3
3
|
Icon,
|
|
4
4
|
Input
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-27ZYAKII.js";
|
|
6
6
|
import {
|
|
7
7
|
Button
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-IYNS423D.js";
|
|
9
9
|
import {
|
|
10
|
-
useFloatingPlaceholder
|
|
11
|
-
|
|
10
|
+
useFloatingPlaceholder,
|
|
11
|
+
withTitleTooltip
|
|
12
|
+
} from "./chunk-RAO3JHDL.js";
|
|
12
13
|
|
|
13
14
|
// src/components/RichTextEditor.tsx
|
|
14
15
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
@@ -42,7 +43,7 @@ function sanitizeContent(value) {
|
|
|
42
43
|
function RichTextContent({ content, emptyText = "\u6682\u65E0\u5185\u5BB9", className = "", ...props }) {
|
|
43
44
|
const html = useMemo(() => sanitizeContent(content), [content]);
|
|
44
45
|
if (!html.trim()) return /* @__PURE__ */ jsx("div", { className: `sia-rich-text-content sia-rich-text-content--empty ${className}`.trim(), children: emptyText });
|
|
45
|
-
return /* @__PURE__ */ jsx("article", { className: `sia-rich-text-content ${className}`.trim(), dangerouslySetInnerHTML: { __html: html }, ...props });
|
|
46
|
+
return /* @__PURE__ */ jsx("article", { className: `sia-rich-text-content ${className}`.trim(), dangerouslySetInnerHTML: { __html: html }, ...withTitleTooltip(props) });
|
|
46
47
|
}
|
|
47
48
|
function RichTextEditor({
|
|
48
49
|
value,
|
|
@@ -222,7 +223,7 @@ function RichTextEditor({
|
|
|
222
223
|
}
|
|
223
224
|
};
|
|
224
225
|
const floating = useFloatingPlaceholder({ mode: placeholderMode, placeholder, filled: editor ? !editor.isEmpty : Boolean(value ?? defaultValue) });
|
|
225
|
-
return /* @__PURE__ */ jsxs("div", { ...props, id, style: mergedStyle, className: `sia-rich-text-editor${floating.className}${disabled ? " is-disabled" : ""} sia-rich-text-editor--${toolbar} ${className}`.trim(), children: [
|
|
226
|
+
return /* @__PURE__ */ jsxs("div", { ...withTitleTooltip(props), id, style: mergedStyle, className: `sia-rich-text-editor${floating.className}${disabled ? " is-disabled" : ""} sia-rich-text-editor--${toolbar} ${className}`.trim(), children: [
|
|
226
227
|
floating.label,
|
|
227
228
|
/* @__PURE__ */ jsxs("div", { className: "sia-rich-text-editor__toolbar", "aria-label": "\u6587\u672C\u683C\u5F0F\u5DE5\u5177\u680F", children: [
|
|
228
229
|
/* @__PURE__ */ jsxs("div", { className: "sia-rich-text-editor__toolbar-main", children: [
|