@tensor_1/react 2.40.2 → 2.42.0
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/components/Button.d.ts +19 -1
- package/dist/components/Button.js +13 -8
- package/dist/components/DescriptionList.d.ts +11 -0
- package/dist/components/DiscardPrompt.d.ts +54 -0
- package/dist/components/DiscardPrompt.js +245 -0
- package/dist/components/Drawer.d.ts +19 -3
- package/dist/components/Drawer.js +60 -21
- package/dist/components/EditorialHome.d.ts +1 -1
- package/dist/components/Field.d.ts +7 -1
- package/dist/components/Field.js +5 -4
- package/dist/components/Input.d.ts +5 -0
- package/dist/components/Input.js +2 -1
- package/dist/components/Kbd.d.ts +20 -1
- package/dist/components/Kbd.js +30 -7
- package/dist/components/Menu.d.ts +11 -4
- package/dist/components/Menu.js +17 -3
- package/dist/components/MetricInput.d.ts +8 -1
- package/dist/components/MetricInput.js +11 -3
- package/dist/components/Modal.d.ts +15 -1
- package/dist/components/Modal.js +58 -13
- package/dist/components/SearchBar.d.ts +67 -0
- package/dist/components/SearchBar.js +117 -0
- package/dist/components/Select.js +5 -4
- package/dist/components/ShortcutHint.d.ts +29 -0
- package/dist/components/ShortcutHint.js +149 -0
- package/dist/components/Table.d.ts +7 -1
- package/dist/components/Table.js +2 -0
- package/dist/components/Tooltip.d.ts +10 -1
- package/dist/components/Tooltip.js +15 -4
- package/dist/emoji.cjs +108 -31
- package/dist/hooks/useAnchoredPosition.d.ts +13 -1
- package/dist/hooks/useAnchoredPosition.js +19 -11
- package/dist/hooks/useDialog.d.ts +6 -1
- package/dist/hooks/useDialog.js +10 -1
- package/dist/index.cjs +3186 -2521
- package/dist/index.d.cts +228 -40
- package/dist/index.d.ts +3 -1
- package/dist/index.js +6 -1
- package/dist/labels-context.d.ts +8 -0
- package/dist/rich-text.cjs +17 -10
- package/package.json +1 -1
|
@@ -33,11 +33,16 @@ function translationOf(el) {
|
|
|
33
33
|
if (!t || t === "none" || typeof DOMMatrixReadOnly === "undefined") return { x: 0, y: 0 };
|
|
34
34
|
try {
|
|
35
35
|
const m = new DOMMatrixReadOnly(t);
|
|
36
|
-
|
|
36
|
+
const z = zoomOf(el);
|
|
37
|
+
return { x: m.m41 * z, y: m.m42 * z };
|
|
37
38
|
} catch {
|
|
38
39
|
return { x: 0, y: 0 };
|
|
39
40
|
}
|
|
40
41
|
}
|
|
42
|
+
function zoomOf(el) {
|
|
43
|
+
const z = el.currentCSSZoom;
|
|
44
|
+
return typeof z === "number" && Number.isFinite(z) && z > 0 ? z : 1;
|
|
45
|
+
}
|
|
41
46
|
const signed = (n) => `${n < 0 ? "-" : "+"} ${Math.round(Math.abs(n) * 100) / 100}px`;
|
|
42
47
|
const prepared = /* @__PURE__ */ new WeakSet();
|
|
43
48
|
function useAnchoredPosition(anchor, floatingRef, { open, placement = "bottom-start", offset = 6, padding = 8, shiftMainAxis = true, capHeight = false, onAnchorHidden }) {
|
|
@@ -62,8 +67,9 @@ function useAnchoredPosition(anchor, floatingRef, { open, placement = "bottom-st
|
|
|
62
67
|
const s = floating.style;
|
|
63
68
|
if (keepPlace && current.anchor.isConnected) {
|
|
64
69
|
const a = current.anchor.getBoundingClientRect();
|
|
65
|
-
|
|
66
|
-
s.
|
|
70
|
+
const z = zoomOf(floating);
|
|
71
|
+
s.top = `${Math.round(((current.yEdge === "bottom" ? a.bottom : a.top) + current.dy) / z)}px`;
|
|
72
|
+
s.left = `${Math.round(((current.xEdge === "right" ? a.right : a.left) + current.dx) / z)}px`;
|
|
67
73
|
}
|
|
68
74
|
s.removeProperty("position-anchor");
|
|
69
75
|
}
|
|
@@ -91,6 +97,7 @@ function useAnchoredPosition(anchor, floatingRef, { open, placement = "bottom-st
|
|
|
91
97
|
written.current = "";
|
|
92
98
|
}
|
|
93
99
|
const { placement: p, offset: o, padding: pad, shiftMainAxis: keepInView, capHeight: cap } = opts.current;
|
|
100
|
+
const zoom = floating.getClientRects().length > 0 ? zoomOf(floating) : zoomOf(anchorEl);
|
|
94
101
|
if (cap) {
|
|
95
102
|
if (!heightCap.current) {
|
|
96
103
|
const own = getComputedStyle(floating);
|
|
@@ -104,7 +111,7 @@ function useAnchoredPosition(anchor, floatingRef, { open, placement = "bottom-st
|
|
|
104
111
|
};
|
|
105
112
|
if (setOverflow) s.overflowY = "auto";
|
|
106
113
|
}
|
|
107
|
-
const room = `${Math.max(0, window.innerHeight - 2 * pad)}px`;
|
|
114
|
+
const room = `${Math.max(0, (window.innerHeight - 2 * pad * zoom) / zoom)}px`;
|
|
108
115
|
const max = heightCap.current.ownMaxHeight ? `min(${room}, ${heightCap.current.ownMaxHeight})` : room;
|
|
109
116
|
if (max !== heightCap.current.written) {
|
|
110
117
|
s.maxHeight = max;
|
|
@@ -114,19 +121,19 @@ function useAnchoredPosition(anchor, floatingRef, { open, placement = "bottom-st
|
|
|
114
121
|
uncap();
|
|
115
122
|
}
|
|
116
123
|
const a = anchorEl.getBoundingClientRect();
|
|
117
|
-
const size = { width: floating.offsetWidth, height: floating.offsetHeight };
|
|
124
|
+
const size = { width: floating.offsetWidth * zoom, height: floating.offsetHeight * zoom };
|
|
118
125
|
const pos = computePosition(
|
|
119
126
|
{ x: a.x, y: a.y, width: a.width, height: a.height },
|
|
120
127
|
size,
|
|
121
128
|
{ width: window.innerWidth, height: window.innerHeight },
|
|
122
|
-
{ placement: p, offset: o, padding: pad, shiftMainAxis: keepInView, stickySide: side.current ?? void 0 }
|
|
129
|
+
{ placement: p, offset: o * zoom, padding: pad * zoom, shiftMainAxis: keepInView, stickySide: side.current ?? void 0 }
|
|
123
130
|
);
|
|
124
131
|
const measured = size.width > 0 || size.height > 0;
|
|
125
132
|
if (measured && session.current) side.current = pos.side;
|
|
126
133
|
if (floating.dataset.placement !== pos.placement) floating.dataset.placement = pos.placement;
|
|
127
134
|
const writeFixed = (at) => {
|
|
128
|
-
const left2 = `${Math.round(at.x)}px`;
|
|
129
|
-
const top2 = `${Math.round(at.y)}px`;
|
|
135
|
+
const left2 = `${Math.round(at.x / zoom)}px`;
|
|
136
|
+
const top2 = `${Math.round(at.y / zoom)}px`;
|
|
130
137
|
const key2 = `fixed ${left2} ${top2}`;
|
|
131
138
|
if (key2 === written.current) return;
|
|
132
139
|
s.left = left2;
|
|
@@ -153,8 +160,8 @@ function useAnchoredPosition(anchor, floatingRef, { open, placement = "bottom-st
|
|
|
153
160
|
current.xEdge = pos.side === "right" ? "right" : "left";
|
|
154
161
|
current.dy = pos.y - (current.yEdge === "bottom" ? a.bottom : a.top);
|
|
155
162
|
current.dx = pos.x - (current.xEdge === "right" ? a.right : a.left);
|
|
156
|
-
const top = `round(anchor(${current.yEdge}) ${signed(current.dy)}, 1px)`;
|
|
157
|
-
const left = `round(anchor(${current.xEdge}) ${signed(current.dx)}, 1px)`;
|
|
163
|
+
const top = `round(anchor(${current.yEdge}) ${signed(current.dy / zoom)}, 1px)`;
|
|
164
|
+
const left = `round(anchor(${current.xEdge}) ${signed(current.dx / zoom)}, 1px)`;
|
|
158
165
|
const key = `anchored ${top} ${left}`;
|
|
159
166
|
if (key !== written.current) {
|
|
160
167
|
s.top = top;
|
|
@@ -221,5 +228,6 @@ function useAnchoredPosition(anchor, floatingRef, { open, placement = "bottom-st
|
|
|
221
228
|
}
|
|
222
229
|
export {
|
|
223
230
|
resolveAnchor,
|
|
224
|
-
useAnchoredPosition
|
|
231
|
+
useAnchoredPosition,
|
|
232
|
+
zoomOf
|
|
225
233
|
};
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* `keepOpen` is asked when the browser closed the dialog on its own (Escape or a close request
|
|
3
|
+
* nobody cancelled, a `method="dialog"` form). Returning `true` reopens it instead of calling
|
|
4
|
+
* `onClose`: a form dialog with unsaved input or a save in flight (HAR-2029).
|
|
5
|
+
*/
|
|
6
|
+
declare function useDialog(open: boolean, onClose?: () => void, keepOpen?: () => boolean): React.RefObject<HTMLDialogElement>;
|
|
2
7
|
|
|
3
8
|
export { useDialog };
|
package/dist/hooks/useDialog.js
CHANGED
|
@@ -30,10 +30,12 @@ function unlockBodyScroll() {
|
|
|
30
30
|
saved = null;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
function useDialog(open, onClose) {
|
|
33
|
+
function useDialog(open, onClose, keepOpen) {
|
|
34
34
|
const ref = useRef(null);
|
|
35
35
|
const onCloseRef = useRef(onClose);
|
|
36
36
|
onCloseRef.current = onClose;
|
|
37
|
+
const keepOpenRef = useRef(keepOpen);
|
|
38
|
+
keepOpenRef.current = keepOpen;
|
|
37
39
|
useEffect(() => {
|
|
38
40
|
const el = ref.current;
|
|
39
41
|
if (!el || !open) {
|
|
@@ -45,6 +47,13 @@ function useDialog(open, onClose) {
|
|
|
45
47
|
let locked = true;
|
|
46
48
|
const handleClose = () => {
|
|
47
49
|
if (el.open) return;
|
|
50
|
+
if (keepOpenRef.current?.()) {
|
|
51
|
+
try {
|
|
52
|
+
el.showModal();
|
|
53
|
+
return;
|
|
54
|
+
} catch {
|
|
55
|
+
}
|
|
56
|
+
}
|
|
48
57
|
if (locked) {
|
|
49
58
|
locked = false;
|
|
50
59
|
unlockBodyScroll();
|