mirror of
https://github.com/docmost/docmost.git
synced 2026-08-22 00:21:36 +10:00
* feat(ee): bases Table and kanban UI, formula engine package, and the base-embed editor extension. * - default status - type fix - error helper * fix: base trash list handling * feat: base nodeview menu * feat: translation * fix number precision * feat(base): add focused-cell atom and cell coordinate types * feat(base): add cell focus-ring style * feat(base): add pure next-cell navigation helper * feat(base): keyboard navigation controller and grid wiring * update offerings * feat(base): cell focus ring, click-to-focus, and gridcell ARIA * feat(base): row ARIA index and selected state * feat(base): seed editor value on type-to-edit for free-text cells * feat(base): make column headers keyboard-focusable as tab stops * fix(base): remove focus outline on grid container * fix(base): show cell focus ring only while the grid is focused * feat(base): keyboard-navigate the row-number column for selection * fix(base): sync header/body horizontal scroll on header focus; expand row via Space, drop expander from tab order * fix(base): tab from long-text editor moves to next cell instead of leaving the table * fix(base): close view popovers on Escape regardless of focus; drop redundant property switch tab stop * fix(base): show cell focus ring only while the grid body itself is focused * fix(base): render view-tab rename as an inline pill so the tab band height stays put * fix(base): refer to the feature as 'base' rather than 'database' * fix: change permissions object shape * license file * fix tsconfig * fix base cache * fix: preserve sidebar title/icon on partial page updates * fix: skip duplicate row fetch when opening new kanban card * fix refetch * fix focus * fix spacing * fix(base): select grid cell on mousedown to avoid stale focus ring flash The focus ring is gated on the grid having DOM focus (.bodyGrid:focus .cellFocused), but the focusedCell atom is never cleared when the grid blurs. Clicking outside hides the ring via the :focus gate while the atom still points at the old cell. Selection was committed on click (mouseup), while the grid receives focus on mousedown. Clicking a new cell re-focused the grid before the atom updated, briefly painting the ring on the previously selected cell. Commit selection on mousedown so the atom updates in the same event that grants focus, before the browser paints. * fix: activate New row button via keyboard (Enter/Space) The New row control is a role=button div with no keydown handler, so Enter/Space never triggered it. It also lives inside the grid element, whose native keydown listener caught the Enter and ran cell navigation against the previously focused cell. Add Enter/Space activation to the button, and make the grid keyboard handler ignore keydowns that originate from a focusable child rather than the grid element itself, so in-grid controls handle their own keys. * fix(base): keep add-property popover within viewport on mobile Opened from the row detail modal, the create-property popover anchors to the bottom Add property button and flips upward on small screens, clipping its top (name field, formula editor) off-screen with no way to scroll to it. Bound the dropdown to the available height with the floating-ui size middleware and give it an internal scroll container. Disable react-remove-scroll isolation on the modal so the body-portaled popover can scroll on touch while the modal scroll lock stays active. * fix(base): enable grid cell editing on touch devices Cells could only enter edit mode via double-click or a physical keyboard, so touch devices had no way to edit a cell. Treat a touch/pen tap as the edit gesture, distinguishing a tap from a scroll by movement and branching per pointer type so mouse double-click stays unchanged. Also reveal the row expand button on hover-less devices so the row detail view stays reachable. * feat(editor): add base and kanban inserts to the toolbar * feat(base): insert row below via Shift+Enter on the primary cell * fix(base): place caret at end instead of selecting all when editing cells * fix(base): prevent popover inputs from losing focus on mobile in row detail modal * fix grid cells on mobile * sync * fix: read-only export * feat(base): add prefixed nanoid id schemas and generators * feat(base): enforce strict property/choice id validation * feat(base): make property id varchar with per-base composite pk * feat(base): pass property id as text to cell extractors * feat(base): scope property lookups per base and generate property ids in repo * feat(base): generate status template choice ids as nanoid * feat(base): generate choice ids as nanoid on the client * chore(base): seed choice ids with nanoid * fix(base): mint kanban choice ids as nanoid * sync * sync * sync
199 lines
7.2 KiB
TypeScript
199 lines
7.2 KiB
TypeScript
import { memo, useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
import { Row, VisibilityState } from "@tanstack/react-table";
|
|
import { combine } from "@atlaskit/pragmatic-drag-and-drop/combine";
|
|
import {
|
|
draggable,
|
|
dropTargetForElements,
|
|
} from "@atlaskit/pragmatic-drag-and-drop/element/adapter";
|
|
import { setCustomNativeDragPreview } from "@atlaskit/pragmatic-drag-and-drop/element/set-custom-native-drag-preview";
|
|
import { pointerOutsideOfPreview } from "@atlaskit/pragmatic-drag-and-drop/element/pointer-outside-of-preview";
|
|
import {
|
|
attachClosestEdge,
|
|
extractClosestEdge,
|
|
type Edge,
|
|
} from "@atlaskit/pragmatic-drag-and-drop-hitbox/closest-edge";
|
|
import { triggerPostMoveFlash } from "@atlaskit/pragmatic-drag-and-drop-flourish/trigger-post-move-flash";
|
|
import * as liveRegion from "@atlaskit/pragmatic-drag-and-drop-live-region";
|
|
import { IBaseProperty, IBaseRow } from "@/ee/base/types/base.types";
|
|
import { useRowSelection } from "@/ee/base/hooks/use-row-selection";
|
|
import { GridCell } from "./grid-cell";
|
|
import classes from "@/ee/base/styles/grid.module.css";
|
|
|
|
export const ROW_DRAG_TYPE = "base-row";
|
|
|
|
type GridRowProps = {
|
|
row: Row<IBaseRow>;
|
|
rowIndex: number;
|
|
measureRef: (node: Element | null) => void;
|
|
onCellUpdate: (rowId: string, propertyId: string, value: unknown) => void;
|
|
onRowReorder?: (
|
|
rowId: string,
|
|
targetRowId: string,
|
|
position: "above" | "below",
|
|
) => void;
|
|
properties: IBaseProperty[];
|
|
columnVisibility: VisibilityState;
|
|
columnOrder: string[];
|
|
pageId: string;
|
|
};
|
|
|
|
export const GridRow = memo(function GridRow({
|
|
row,
|
|
rowIndex,
|
|
measureRef,
|
|
onCellUpdate,
|
|
onRowReorder,
|
|
pageId,
|
|
}: GridRowProps) {
|
|
const rowId = row.id;
|
|
const isSelected = useRowSelection(pageId).isSelected(rowId);
|
|
|
|
const rowRef = useRef<HTMLDivElement>(null);
|
|
const [isDragging, setIsDragging] = useState(false);
|
|
const [closestEdge, setClosestEdge] = useState<Edge | null>(null);
|
|
|
|
const setRowEl = useCallback(
|
|
(node: HTMLDivElement | null) => {
|
|
rowRef.current = node;
|
|
measureRef(node);
|
|
},
|
|
[measureRef],
|
|
);
|
|
|
|
// onRowReorder ultimately depends on React Query result objects (activeView,
|
|
// base) via persistViewConfig, and its identity changes on every WS-driven
|
|
// cache invalidation. Holding it in a ref keeps it out of the DnD effect's
|
|
// dep array so we don't tear down and re-register every row's pragmatic-dnd
|
|
// adapter each time another user edits the base. Same pattern as the column
|
|
// header's onColumnReorderRef.
|
|
const onRowReorderRef = useRef(onRowReorder);
|
|
useLayoutEffect(() => {
|
|
onRowReorderRef.current = onRowReorder;
|
|
});
|
|
|
|
useEffect(() => {
|
|
const rowEl = rowRef.current;
|
|
if (!rowEl || !onRowReorder) return;
|
|
// The whole row is the draggable element (full-row native preview).
|
|
// dragHandle limits initiation to the grip, leaving cell clicks and
|
|
// inline editing untouched.
|
|
const handle = rowEl.querySelector<HTMLElement>(
|
|
`.${classes.rowNumberDragHandle}`,
|
|
);
|
|
if (!handle) return;
|
|
return combine(
|
|
draggable({
|
|
element: rowEl,
|
|
dragHandle: handle,
|
|
getInitialData: () => ({ type: ROW_DRAG_TYPE, rowId, pageId }),
|
|
onGenerateDragPreview: ({ nativeSetDragImage }) => {
|
|
// Native preview of the full-width sticky subgrid row rasterizes
|
|
// garbled (it pulls in surrounding page paint, e.g. the sidebar).
|
|
// Render a compact card that clones just the title cell instead.
|
|
const titleCell =
|
|
rowEl.querySelector<HTMLElement>(`.${classes.primaryCell}`) ??
|
|
rowEl.querySelector<HTMLElement>(`.${classes.cell}`);
|
|
if (!titleCell) return;
|
|
const width = titleCell.getBoundingClientRect().width;
|
|
setCustomNativeDragPreview({
|
|
nativeSetDragImage,
|
|
getOffset: pointerOutsideOfPreview({ x: "12px", y: "8px" }),
|
|
render: ({ container }) => {
|
|
const card = document.createElement("div");
|
|
card.className = classes.rowDragPreview;
|
|
card.style.width = `${width}px`;
|
|
const clone = titleCell.cloneNode(true) as HTMLElement;
|
|
clone.style.position = "static";
|
|
clone.style.left = "auto";
|
|
clone.style.width = "100%";
|
|
clone.style.opacity = "1";
|
|
clone.style.borderRight = "none";
|
|
card.appendChild(clone);
|
|
container.appendChild(card);
|
|
},
|
|
});
|
|
},
|
|
onDragStart: () => setIsDragging(true),
|
|
onDrop: () => setIsDragging(false),
|
|
}),
|
|
dropTargetForElements({
|
|
element: rowEl,
|
|
canDrop: ({ source }) =>
|
|
source.data.type === ROW_DRAG_TYPE &&
|
|
source.data.pageId === pageId &&
|
|
source.data.rowId !== rowId,
|
|
getData: ({ input, element }) =>
|
|
attachClosestEdge(
|
|
{ rowId },
|
|
{ input, element, allowedEdges: ["top", "bottom"] },
|
|
),
|
|
onDrag: ({ self }) => setClosestEdge(extractClosestEdge(self.data)),
|
|
onDragLeave: () => setClosestEdge(null),
|
|
onDrop: ({ source, self }) => {
|
|
setClosestEdge(null);
|
|
const edge = extractClosestEdge(self.data);
|
|
if (!edge) return;
|
|
onRowReorderRef.current?.(
|
|
source.data.rowId as string,
|
|
rowId,
|
|
edge === "top" ? "above" : "below",
|
|
);
|
|
triggerPostMoveFlash(rowEl);
|
|
liveRegion.announce("Moved row");
|
|
},
|
|
}),
|
|
);
|
|
// onRowReorder is read through onRowReorderRef; only its presence gates
|
|
// registration, and that does not change across a row's mounted life.
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [rowId, pageId]);
|
|
|
|
const dropIndicatorClass = closestEdge
|
|
? closestEdge === "top"
|
|
? classes.rowDropAbove
|
|
: classes.rowDropBelow
|
|
: "";
|
|
|
|
return (
|
|
<div
|
|
ref={setRowEl}
|
|
data-index={rowIndex}
|
|
className={`${classes.row} ${classes.virtualRow} ${isDragging ? classes.rowDragging : ""} ${dropIndicatorClass} ${isSelected ? classes.rowSelected : ""}`}
|
|
role="row"
|
|
aria-rowindex={rowIndex + 1}
|
|
aria-selected={isSelected}
|
|
>
|
|
{row.getVisibleCells().map((cell, colIndex) => (
|
|
<GridCell
|
|
key={cell.id}
|
|
cell={cell}
|
|
rowIndex={rowIndex}
|
|
colIndex={colIndex}
|
|
onCellUpdate={onCellUpdate}
|
|
pageId={pageId}
|
|
/>
|
|
))}
|
|
</div>
|
|
);
|
|
},
|
|
gridRowPropsEqual);
|
|
|
|
// row compares by row.original: React Query structural sharing keeps
|
|
// unchanged rows reference-stable, while TanStack re-instantiates Row/Cell
|
|
// wrappers on every data change. properties/columnVisibility/columnOrder are
|
|
// layout busters — schema or column-state changes must re-render rows.
|
|
function gridRowPropsEqual(prev: GridRowProps, next: GridRowProps) {
|
|
return (
|
|
prev.row.id === next.row.id &&
|
|
prev.row.original === next.row.original &&
|
|
prev.rowIndex === next.rowIndex &&
|
|
prev.pageId === next.pageId &&
|
|
prev.onCellUpdate === next.onCellUpdate &&
|
|
prev.onRowReorder === next.onRowReorder &&
|
|
prev.measureRef === next.measureRef &&
|
|
prev.properties === next.properties &&
|
|
prev.columnVisibility === next.columnVisibility &&
|
|
prev.columnOrder === next.columnOrder
|
|
);
|
|
}
|