@tensor_1/react 2.26.2 → 2.27.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.
Files changed (68) hide show
  1. package/README.md +51 -0
  2. package/dist/calendar-model.d.ts +4 -2
  3. package/dist/components/AppShell.d.ts +1 -1
  4. package/dist/components/AppShell.js +6 -2
  5. package/dist/components/Button.d.ts +28 -4
  6. package/dist/components/Button.js +19 -9
  7. package/dist/components/Card.d.ts +7 -1
  8. package/dist/components/Card.js +3 -3
  9. package/dist/components/Chip.d.ts +43 -0
  10. package/dist/components/Chip.js +73 -0
  11. package/dist/components/CollapsibleSection.d.ts +19 -1
  12. package/dist/components/CollapsibleSection.js +5 -2
  13. package/dist/components/CollapsibleSectionState.d.ts +11 -0
  14. package/dist/components/CollapsibleSectionState.js +67 -0
  15. package/dist/components/CommandPalette.d.ts +1 -1
  16. package/dist/components/CommandPalette.js +4 -1
  17. package/dist/components/DateRangePicker.js +3 -1
  18. package/dist/components/Dialogs.d.ts +54 -3
  19. package/dist/components/Dialogs.js +167 -6
  20. package/dist/components/Drawer.d.ts +6 -1
  21. package/dist/components/Drawer.js +5 -2
  22. package/dist/components/EmojiPicker.d.ts +3 -0
  23. package/dist/components/EmojiPicker.js +109 -54
  24. package/dist/components/Kbd.d.ts +27 -0
  25. package/dist/components/Kbd.js +45 -0
  26. package/dist/components/Menu.d.ts +51 -0
  27. package/dist/components/Menu.js +177 -0
  28. package/dist/components/Modal.d.ts +1 -1
  29. package/dist/components/Modal.js +4 -1
  30. package/dist/components/Pagination.d.ts +36 -5
  31. package/dist/components/Pagination.js +59 -37
  32. package/dist/components/Peek.d.ts +1 -1
  33. package/dist/components/Peek.js +6 -1
  34. package/dist/components/Popover.d.ts +15 -5
  35. package/dist/components/Popover.js +66 -6
  36. package/dist/components/SchedulingCalendar.d.ts +47 -2
  37. package/dist/components/SchedulingCalendar.js +69 -22
  38. package/dist/components/SearchSuggest.d.ts +1 -1
  39. package/dist/components/SearchSuggest.js +4 -1
  40. package/dist/components/Sidebar.d.ts +7 -2
  41. package/dist/components/Sidebar.js +15 -4
  42. package/dist/components/Stat.d.ts +16 -0
  43. package/dist/components/Stat.js +12 -5
  44. package/dist/components/Steps.d.ts +48 -0
  45. package/dist/components/Steps.js +42 -0
  46. package/dist/components/Toast.d.ts +2 -2
  47. package/dist/components/Toast.js +7 -2
  48. package/dist/components/Tooltip.d.ts +10 -4
  49. package/dist/components/Tooltip.js +2 -2
  50. package/dist/{emoji-image-WQLh8ZQP.d.cts → emoji-image-6mPZ15Zy.d.cts} +4 -1
  51. package/dist/emoji.cjs +326 -76
  52. package/dist/emoji.d.cts +3 -3
  53. package/dist/hooks/useAnchoredPosition.d.ts +13 -5
  54. package/dist/hooks/useAnchoredPosition.js +146 -15
  55. package/dist/index.cjs +2278 -1372
  56. package/dist/index.d.cts +622 -176
  57. package/dist/index.d.ts +10 -4
  58. package/dist/index.js +24 -2
  59. package/dist/labels-context.d.ts +72 -0
  60. package/dist/labels-context.js +23 -0
  61. package/dist/link.d.ts +20 -0
  62. package/dist/link.js +9 -0
  63. package/dist/{overlay-position-CEGSz6Z2.d.cts → overlay-position-Cjv5E7mn.d.cts} +7 -0
  64. package/dist/overlay-position.d.ts +7 -0
  65. package/dist/overlay-position.js +7 -2
  66. package/dist/rich-text.cjs +324 -74
  67. package/dist/rich-text.d.cts +3 -3
  68. package/package.json +1 -1
@@ -2,43 +2,174 @@
2
2
  import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
3
3
  import { computePosition } from "../overlay-position.js";
4
4
  const useIsomorphicLayoutEffect = typeof document !== "undefined" ? useLayoutEffect : useEffect;
5
- const resolve = (a) => a && typeof a === "object" && "current" in a ? a.current : a ?? null;
5
+ const resolveAnchor = (a) => a && typeof a === "object" && "current" in a ? a.current : a ?? null;
6
+ let anchoringSupported;
7
+ function supportsAnchoring() {
8
+ if (anchoringSupported === void 0) {
9
+ try {
10
+ const css = typeof CSS !== "undefined" ? CSS : void 0;
11
+ anchoringSupported = !!css && typeof css.supports === "function" && css.supports("anchor-name", "--uix-a") && css.supports("position-anchor", "--uix-a") && css.supports("top", "round(anchor(bottom) + 1px, 1px)");
12
+ } catch {
13
+ anchoringSupported = false;
14
+ }
15
+ }
16
+ return anchoringSupported;
17
+ }
18
+ let anchorCount = 0;
19
+ const namesOf = (value) => value.split(",").map((n) => n.trim()).filter((n) => n.startsWith("--"));
20
+ function addAnchorName(el, name) {
21
+ const names = namesOf(getComputedStyle(el).getPropertyValue("anchor-name"));
22
+ if (!names.includes(name)) names.push(name);
23
+ el.style.setProperty("anchor-name", names.join(", "));
24
+ }
25
+ function removeAnchorName(el, name) {
26
+ const names = namesOf(el.style.getPropertyValue("anchor-name")).filter((n) => n !== name);
27
+ if (names.length) el.style.setProperty("anchor-name", names.join(", "));
28
+ else el.style.removeProperty("anchor-name");
29
+ }
30
+ function translationOf(el) {
31
+ const t = getComputedStyle(el).transform;
32
+ if (!t || t === "none" || typeof DOMMatrixReadOnly === "undefined") return { x: 0, y: 0 };
33
+ try {
34
+ const m = new DOMMatrixReadOnly(t);
35
+ return { x: m.m41, y: m.m42 };
36
+ } catch {
37
+ return { x: 0, y: 0 };
38
+ }
39
+ }
40
+ const signed = (n) => `${n < 0 ? "-" : "+"} ${Math.round(Math.abs(n) * 100) / 100}px`;
41
+ const prepared = /* @__PURE__ */ new WeakSet();
6
42
  function useAnchoredPosition(anchor, floatingRef, { open, placement = "bottom-start", offset = 6, padding = 8 }) {
7
43
  const opts = useRef({ placement, offset, padding });
8
44
  opts.current = { placement, offset, padding };
45
+ const session = useRef(false);
46
+ const side = useRef(null);
47
+ const written = useRef("");
48
+ const anchoring = useRef(null);
49
+ const anchoringFailed = useRef(false);
50
+ const anchorName = useRef("");
51
+ const release = useCallback((keepPlace) => {
52
+ const current = anchoring.current;
53
+ if (!current) return;
54
+ anchoring.current = null;
55
+ written.current = "";
56
+ const floating = floatingRef.current;
57
+ if (floating) {
58
+ const s = floating.style;
59
+ if (keepPlace && current.anchor.isConnected) {
60
+ const a = current.anchor.getBoundingClientRect();
61
+ s.top = `${Math.round((current.yEdge === "bottom" ? a.bottom : a.top) + current.dy)}px`;
62
+ s.left = `${Math.round((current.xEdge === "right" ? a.right : a.left) + current.dx)}px`;
63
+ }
64
+ s.removeProperty("position-anchor");
65
+ }
66
+ removeAnchorName(current.anchor, current.name);
67
+ }, [floatingRef]);
9
68
  const reposition = useCallback(() => {
10
- const anchorEl = resolve(anchor);
69
+ const anchorEl = resolveAnchor(anchor);
11
70
  const floating = floatingRef.current;
12
71
  if (!anchorEl || !floating) return;
13
72
  const s = floating.style;
14
- s.position = "fixed";
15
- s.inset = "auto";
16
- s.margin = "0";
73
+ if (!prepared.has(floating)) {
74
+ s.position = "fixed";
75
+ s.inset = "auto";
76
+ s.margin = "0";
77
+ prepared.add(floating);
78
+ written.current = "";
79
+ }
17
80
  const a = anchorEl.getBoundingClientRect();
81
+ const size = { width: floating.offsetWidth, height: floating.offsetHeight };
18
82
  const { placement: p, offset: o, padding: pad } = opts.current;
19
83
  const pos = computePosition(
20
84
  { x: a.x, y: a.y, width: a.width, height: a.height },
21
- { width: floating.offsetWidth, height: floating.offsetHeight },
85
+ size,
22
86
  { width: window.innerWidth, height: window.innerHeight },
23
- { placement: p, offset: o, padding: pad }
87
+ { placement: p, offset: o, padding: pad, stickySide: side.current ?? void 0 }
24
88
  );
25
- s.left = `${Math.round(pos.x)}px`;
26
- s.top = `${Math.round(pos.y)}px`;
27
- floating.dataset.placement = pos.placement;
28
- }, [anchor, floatingRef]);
89
+ const measured = size.width > 0 || size.height > 0;
90
+ if (measured && session.current) side.current = pos.side;
91
+ if (floating.dataset.placement !== pos.placement) floating.dataset.placement = pos.placement;
92
+ const writeFixed = (at) => {
93
+ const left2 = `${Math.round(at.x)}px`;
94
+ const top2 = `${Math.round(at.y)}px`;
95
+ const key2 = `fixed ${left2} ${top2}`;
96
+ if (key2 === written.current) return;
97
+ s.left = left2;
98
+ s.top = top2;
99
+ written.current = key2;
100
+ };
101
+ if (anchoringFailed.current || !supportsAnchoring()) {
102
+ writeFixed(pos);
103
+ return;
104
+ }
105
+ if (anchoring.current && anchoring.current.anchor !== anchorEl) release(false);
106
+ if (!anchoring.current) {
107
+ anchorName.current || (anchorName.current = `--uix-anchor-${++anchorCount}`);
108
+ addAnchorName(anchorEl, anchorName.current);
109
+ s.setProperty("position-anchor", anchorName.current);
110
+ anchoring.current = { anchor: anchorEl, name: anchorName.current, yEdge: "bottom", xEdge: "left", dy: 0, dx: 0, verified: false };
111
+ written.current = "";
112
+ }
113
+ const current = anchoring.current;
114
+ current.yEdge = pos.side === "bottom" ? "bottom" : "top";
115
+ current.xEdge = pos.side === "right" ? "right" : "left";
116
+ current.dy = pos.y - (current.yEdge === "bottom" ? a.bottom : a.top);
117
+ current.dx = pos.x - (current.xEdge === "right" ? a.right : a.left);
118
+ const top = `round(anchor(${current.yEdge}) ${signed(current.dy)}, 1px)`;
119
+ const left = `round(anchor(${current.xEdge}) ${signed(current.dx)}, 1px)`;
120
+ const key = `anchored ${top} ${left}`;
121
+ if (key !== written.current) {
122
+ s.top = top;
123
+ s.left = left;
124
+ written.current = key;
125
+ }
126
+ if (!current.verified && measured) {
127
+ current.verified = true;
128
+ const box = floating.getBoundingClientRect();
129
+ const t = translationOf(floating);
130
+ const dxc = box.left + box.width / 2 - t.x - (pos.x + size.width / 2);
131
+ const dyc = box.top + box.height / 2 - t.y - (pos.y + size.height / 2);
132
+ if (Math.abs(dxc) > 2 || Math.abs(dyc) > 2) {
133
+ anchoringFailed.current = true;
134
+ release(false);
135
+ writeFixed(pos);
136
+ }
137
+ }
138
+ }, [anchor, floatingRef, release]);
29
139
  useIsomorphicLayoutEffect(() => {
30
140
  if (!open) return;
141
+ session.current = true;
31
142
  reposition();
32
- const onScroll = () => reposition();
143
+ const anchorEl = resolveAnchor(anchor);
144
+ const floating = floatingRef.current;
145
+ const onScroll = (event) => {
146
+ const target = event.target;
147
+ if (target && typeof target.contains === "function") {
148
+ if (floating?.contains(target)) return;
149
+ if (anchorEl && !target.contains(anchorEl)) return;
150
+ }
151
+ reposition();
152
+ };
153
+ const onResize = () => reposition();
33
154
  window.addEventListener("scroll", onScroll, { passive: true, capture: true });
34
- window.addEventListener("resize", onScroll);
155
+ window.addEventListener("resize", onResize);
156
+ const observer = typeof ResizeObserver === "function" ? new ResizeObserver(() => reposition()) : null;
157
+ if (floating) observer?.observe(floating);
158
+ if (anchorEl) observer?.observe(anchorEl);
35
159
  return () => {
36
160
  window.removeEventListener("scroll", onScroll, true);
37
- window.removeEventListener("resize", onScroll);
161
+ window.removeEventListener("resize", onResize);
162
+ observer?.disconnect();
163
+ session.current = false;
164
+ side.current = null;
165
+ anchoringFailed.current = false;
166
+ release(true);
38
167
  };
39
- }, [open, reposition]);
168
+ }, [open, reposition, anchor, floatingRef, release]);
169
+ useEffect(() => () => release(false), [release]);
40
170
  return reposition;
41
171
  }
42
172
  export {
173
+ resolveAnchor,
43
174
  useAnchoredPosition
44
175
  };