@alexgorbatchev/shadcn 0.0.144 → 0.0.145

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.
@@ -104,6 +104,50 @@ function renderDefaultRow(row, props) {
104
104
  })
105
105
  }, row.id);
106
106
  }
107
+ function revealRow(viewport, row, focus) {
108
+ const keepInView = () => {
109
+ const header = viewport.querySelector("thead")?.getBoundingClientRect().height ?? 0;
110
+ const view = viewport.getBoundingClientRect();
111
+ const bounds = row.getBoundingClientRect();
112
+ const top = view.top + header;
113
+ const bottom = view.top + viewport.clientHeight;
114
+ if (bounds.top < top || bounds.height > bottom - top)
115
+ viewport.scrollTop += bounds.top - top;
116
+ else if (bounds.bottom > bottom)
117
+ viewport.scrollTop += bounds.bottom - bottom;
118
+ };
119
+ keepInView();
120
+ if (!focus)
121
+ return;
122
+ row.focus({ preventScroll: true });
123
+ const table = row.closest("table");
124
+ if (row.ownerDocument.activeElement !== row || !table)
125
+ return;
126
+ const input = new AbortController;
127
+ let frame = 0;
128
+ const schedule = () => {
129
+ if (frame)
130
+ return;
131
+ frame = requestAnimationFrame(() => {
132
+ frame = 0;
133
+ if (row === row.ownerDocument.activeElement)
134
+ keepInView();
135
+ });
136
+ };
137
+ const observer = new ResizeObserver(schedule);
138
+ const stop = () => {
139
+ cancelAnimationFrame(frame);
140
+ observer.disconnect();
141
+ input.abort();
142
+ };
143
+ for (const event of ["wheel", "pointerdown", "touchstart", "keydown"]) {
144
+ viewport.addEventListener(event, stop, { signal: input.signal, passive: true, capture: true });
145
+ }
146
+ row.addEventListener("blur", stop, { signal: input.signal });
147
+ viewport.addEventListener("scroll", schedule, { signal: input.signal, passive: true });
148
+ observer.observe(table);
149
+ return stop;
150
+ }
107
151
  function handleRowKeys(cursor, event) {
108
152
  if (event.target !== event.currentTarget || event.altKey)
109
153
  return;
@@ -168,15 +212,7 @@ function VirtualDataGrid({
168
212
  const row = viewport?.querySelector(`tr[data-row-id="${CSS.escape(reveal.rowId)}"]`);
169
213
  if (!viewport || !row)
170
214
  return;
171
- const header = viewport.querySelector("thead")?.getBoundingClientRect().height ?? 0;
172
- const view = viewport.getBoundingClientRect();
173
- const bounds = row.getBoundingClientRect();
174
- if (bounds.top < view.top + header)
175
- viewport.scrollTop -= view.top + header - bounds.top;
176
- else if (bounds.bottom > view.bottom)
177
- viewport.scrollTop += bounds.bottom - view.bottom;
178
- if (reveal.focus)
179
- row.focus({ preventScroll: true });
215
+ return revealRow(viewport, row, reveal.focus);
180
216
  }, [reveal]);
181
217
  const cursorProps = (row) => rowCursor ? {
182
218
  tabIndex: row.id === tabStop ? 0 : -1,
package/dist/prototype.js CHANGED
@@ -2051,7 +2051,7 @@ var program = new Command;
2051
2051
  // package.json
2052
2052
  var package_default = {
2053
2053
  name: "@alexgorbatchev/shadcn",
2054
- version: "0.0.144",
2054
+ version: "0.0.145",
2055
2055
  description: "Sharp, monospace React components with compact, comfortable, and touch densities.",
2056
2056
  license: "MIT",
2057
2057
  repository: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alexgorbatchev/shadcn",
3
- "version": "0.0.144",
3
+ "version": "0.0.145",
4
4
  "description": "Sharp, monospace React components with compact, comfortable, and touch densities.",
5
5
  "license": "MIT",
6
6
  "repository": {