@tensor_1/react 2.54.1 → 2.55.1

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.
@@ -35,6 +35,6 @@ interface ComboboxProps extends Omit<HTMLAttributes<HTMLDivElement>, 'onChange'>
35
35
  * Escape closes the list and puts the chosen option's text back, as leaving the field does.
36
36
  * Groups render as `role="group"`; the no-match row sits outside the listbox.
37
37
  */
38
- declare function Combobox({ options, value, defaultValue, onValueChange, label, placeholder, emptyLabel, name, disabled, className, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, inputId, placement, ...props }: ComboboxProps): react.JSX.Element;
38
+ declare function Combobox({ options, value, defaultValue, onValueChange, label, placeholder, emptyLabel, name, disabled, className, 'aria-labelledby': ariaLabelledBy, 'aria-describedby': ariaDescribedBy, 'aria-invalid': ariaInvalid, 'aria-required': ariaRequired, inputId, placement, ...props }: ComboboxProps): react.JSX.Element;
39
39
 
40
40
  export { Combobox, ComboboxGroup, ComboboxOption, type ComboboxProps };
@@ -24,6 +24,7 @@ function Combobox({
24
24
  "aria-labelledby": ariaLabelledBy,
25
25
  "aria-describedby": ariaDescribedBy,
26
26
  "aria-invalid": ariaInvalid,
27
+ "aria-required": ariaRequired,
27
28
  inputId,
28
29
  placement = "bottom-start",
29
30
  ...props
@@ -204,6 +205,7 @@ function Combobox({
204
205
  "aria-labelledby": ariaLabelledBy,
205
206
  "aria-describedby": ariaDescribedBy,
206
207
  "aria-invalid": invalid || void 0,
208
+ "aria-required": ariaRequired,
207
209
  "aria-autocomplete": "list",
208
210
  "aria-expanded": open,
209
211
  "aria-controls": listboxId,
@@ -224,6 +224,13 @@ interface DataWorkspaceProps<T, S extends DataWorkspaceSortState = DataWorkspace
224
224
  * their row, at any width.
225
225
  */
226
226
  rowActions?: (row: T, context: DataWorkspaceRowActionsContext) => ReactNode;
227
+ /**
228
+ * Keep the actions column on an unpaged virtual list even if only off-screen rows have actions.
229
+ * Only mounted rows and overscan call `rowActions`. A stable renderer avoids unrelated rerenders;
230
+ * change its identity when permissions or other data used by the renderer change. Grouped,
231
+ * paginated and card layouts retain the normal all-row check.
232
+ */
233
+ rowActionsColumn?: boolean;
227
234
  /** More props for a row, e.g. a data attribute that marks it changed (see ChangeHighlight, PR #164). */
228
235
  getRowProps?: (row: T) => HTMLAttributes<HTMLTableRowElement> & Record<`data-${string}`, string | undefined>;
229
236
  density?: TableDensity;
@@ -369,6 +376,6 @@ interface DataWorkspaceProps<T, S extends DataWorkspaceSortState = DataWorkspace
369
376
  * rich id cell, multi-column sort, the product's state bodies and `beforeBody`, row groups,
370
377
  * windowing (`virtualize`) and a keyboard row model (`onRowActivate`).
371
378
  */
372
- declare function DataWorkspace<T, S extends DataWorkspaceSortState = DataWorkspaceSort | null>({ label, rows, getRowId, rowLabel, columns, idColumn, sort, onSortChange, selection, onSelectionChange, maxSelection, bulkActions, rowActions, getRowProps, density, zebra, freezeFirstColumn, fixed, mobile, search, filters, savedViews, viewMenu, viewChanged, onSaveView, onSaveViewAs, saveViewAs, maximized, onMaximizedChange, toolbarEnd, beforeBody, pagination, status, refreshing, onRetry, loadingRows, empty, emptyAction, filteredEmpty, filteredEmptyAction, error, stateOverride, groups, collapsedGroups, onCollapsedGroupsChange, virtualize, rowNavigation, onRowActivate, activateOnClick, activeRowId, onActiveRowChange, multiSort, labels: labelOverrides, className, ...props }: DataWorkspaceProps<T, S>): react.JSX.Element;
379
+ declare function DataWorkspace<T, S extends DataWorkspaceSortState = DataWorkspaceSort | null>({ label, rows, getRowId, rowLabel, columns, idColumn, sort, onSortChange, selection, onSelectionChange, maxSelection, bulkActions, rowActions, rowActionsColumn, getRowProps, density, zebra, freezeFirstColumn, fixed, mobile, search, filters, savedViews, viewMenu, viewChanged, onSaveView, onSaveViewAs, saveViewAs, maximized, onMaximizedChange, toolbarEnd, beforeBody, pagination, status, refreshing, onRetry, loadingRows, empty, emptyAction, filteredEmpty, filteredEmptyAction, error, stateOverride, groups, collapsedGroups, onCollapsedGroupsChange, virtualize, rowNavigation, onRowActivate, activateOnClick, activeRowId, onActiveRowChange, multiSort, labels: labelOverrides, className, ...props }: DataWorkspaceProps<T, S>): react.JSX.Element;
373
380
 
374
381
  export { DEFAULT_DATA_WORKSPACE_LABELS, DataWorkspace, type DataWorkspaceColumn, type DataWorkspaceGroup, type DataWorkspaceIdColumn, type DataWorkspaceLabels, type DataWorkspacePagination, type DataWorkspaceProps, type DataWorkspaceRowActionsContext, type DataWorkspaceSort, type DataWorkspaceSortState, type DataWorkspaceSortValue, type DataWorkspaceVirtualize };
@@ -95,6 +95,7 @@ function DataWorkspace({
95
95
  maxSelection,
96
96
  bulkActions,
97
97
  rowActions,
98
+ rowActionsColumn,
98
99
  getRowProps,
99
100
  density,
100
101
  zebra,
@@ -247,12 +248,13 @@ function DataWorkspace({
247
248
  onSelectionChange(apply(new Set(selected), rowIds, on));
248
249
  };
249
250
  const atCap = selected.size >= cap;
251
+ const lazyRowActions = rowActionsColumn && virtualize && !pagination && !shownGroups && ladder !== "cards" ? rowActions : void 0;
250
252
  const actionsByRow = useMemo(() => {
251
- if (!rowActions) return [];
253
+ if (!rowActions || lazyRowActions) return [];
252
254
  const context = { ladder, compact: ladder === "priority-mid" };
253
255
  return shownRows.map((row) => rowActions(row, context));
254
- }, [shownRows, rowActions, ladder]);
255
- const hasActions = actionsByRow.some((node) => node != null && node !== false);
256
+ }, [shownRows, rowActions, ladder, lazyRowActions]);
257
+ const hasActions = !!lazyRowActions || actionsByRow.some((node) => node != null && node !== false);
256
258
  const activeFilters = filters ? filters.fields.filter((field) => !isFilterEmpty(filters.values[field.id])) : [];
257
259
  const searching = (search?.value.trim() ?? "") !== "";
258
260
  const clearAll = () => {
@@ -357,6 +359,7 @@ function DataWorkspace({
357
359
  toggleRow,
358
360
  toggleMany,
359
361
  actionsByRow,
362
+ lazyRowActions,
360
363
  hasActions,
361
364
  keys,
362
365
  sortable: onSortChange != null,
@@ -449,6 +452,7 @@ function WorkspaceTable({
449
452
  toggleRow,
450
453
  toggleMany,
451
454
  actionsByRow,
455
+ lazyRowActions,
452
456
  hasActions,
453
457
  keys,
454
458
  sortable,
@@ -773,6 +777,8 @@ function WorkspaceTable({
773
777
  selectDisabled: !isSelected && atCap,
774
778
  hasActions,
775
779
  actions: actionsByRow[index],
780
+ lazyRowActions,
781
+ ladder,
776
782
  ladderOn,
777
783
  selectRowLabel,
778
784
  openLabel,
@@ -929,6 +935,8 @@ function WorkspaceRowInner({
929
935
  selectDisabled,
930
936
  hasActions,
931
937
  actions,
938
+ lazyRowActions,
939
+ ladder,
932
940
  ladderOn,
933
941
  selectRowLabel,
934
942
  openLabel,
@@ -938,6 +946,10 @@ function WorkspaceRowInner({
938
946
  tabStop,
939
947
  handlers
940
948
  }) {
949
+ const renderedActions = useMemo(
950
+ () => lazyRowActions ? lazyRowActions(row, { ladder, compact: ladder === "priority-mid" }) : actions,
951
+ [lazyRowActions, row, ladder, actions]
952
+ );
941
953
  const text = idColumn?.text(row) ?? rowLabel?.(row) ?? rowId;
942
954
  const extra = getRowProps?.(row);
943
955
  const navProps = nav ? {
@@ -973,7 +985,7 @@ function WorkspaceRowInner({
973
985
  ) }),
974
986
  idColumn && /* @__PURE__ */ jsx(Td, { className: "uix-id-cell", "data-col": ladderOn ? "id" : void 0, children: /* @__PURE__ */ jsx(IdCell, { row, text, idColumn, openLabel }) }),
975
987
  columns.map((column) => /* @__PURE__ */ jsx(Td, { className: cx(column.align === "end" && "uix-col--num", column.className) || void 0, ...ladderAttrs(ladderOn, column, true), children: column.cell(row) }, column.id)),
976
- hasActions && /* @__PURE__ */ jsx(RowActions, { "data-col": ladderOn ? "actions" : void 0, children: actions })
988
+ hasActions && /* @__PURE__ */ jsx(RowActions, { "data-col": ladderOn ? "actions" : void 0, children: renderedActions })
977
989
  ] });
978
990
  }
979
991
  const WorkspaceRow = memo(WorkspaceRowInner);
@@ -23,6 +23,7 @@ interface FieldProps {
23
23
  helpLabel?: string;
24
24
  children: ReactNode;
25
25
  className?: string;
26
+ /** Explicit label target. When a Combobox also supplies `inputId`, the two IDs must match. */
26
27
  htmlFor?: string;
27
28
  }
28
29
  declare function Field({ label, hint, error, warning, success, required, help, helpLabel, children, className, htmlFor }: FieldProps): react.JSX.Element;
@@ -2,14 +2,23 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { cloneElement, isValidElement, useId } from "react";
3
3
  import { cx } from "../cx.js";
4
4
  import { InfoTip } from "./InfoTip.js";
5
+ import { Combobox } from "./Combobox.js";
5
6
  import { hasHelp, helpLabelFor } from "../info-tip-model.js";
7
+ function isComboboxElement(child) {
8
+ let type = child.type;
9
+ while (type !== null && typeof type === "object" && Reflect.get(type, "$$typeof") === /* @__PURE__ */ Symbol.for("react.memo")) {
10
+ type = Reflect.get(type, "type");
11
+ }
12
+ return type === Combobox;
13
+ }
6
14
  function Field({ label, hint, error, warning, success, required, help, helpLabel, children, className, htmlFor }) {
7
15
  const uid = useId();
8
16
  const msgId = `${uid}-msg`;
9
17
  const describedBy = error || warning || success || hint ? msgId : void 0;
10
- const controlId = isValidElement(children) ? children.props.id ?? `${uid}-ctl` : void 0;
18
+ const isCombobox = isValidElement(children) && isComboboxElement(children);
19
+ const controlId = isValidElement(children) ? isCombobox ? children.props.inputId ?? htmlFor ?? `${uid}-ctl` : children.props.id ?? `${uid}-ctl` : void 0;
11
20
  const control = isValidElement(children) ? cloneElement(children, {
12
- id: controlId,
21
+ ...isCombobox ? { inputId: controlId } : { id: controlId },
13
22
  "aria-describedby": [children.props["aria-describedby"], describedBy].filter(Boolean).join(" ") || void 0,
14
23
  "aria-invalid": error ? true : children.props["aria-invalid"],
15
24
  "aria-required": children.props["aria-required"] ?? (required || void 0),
@@ -7,6 +7,8 @@ import { prefersReducedMotion } from "../hooks/useReducedMotion.js";
7
7
  import { tokenMs } from "../motion.js";
8
8
  import { XIcon } from "../icons/components.js";
9
9
  import { toast as defaultToast } from "../toast-store.js";
10
+ import { createPortal } from "react-dom";
11
+ import { subscribeModalLayer, topModalDialog } from "../hooks/dialog-layer.js";
10
12
  const ToasterContext = createContext(null);
11
13
  const useIsomorphicLayoutEffect = typeof document !== "undefined" ? useLayoutEffect : useEffect;
12
14
  const SWIPE_VELOCITY = 0.11;
@@ -227,6 +229,7 @@ function useToastTimers(store, visible, paused) {
227
229
  function Toaster({ children, regionLabel: regionLabelProp, store = defaultToast.store, limit = 3, position = "bottom-end", className, onMouseEnter, onMouseLeave, onFocus, onBlur, onKeyDown, ...props }) {
228
230
  const uixLabels = useUixLabels();
229
231
  const regionLabel = regionLabelProp ?? uixLabels.toaster?.region ?? "Notifications";
232
+ const [portalHost, setPortalHost] = useState(null);
230
233
  const [announced, setAnnounced] = useState("");
231
234
  const clearTimer = useRef(null);
232
235
  const announce = useCallback((text) => {
@@ -237,7 +240,8 @@ function Toaster({ children, regionLabel: regionLabelProp, store = defaultToast.
237
240
  useEffect(() => () => {
238
241
  if (clearTimer.current != null) clearTimeout(clearTimer.current);
239
242
  }, []);
240
- const ctx = useMemo(() => ({ announce }), [announce]);
243
+ const ctx = useMemo(() => ({ announce: portalHost ? announce : () => {
244
+ } }), [announce, portalHost]);
241
245
  const records = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
242
246
  const visible = useMemo(() => records.slice(-Math.max(1, limit)), [records, limit]);
243
247
  const [hovered, setHovered] = useState(false);
@@ -251,6 +255,48 @@ function Toaster({ children, regionLabel: regionLabelProp, store = defaultToast.
251
255
  }, []);
252
256
  useToastTimers(store, visible, hovered || focused || hidden);
253
257
  const regionRef = useRef(null);
258
+ const homeRef = useRef(null);
259
+ const returnFocusRef = useRef(null);
260
+ useIsomorphicLayoutEffect(() => {
261
+ const host = document.createElement("div");
262
+ host.dataset.uixToastHost = "";
263
+ host.style.display = "contents";
264
+ homeRef.current?.after(host);
265
+ setPortalHost(host);
266
+ return () => {
267
+ host.remove();
268
+ };
269
+ }, []);
270
+ useIsomorphicLayoutEffect(() => {
271
+ if (!portalHost) return;
272
+ const sync = () => {
273
+ const region = regionRef.current;
274
+ if (!region) return;
275
+ const active = document.activeElement;
276
+ const focusedElement = region.contains(active) ? active : null;
277
+ const dialog = topModalDialog();
278
+ if (typeof region.hidePopover === "function" && region.matches(":popover-open")) region.hidePopover();
279
+ if (dialog) {
280
+ dialog.append(portalHost);
281
+ } else {
282
+ homeRef.current?.after(portalHost);
283
+ }
284
+ if (dialog && typeof region.showPopover === "function") {
285
+ region.setAttribute("popover", "manual");
286
+ region.showPopover();
287
+ } else {
288
+ region.removeAttribute("popover");
289
+ }
290
+ focusedElement?.focus({ preventScroll: true });
291
+ };
292
+ sync();
293
+ return subscribeModalLayer(sync);
294
+ }, [portalHost]);
295
+ useIsomorphicLayoutEffect(() => {
296
+ if (focused && visible.every((record) => record.leaving) && returnFocusRef.current?.isConnected) {
297
+ returnFocusRef.current.focus({ preventScroll: true });
298
+ }
299
+ }, [visible, focused]);
254
300
  const tops = useRef(/* @__PURE__ */ new Map());
255
301
  useIsomorphicLayoutEffect(() => {
256
302
  const region = regionRef.current;
@@ -281,7 +327,7 @@ function Toaster({ children, regionLabel: regionLabelProp, store = defaultToast.
281
327
  event.stopPropagation();
282
328
  store.dismiss(id, "close");
283
329
  };
284
- return /* @__PURE__ */ jsx(ToasterContext.Provider, { value: ctx, children: /* @__PURE__ */ jsxs(
330
+ const content = /* @__PURE__ */ jsx(ToasterContext.Provider, { value: ctx, children: /* @__PURE__ */ jsxs(
285
331
  "div",
286
332
  {
287
333
  ref: regionRef,
@@ -298,6 +344,7 @@ function Toaster({ children, regionLabel: regionLabelProp, store = defaultToast.
298
344
  onMouseLeave?.(e);
299
345
  },
300
346
  onFocus: (e) => {
347
+ if (e.relatedTarget instanceof window.HTMLElement && !e.currentTarget.contains(e.relatedTarget)) returnFocusRef.current = e.relatedTarget;
301
348
  setFocused(true);
302
349
  onFocus?.(e);
303
350
  },
@@ -314,6 +361,10 @@ function Toaster({ children, regionLabel: regionLabelProp, store = defaultToast.
314
361
  ]
315
362
  }
316
363
  ) });
364
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
365
+ /* @__PURE__ */ jsx("span", { hidden: true, ref: homeRef }),
366
+ portalHost ? createPortal(content, portalHost) : content
367
+ ] });
317
368
  }
318
369
  export {
319
370
  Toast,
@@ -50,7 +50,8 @@ function readSystemDisplayPreferences() {
50
50
  return { dark: mm("(prefers-color-scheme: dark)"), moreContrast: mm("(prefers-contrast: more)") };
51
51
  }
52
52
  function displayPreferencesScript(storageKey = DISPLAY_PREFERENCES_STORAGE_KEY, defaults = DEFAULT_DISPLAY_PREFERENCES) {
53
- return `(function(){try{var d=document.documentElement,p={};try{p=JSON.parse(localStorage.getItem(${JSON.stringify(storageKey)})||'{}')||{}}catch(e){}if(typeof p!=='object')p={};var D=${JSON.stringify(defaults)},O=${JSON.stringify(DISPLAY_PREFERENCE_OPTIONS)};for(var k in O)if(O[k].indexOf(p[k])<0)p[k]=D[k];var m=function(q){return !!(window.matchMedia&&window.matchMedia(q).matches)};var s=function(n,v){if(v)d.setAttribute(n,v);else d.removeAttribute(n)};s('data-theme',p.theme==='light'||p.theme==='dark'?p.theme:(m('(prefers-color-scheme: dark)')?'dark':'light'));s('data-contrast',p.contrast==='more'||(p.contrast!=='standard'&&m('(prefers-contrast: more)'))?'more':'');s('data-text-scale',p.textScale==='sm'||p.textScale==='lg'||p.textScale==='xl'?p.textScale:'');s('data-motion',p.motion==='reduce'?'reduce':'');s('data-density',p.density==='compact'||p.density==='comfortable'?p.density:'')}catch(e){}})();`;
53
+ const inlineJSON = (value) => JSON.stringify(value).replace(/</g, "\\u003c");
54
+ return `(function(){try{var d=document.documentElement,p={};try{p=JSON.parse(localStorage.getItem(${inlineJSON(storageKey)})||'{}')||{}}catch(e){}if(typeof p!=='object')p={};var D=${inlineJSON(defaults)},O=${inlineJSON(DISPLAY_PREFERENCE_OPTIONS)};for(var k in O)if(O[k].indexOf(p[k])<0)p[k]=D[k];var m=function(q){return !!(window.matchMedia&&window.matchMedia(q).matches)};var s=function(n,v){if(v)d.setAttribute(n,v);else d.removeAttribute(n)};s('data-theme',p.theme==='light'||p.theme==='dark'?p.theme:(m('(prefers-color-scheme: dark)')?'dark':'light'));s('data-contrast',p.contrast==='more'||(p.contrast!=='standard'&&m('(prefers-contrast: more)'))?'more':'');s('data-text-scale',p.textScale==='sm'||p.textScale==='lg'||p.textScale==='xl'?p.textScale:'');s('data-motion',p.motion==='reduce'?'reduce':'');s('data-density',p.density==='compact'||p.density==='comfortable'?p.density:'')}catch(e){}})();`;
54
55
  }
55
56
  export {
56
57
  DEFAULT_DISPLAY_PREFERENCES,
@@ -0,0 +1,5 @@
1
+ declare function topModalDialog(): HTMLDialogElement | undefined;
2
+ declare function subscribeModalLayer(listener: () => void): () => void;
3
+ declare function registerModalLayer(dialog: HTMLDialogElement): () => void;
4
+
5
+ export { registerModalLayer, subscribeModalLayer, topModalDialog };
@@ -0,0 +1,34 @@
1
+ const dialogs = [];
2
+ const listeners = /* @__PURE__ */ new Set();
3
+ const notify = () => {
4
+ for (const listener of listeners) listener();
5
+ };
6
+ function topModalDialog() {
7
+ for (let index = dialogs.length - 1; index >= 0; index -= 1) {
8
+ const dialog = dialogs[index];
9
+ if (dialog?.open && dialog.isConnected) return dialog;
10
+ }
11
+ }
12
+ function subscribeModalLayer(listener) {
13
+ listeners.add(listener);
14
+ return () => {
15
+ listeners.delete(listener);
16
+ };
17
+ }
18
+ function registerModalLayer(dialog) {
19
+ const previous = dialogs.indexOf(dialog);
20
+ if (previous !== -1) dialogs.splice(previous, 1);
21
+ dialogs.push(dialog);
22
+ notify();
23
+ return () => {
24
+ const index = dialogs.indexOf(dialog);
25
+ if (index === -1) return;
26
+ dialogs.splice(index, 1);
27
+ notify();
28
+ };
29
+ }
30
+ export {
31
+ registerModalLayer,
32
+ subscribeModalLayer,
33
+ topModalDialog
34
+ };
@@ -1,6 +1,7 @@
1
1
  "use client";
2
2
  import { useRef, useEffect, useLayoutEffect } from "react";
3
3
  import { markKeyOpened, watchInputModality } from "../motion.js";
4
+ import { registerModalLayer } from "./dialog-layer.js";
4
5
  const useIsomorphicLayoutEffect = typeof document !== "undefined" ? useLayoutEffect : useEffect;
5
6
  let lockCount = 0;
6
7
  let saved = null;
@@ -54,6 +55,7 @@ function useDialog(open, onClose, keepOpen) {
54
55
  markKeyOpened(el);
55
56
  el.showModal();
56
57
  }
58
+ const leaveLayer = registerModalLayer(el);
57
59
  lockBodyScroll();
58
60
  let locked = true;
59
61
  const handleClose = () => {
@@ -65,6 +67,7 @@ function useDialog(open, onClose, keepOpen) {
65
67
  } catch {
66
68
  }
67
69
  }
70
+ leaveLayer();
68
71
  if (locked) {
69
72
  locked = false;
70
73
  unlockBodyScroll();
@@ -77,6 +80,7 @@ function useDialog(open, onClose, keepOpen) {
77
80
  return () => {
78
81
  el.removeEventListener("close", handleClose);
79
82
  el.removeEventListener("cancel", handleCancel);
83
+ leaveLayer();
80
84
  if (locked) {
81
85
  locked = false;
82
86
  unlockBodyScroll();