@viewkitjs/views 0.1.0 → 0.2.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/CHANGELOG.md +196 -1
- package/README.md +90 -41
- package/dist/atoms/Row.js +1 -1
- package/dist/atoms/RowMenu.d.ts +1 -1
- package/dist/atoms/RowMenu.js +15 -4
- package/dist/atoms/types.d.ts +4 -4
- package/dist/contract.d.ts +37 -7
- package/dist/contract.js +24 -5
- package/dist/display/format.d.ts +16 -1
- package/dist/display/format.js +10 -1
- package/dist/display/index.d.ts +1 -1
- package/dist/display/index.js +1 -1
- package/dist/display/link.js +5 -3
- package/dist/display/location.d.ts +4 -3
- package/dist/display/location.js +12 -5
- package/dist/display/options.d.ts +1 -1
- package/dist/display/percent.js +10 -3
- package/dist/display/phone.d.ts +2 -1
- package/dist/display/phone.js +8 -1
- package/dist/display/relation.js +1 -1
- package/dist/editors/ChipsEditor.js +1 -1
- package/dist/editors/LocationEditor.js +16 -17
- package/dist/editors/NameEditor.js +5 -4
- package/dist/editors/NumberEditor.js +2 -2
- package/dist/editors/RangeEditor.js +2 -2
- package/dist/editors/ValueListEditor.d.ts +2 -2
- package/dist/editors/ValueListEditor.js +8 -8
- package/dist/editors/edit-cores.d.ts +1 -1
- package/dist/fields/binding.d.ts +1 -1
- package/dist/fields/currency.d.ts +0 -10
- package/dist/fields/currency.js +0 -14
- package/dist/fields/money.d.ts +1 -0
- package/dist/fields/money.js +1 -0
- package/dist/filters/filter-model.d.ts +0 -1
- package/dist/filters/registry.d.ts +3 -36
- package/dist/filters/registry.js +0 -38
- package/dist/grid/chrome/GridAddColumn.d.ts +11 -0
- package/dist/grid/chrome/GridAddColumn.js +29 -0
- package/dist/grid/chrome/GridAggregateMenu.d.ts +31 -0
- package/dist/grid/chrome/GridAggregateMenu.js +27 -0
- package/dist/grid/chrome/GridCellEditors.d.ts +64 -0
- package/dist/grid/chrome/GridCellEditors.js +55 -0
- package/dist/grid/chrome/GridCellOutline.d.ts +70 -0
- package/dist/grid/chrome/GridCellOutline.js +21 -0
- package/dist/grid/chrome/GridChipsEditor.d.ts +28 -0
- package/dist/grid/chrome/GridChipsEditor.js +40 -0
- package/dist/grid/chrome/GridColumnColorSection.d.ts +11 -0
- package/dist/grid/chrome/GridColumnColorSection.js +40 -0
- package/dist/grid/chrome/GridColumnDateSection.d.ts +23 -0
- package/dist/grid/chrome/GridColumnDateSection.js +23 -0
- package/dist/grid/chrome/GridColumnDurationSection.d.ts +19 -0
- package/dist/grid/chrome/GridColumnDurationSection.js +24 -0
- package/dist/grid/chrome/GridColumnMenu.d.ts +101 -0
- package/dist/grid/chrome/GridColumnMenu.js +99 -0
- package/dist/grid/chrome/GridColumnNumberSection.d.ts +25 -0
- package/dist/grid/chrome/GridColumnNumberSection.js +27 -0
- package/dist/grid/chrome/GridColumnPercentSection.d.ts +15 -0
- package/dist/grid/chrome/GridColumnPercentSection.js +16 -0
- package/dist/grid/chrome/GridColumnSortSection.d.ts +18 -0
- package/dist/grid/chrome/GridColumnSortSection.js +16 -0
- package/dist/grid/chrome/GridDateEditor.d.ts +22 -0
- package/dist/grid/chrome/GridDateEditor.js +31 -0
- package/dist/grid/chrome/GridFlyout.d.ts +44 -0
- package/dist/grid/chrome/GridFlyout.js +80 -0
- package/dist/grid/chrome/GridFooter.d.ts +23 -0
- package/dist/grid/chrome/GridFooter.js +81 -0
- package/dist/grid/chrome/GridGroupMenu.d.ts +37 -0
- package/dist/grid/chrome/GridGroupMenu.js +57 -0
- package/dist/grid/chrome/GridHeader.d.ts +61 -0
- package/dist/grid/chrome/GridHeader.js +37 -0
- package/dist/grid/chrome/GridLongTextEditor.d.ts +36 -0
- package/dist/grid/chrome/GridLongTextEditor.js +127 -0
- package/dist/grid/chrome/GridMenuRow.d.ts +15 -0
- package/dist/grid/chrome/GridMenuRow.js +15 -0
- package/dist/grid/chrome/GridNameEditor.d.ts +19 -0
- package/dist/grid/chrome/GridNameEditor.js +36 -0
- package/dist/grid/chrome/GridNumberEditor.d.ts +35 -0
- package/dist/grid/chrome/GridNumberEditor.js +25 -0
- package/dist/grid/chrome/GridRangeEditor.d.ts +20 -0
- package/dist/grid/chrome/GridRangeEditor.js +25 -0
- package/dist/grid/chrome/GridRelationEditor.d.ts +21 -0
- package/dist/grid/chrome/GridRelationEditor.js +30 -0
- package/dist/grid/chrome/GridResizeHandle.d.ts +19 -0
- package/dist/grid/chrome/GridResizeHandle.js +19 -0
- package/dist/grid/chrome/GridRow.d.ts +25 -0
- package/dist/grid/chrome/GridRow.js +136 -0
- package/dist/grid/chrome/GridRowActions.d.ts +32 -0
- package/dist/grid/chrome/GridRowActions.js +25 -0
- package/dist/grid/chrome/GridRowCells.d.ts +4 -0
- package/dist/grid/chrome/GridRowCells.js +133 -0
- package/dist/grid/chrome/GridRowGlyph.d.ts +12 -0
- package/dist/grid/chrome/GridRowGlyph.js +13 -0
- package/dist/grid/chrome/GridSelectEditor.d.ts +18 -0
- package/dist/grid/chrome/GridSelectEditor.js +49 -0
- package/dist/grid/chrome/GridStructure.d.ts +48 -0
- package/dist/grid/chrome/GridStructure.js +45 -0
- package/dist/grid/chrome/GridTable.d.ts +4 -0
- package/dist/grid/chrome/GridTable.js +125 -0
- package/dist/grid/chrome/GridTableSurface.d.ts +15 -0
- package/dist/grid/chrome/GridTableSurface.js +6 -0
- package/dist/grid/chrome/GridTextEditor.d.ts +11 -0
- package/dist/grid/chrome/GridTextEditor.js +40 -0
- package/dist/grid/chrome/GridValueListEditor.d.ts +18 -0
- package/dist/grid/chrome/GridValueListEditor.js +36 -0
- package/dist/grid/chrome/StuckMarker.d.ts +16 -0
- package/dist/grid/chrome/StuckMarker.js +34 -0
- package/dist/grid/chrome/cell-clipboard.d.ts +9 -0
- package/dist/grid/chrome/cell-clipboard.js +28 -0
- package/dist/grid/chrome/cells.d.ts +21 -0
- package/dist/grid/chrome/cells.js +20 -0
- package/dist/grid/chrome/checks.d.ts +35 -0
- package/dist/grid/chrome/checks.js +22 -0
- package/dist/grid/chrome/column-glyph.d.ts +14 -0
- package/dist/grid/chrome/column-glyph.js +44 -0
- package/dist/grid/chrome/editors.d.ts +9 -0
- package/dist/grid/chrome/editors.js +10 -0
- package/dist/grid/chrome/grid-cell-classes.d.ts +59 -0
- package/dist/grid/chrome/grid-cell-classes.js +30 -0
- package/dist/grid/chrome/grid-menu-search.d.ts +7 -0
- package/dist/grid/chrome/grid-menu-search.js +7 -0
- package/dist/grid/chrome/grid-row-props.d.ts +131 -0
- package/dist/grid/chrome/grid-row-props.js +1 -0
- package/dist/grid/chrome/grid-styles.d.ts +37 -0
- package/dist/grid/chrome/grid-styles.js +8 -0
- package/dist/grid/chrome/grid-table-props.d.ts +173 -0
- package/dist/grid/chrome/grid-table-props.js +1 -0
- package/dist/grid/chrome/useGridBatchApi.d.ts +34 -0
- package/dist/grid/chrome/useGridBatchApi.js +35 -0
- package/dist/grid/chrome/useGridColumnLayout.d.ts +30 -0
- package/dist/grid/chrome/useGridColumnLayout.js +206 -0
- package/dist/grid/chrome/useGridHeaderDrag.d.ts +20 -0
- package/dist/grid/chrome/useGridHeaderDrag.js +37 -0
- package/dist/grid/chrome/useGridKeyboard.d.ts +47 -0
- package/dist/grid/chrome/useGridKeyboard.js +274 -0
- package/dist/grid/chrome/useGridPendingReconciliation.d.ts +12 -0
- package/dist/grid/chrome/useGridPendingReconciliation.js +32 -0
- package/dist/grid/chrome/useGridRailReveal.d.ts +57 -0
- package/dist/grid/chrome/useGridRailReveal.js +67 -0
- package/dist/grid/chrome/useGridRangeActions.d.ts +49 -0
- package/dist/grid/chrome/useGridRangeActions.js +188 -0
- package/dist/grid/chrome/useGridRangeGestures.d.ts +32 -0
- package/dist/grid/chrome/useGridRangeGestures.js +190 -0
- package/dist/grid/chrome/useGridRowContextMenu.d.ts +35 -0
- package/dist/grid/chrome/useGridRowContextMenu.js +127 -0
- package/dist/grid/chrome/useGridScaleStyles.d.ts +1 -0
- package/dist/grid/chrome/useGridScaleStyles.js +29 -0
- package/dist/grid/chrome/useGridScrollSync.d.ts +38 -0
- package/dist/grid/chrome/useGridScrollSync.js +176 -0
- package/dist/grid/chrome/useGridTableInteractionModel.d.ts +55 -0
- package/dist/grid/chrome/useGridTableInteractionModel.js +197 -0
- package/dist/grid/chrome/useGridTableSelection.d.ts +29 -0
- package/dist/grid/chrome/useGridTableSelection.js +55 -0
- package/dist/grid/chrome/useHeaderDragReorder.d.ts +21 -0
- package/dist/grid/chrome/useHeaderDragReorder.js +216 -0
- package/dist/grid/core/clipboard-model.d.ts +81 -0
- package/dist/grid/core/clipboard-model.js +291 -0
- package/dist/grid/core/column-values.d.ts +27 -0
- package/dist/grid/core/column-values.js +76 -0
- package/dist/grid/core/commit-model.d.ts +34 -0
- package/dist/grid/core/commit-model.js +3 -0
- package/dist/grid/core/coordinates.d.ts +48 -0
- package/dist/grid/core/coordinates.js +27 -0
- package/dist/grid/core/edit-values.d.ts +9 -0
- package/dist/grid/core/edit-values.js +1 -0
- package/dist/grid/core/editing-controller.d.ts +59 -0
- package/dist/grid/core/editing-controller.js +240 -0
- package/dist/grid/core/editing-model.d.ts +78 -0
- package/dist/grid/core/editing-model.js +136 -0
- package/dist/grid/core/grid-scale.d.ts +14 -0
- package/dist/grid/core/grid-scale.js +8 -0
- package/dist/grid/core/nav.d.ts +94 -0
- package/dist/grid/core/nav.js +92 -0
- package/dist/grid/core/pending-reconciliation.d.ts +50 -0
- package/dist/grid/core/pending-reconciliation.js +49 -0
- package/dist/grid/core/range-model.d.ts +25 -0
- package/dist/grid/core/range-model.js +59 -0
- package/dist/grid/core/spreadsheet-operations.d.ts +85 -0
- package/dist/grid/core/spreadsheet-operations.js +253 -0
- package/dist/grid/core/useGridEditing.d.ts +43 -0
- package/dist/grid/core/useGridEditing.js +90 -0
- package/dist/grid/core/useGridRange.d.ts +20 -0
- package/dist/grid/core/useGridRange.js +24 -0
- package/dist/grid/core/value-equality.d.ts +32 -0
- package/dist/grid/core/value-equality.js +34 -0
- package/dist/grid/index.d.ts +18 -0
- package/dist/grid/index.js +5 -0
- package/dist/grid/useGridTablePrefs.d.ts +50 -0
- package/dist/grid/useGridTablePrefs.js +101 -0
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/internal/viewport.d.ts +5 -0
- package/dist/internal/viewport.js +29 -0
- package/dist/model/column-capabilities.d.ts +2 -2
- package/dist/model/column-state.d.ts +1 -1
- package/dist/model/density.js +3 -3
- package/dist/model/filter-capabilities.d.ts +1 -1
- package/dist/model/filter-capabilities.js +1 -1
- package/dist/model/index.d.ts +4 -6
- package/dist/model/index.js +0 -1
- package/dist/model/preferences.d.ts +7 -3
- package/dist/provider/ViewsProvider.d.ts +1 -1
- package/dist/provider/ViewsProvider.js +5 -1
- package/dist/provider/components.d.ts +16 -8
- package/dist/provider/context.d.ts +3 -2
- package/dist/provider/menu-groups.d.ts +8 -0
- package/dist/provider/menu-groups.js +38 -0
- package/dist/provider/ports.d.ts +22 -0
- package/dist/provider/ports.js +1 -0
- package/dist/react.d.ts +1 -1
- package/docs/contract.md +128 -56
- package/docs/getting-started.md +250 -0
- package/docs/guides/atoms.md +245 -0
- package/docs/guides/cells.md +302 -0
- package/docs/guides/columns.md +412 -0
- package/docs/guides/display.md +203 -0
- package/docs/guides/editors.md +404 -0
- package/docs/guides/ports.md +246 -0
- package/docs/guides/selection.md +270 -0
- package/docs/guides/the-grid.md +677 -0
- package/docs/guides/the-provider.md +446 -0
- package/docs/index.md +50 -0
- package/docs/install.md +9 -47
- package/docs/reference/cells.md +28 -0
- package/docs/reference/display.md +42 -0
- package/docs/reference/editors-chips.md +6 -0
- package/docs/reference/editors-date.md +6 -0
- package/docs/reference/editors-location.md +10 -0
- package/docs/reference/editors-name.md +6 -0
- package/docs/reference/editors-number.md +11 -0
- package/docs/reference/editors-open-values.md +9 -0
- package/docs/reference/editors-range.md +6 -0
- package/docs/reference/editors-relation.md +9 -0
- package/docs/reference/editors-select.md +8 -0
- package/docs/reference/editors-session.md +9 -0
- package/docs/reference/editors-value-list.md +6 -0
- package/docs/reference/editors.md +5 -0
- package/docs/reference/grid.md +39 -0
- package/docs/reference/react.md +86 -0
- package/docs/reference/selection.md +33 -0
- package/docs/reference/views.md +601 -0
- package/package.json +7 -3
- package/skills/views/SKILL.md +20 -5
- package/dist/filters/types.d.ts +0 -27
- package/dist/filters/types.js +0 -1
- package/dist/model/filter-pushdown.d.ts +0 -106
- package/dist/model/filter-pushdown.js +0 -147
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
+
import { useViews } from "../../provider/context.js";
|
|
4
|
+
import { cx } from "../../internal/cx.js";
|
|
5
|
+
import { GridHeadCheck } from "./checks.js";
|
|
6
|
+
import { StuckMarker } from "./StuckMarker.js";
|
|
7
|
+
import { GridFrozenShadow } from "./GridCellOutline.js";
|
|
8
|
+
import { GridGroupMenu } from "./GridGroupMenu.js";
|
|
9
|
+
import { GRID_BLEED, GRID_HEADER_BG, GRID_ROW_PAD } from "./grid-styles.js";
|
|
10
|
+
function GridCollapseRegion({ collapsed, children, }) {
|
|
11
|
+
const { Collapse } = useViews().components;
|
|
12
|
+
return (_jsx(Collapse, { open: !collapsed, clipClassName: cx("pt-[2px] mt-[-2px] pb-2 -mb-2", GRID_BLEED, GRID_ROW_PAD), children: children }));
|
|
13
|
+
}
|
|
14
|
+
function GridRowsScroller({ minWidth, surface, children, }) {
|
|
15
|
+
const { register, onScroll, className } = surface;
|
|
16
|
+
return (_jsx(_Fragment, { children: _jsxs("div", { className: cx("relative flow-root", GRID_BLEED), children: [_jsx("div", { ref: register, onScroll: onScroll, "data-grid-scroller": true, className: cx(className, "pt-[2px] mt-[-2px] pb-2 -mb-2"), children: _jsx("div", { style: { minWidth }, children: children }) }), _jsx(GridFrozenShadow, {})] }) }));
|
|
17
|
+
}
|
|
18
|
+
function GridGroupSection({ group, collapsed, count, isMobile, selectable, sort, sortOptions, groupSummary, onToggleGroup, onGroupSummaryChange, renderGroupLabel, onHideGroup, figures, countNoun, renderHeader, renderGroupCheckbox, renderRow, renderFooter, minWidth, surface, headerWheelRef, headerPanHandlers, }) {
|
|
19
|
+
const { icons, messages } = useViews();
|
|
20
|
+
const Caret = collapsed ? icons.caretRight : icons.caretDown;
|
|
21
|
+
const summaryParts = groupSummary ?? [];
|
|
22
|
+
const shownFigures = (figures ?? []).filter((figure) => summaryParts.includes(figure.part));
|
|
23
|
+
const parts = [];
|
|
24
|
+
if (summaryParts.includes("count")) {
|
|
25
|
+
const noun = countNoun ? (count === 1 ? countNoun.one : countNoun.other) : null;
|
|
26
|
+
parts.push({ key: "count", node: noun ? `${count} ${noun}` : count });
|
|
27
|
+
}
|
|
28
|
+
for (const figure of shownFigures) {
|
|
29
|
+
parts.push({
|
|
30
|
+
key: figure.part,
|
|
31
|
+
node: (_jsxs(_Fragment, { children: [figure.label, " ", figure.render(group)] })),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
return (_jsxs("div", { "data-slot": "vk-grid-group", className: "mt-5 first:mt-0", children: [_jsx(StuckMarker, {}), _jsxs("div", { className: cx("sticky top-(--vk-pinned-top,0px) z-30 touch-pan-y data-[stuck=true]:bg-(color:--vk-ground)", GRID_HEADER_BG, GRID_BLEED, GRID_ROW_PAD), ref: headerWheelRef, ...headerPanHandlers, children: [_jsxs("div", { "data-slot": "vk-grid-group-header", className: "group/gridlabel relative mb-1.5 flex h-(--vk-label-h) select-none items-center gap-2", children: [_jsx("button", { type: "button", "aria-label": messages({ key: collapsed ? "views.grid.group-expand" : "views.grid.group-collapse" }), "aria-expanded": !collapsed, onClick: () => onToggleGroup?.(group.key), className: "flex h-6 w-6 shrink-0 items-center justify-center rounded-sm text-(color:--vk-fg-subtle) hover:bg-(color:--vk-hovered) hover:text-(color:--vk-fg)", children: _jsx(Caret, { className: "h-(--vk-glyph) w-(--vk-glyph)" }) }), _jsx("span", { className: "ml-[calc(var(--vk-px)-0.5rem-(1.5rem-var(--vk-glyph))/2)] truncate text-(length:--vk-text) font-medium", children: renderGroupLabel?.(group) ?? group.label ?? "—" }), parts.length > 0 && (_jsx("span", { className: "ml-[calc(var(--vk-px)-0.5rem)] flex min-w-0 items-baseline gap-1.5 overflow-hidden text-(length:--vk-text) text-(color:--vk-fg-subtle) tabular-nums", children: parts.map((part) => (_jsxs("span", { className: "flex items-baseline gap-1.5 whitespace-nowrap", children: [_jsx("span", { className: "text-(color:--vk-fg-subtlest)", children: "\u00B7" }), _jsx("span", { children: part.node })] }, part.key))) })), ((sort && sortOptions && sortOptions.length > 0) || onHideGroup) && (_jsx(GridGroupMenu, { sort: sort, sortOptions: sortOptions ?? [], summary: summaryParts, onSummaryChange: onGroupSummaryChange, figures: figures, onHide: onHideGroup ? () => onHideGroup(group.key) : undefined }))] }), !isMobile && (_jsx(GridCollapseRegion, { collapsed: collapsed, children: renderHeader(false, selectable ? renderGroupCheckbox(group.items) : undefined) }))] }), _jsx(GridCollapseRegion, { collapsed: collapsed, children: _jsxs(GridRowsScroller, { minWidth: minWidth, surface: surface, children: [isMobile && renderHeader(true), group.items.map((row, index, items) => renderRow(row, index, items, group.key)), renderFooter(group)] }) })] }));
|
|
35
|
+
}
|
|
36
|
+
export function GridBody({ empty, emptyState, grouped, groups, rows, isMobile, selectable, selecting, allSelected, someSelected, selectAll, clearSelection, isCollapsed, countOf, sort, sortOptions, groupSummary, onToggleGroup, onGroupSummaryChange, renderGroupLabel, onHideGroup, figures, countNoun, renderHeader, renderGroupCheckbox, renderRow, renderFooter, minWidth, surface, headerWheelRef, headerPanHandlers, }) {
|
|
37
|
+
const { messages } = useViews();
|
|
38
|
+
if (empty) {
|
|
39
|
+
return (_jsxs(_Fragment, { children: [renderHeader(false), emptyState] }));
|
|
40
|
+
}
|
|
41
|
+
if (!grouped) {
|
|
42
|
+
return (_jsxs(_Fragment, { children: [!isMobile && _jsx(StuckMarker, {}), !isMobile && (_jsx("div", { className: cx("sticky top-(--vk-pinned-top,0px) z-20 data-[stuck=true]:bg-(color:--vk-ground)", GRID_HEADER_BG), ref: headerWheelRef, children: renderHeader(false, selectable ? (_jsx(GridHeadCheck, { selecting: selecting, allSelected: allSelected, someSelected: someSelected, onToggle: (next) => (next ? selectAll() : clearSelection()), "aria-label": messages({ key: "views.grid.select-all" }) })) : undefined) })), _jsxs(GridRowsScroller, { minWidth: minWidth, surface: surface, children: [isMobile && renderHeader(true), rows.map((row, index, items) => renderRow(row, index, items, groups[0]?.key ?? "__all__")), groups[0] != null && renderFooter(groups[0])] })] }));
|
|
43
|
+
}
|
|
44
|
+
return groups.map((group) => (_jsx(GridGroupSection, { group: group, collapsed: isCollapsed?.(group.key) ?? false, count: countOf ? countOf(group) : group.items.length, isMobile: isMobile, selectable: selectable, sort: sort, sortOptions: sortOptions, groupSummary: groupSummary, onToggleGroup: onToggleGroup, onGroupSummaryChange: onGroupSummaryChange, renderGroupLabel: renderGroupLabel, onHideGroup: onHideGroup, figures: figures, countNoun: countNoun, renderHeader: renderHeader, renderGroupCheckbox: renderGroupCheckbox, renderRow: renderRow, renderFooter: renderFooter, minWidth: minWidth, surface: surface, headerWheelRef: headerWheelRef, headerPanHandlers: headerPanHandlers }, group.key)));
|
|
45
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { GridTableProps } from "./grid-table-props.js";
|
|
2
|
+
export type { GridTableProps } from "./grid-table-props.js";
|
|
3
|
+
/** Spreadsheet sibling to ListView, including editing and synchronized grouped rails. */
|
|
4
|
+
export declare function GridTable<Row>(props: GridTableProps<Row>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useDeferredValue, useMemo, useRef } from "react";
|
|
4
|
+
import { useViews } from "../../provider/context.js";
|
|
5
|
+
import { GridRailProbe, useGridRailReveal } from "./useGridRailReveal.js";
|
|
6
|
+
import { useGridBatchApi } from "./useGridBatchApi.js";
|
|
7
|
+
import { gridRowKey } from "../core/coordinates.js";
|
|
8
|
+
import { useIsMobile } from "../../internal/viewport.js";
|
|
9
|
+
import { GridRow } from "./GridRow.js";
|
|
10
|
+
import { GridHeadCheck } from "./checks.js";
|
|
11
|
+
import { useGridColumnLayout } from "./useGridColumnLayout.js";
|
|
12
|
+
import { useGridScrollSync } from "./useGridScrollSync.js";
|
|
13
|
+
import { GridHeader } from "./GridHeader.js";
|
|
14
|
+
import { GridFooter } from "./GridFooter.js";
|
|
15
|
+
import { GridBody } from "./GridStructure.js";
|
|
16
|
+
import { useGridScaleStyles } from "./useGridScaleStyles.js";
|
|
17
|
+
import { useGridTableInteractionModel } from "./useGridTableInteractionModel.js";
|
|
18
|
+
import { useGridTableSelection } from "./useGridTableSelection.js";
|
|
19
|
+
import { useGridHeaderDrag } from "./useGridHeaderDrag.js";
|
|
20
|
+
import { GridTableSurface } from "./GridTableSurface.js";
|
|
21
|
+
export function GridTable(props) {
|
|
22
|
+
const { atoms, messages } = useViews();
|
|
23
|
+
const { Loading } = atoms;
|
|
24
|
+
const deferredKey = useDeferredValue(props.transitionKey);
|
|
25
|
+
if (props.transitionPending || !Object.is(deferredKey, props.transitionKey)) {
|
|
26
|
+
return _jsx(Loading, { placement: "body", label: props.transitionLabel ?? messages({ key: "views.grid.loading" }) });
|
|
27
|
+
}
|
|
28
|
+
return _jsx(GridTableContent, { ...props });
|
|
29
|
+
}
|
|
30
|
+
function GridTableContent(props) {
|
|
31
|
+
const { groups, grouped, getRowId, columns, isCollapsed, onToggleGroup, renderGroupLabel, onHideGroup, renderAggregate, countOf, onOpenRow, onPrefetchRow, rowHref, rowClassName, onRowDelete, rowActions, rowIcon, showRowIcon = true, freezeIdentity = true, selection, loadMore, emptyState, sort, groupBy, sortOptions, groupSummary, aggregates, onAggregateChange, onGroupSummaryChange, groupFigures, countNoun, optionColors, onOptionColorChange, dateStyles, onDateStyleChange, durationStyles, onDurationStyleChange, numberFormats, onNumberFormatChange, showTimeOverrides, onShowTimeChange, percentDisplays, onPercentDisplayChange, columnState, onColumnStateChange, listConfig, } = props;
|
|
32
|
+
const { atoms, messages } = useViews();
|
|
33
|
+
const { LoadMore } = atoms;
|
|
34
|
+
const verticalBorders = props.verticalBorders ?? true;
|
|
35
|
+
const wrapCells = props.wrapCells ?? false;
|
|
36
|
+
const scale = props.scale ?? 1;
|
|
37
|
+
const isMobile = useIsMobile();
|
|
38
|
+
const rootRef = useRef(null);
|
|
39
|
+
const { visibleColumns, widthVarsStyle, frozenCount, frozenLeft, columnManager, gridTemplate, minWidth, resizingId, startResize, moveResize, endResize, resetColumnWidth, hideColumn, moveColumn, } = useGridColumnLayout({
|
|
40
|
+
rootRef,
|
|
41
|
+
columns,
|
|
42
|
+
columnState,
|
|
43
|
+
onColumnStateChange,
|
|
44
|
+
scale,
|
|
45
|
+
freezeIdentity,
|
|
46
|
+
viewBacked: props.viewBacked,
|
|
47
|
+
});
|
|
48
|
+
const showAddColumn = !!columnManager && !isMobile;
|
|
49
|
+
const scaleVarsStyle = useGridScaleStyles(scale, grouped, isMobile, showAddColumn);
|
|
50
|
+
const flatRows = useMemo(() => groups.flatMap((g) => g.items), [groups]);
|
|
51
|
+
const rowIndex = useMemo(() => {
|
|
52
|
+
const byKey = new Map();
|
|
53
|
+
for (const group of groups) {
|
|
54
|
+
for (const row of group.items) {
|
|
55
|
+
const rowId = getRowId(row);
|
|
56
|
+
const key = gridRowKey(group.key, rowId);
|
|
57
|
+
byKey.set(key, { key, rowId, row });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return byKey;
|
|
61
|
+
}, [groups, getRowId]);
|
|
62
|
+
const visibleRowKeys = useMemo(() => [...rowIndex.keys()], [rowIndex]);
|
|
63
|
+
const { selectable, selecting, selectionState: sel, checkDrag, groupSelection, } = useGridTableSelection({
|
|
64
|
+
rootRef,
|
|
65
|
+
groups,
|
|
66
|
+
grouped,
|
|
67
|
+
isCollapsed,
|
|
68
|
+
getRowId,
|
|
69
|
+
selection,
|
|
70
|
+
});
|
|
71
|
+
const visibleColIds = useMemo(() => visibleColumns.map((c) => c.id), [visibleColumns]);
|
|
72
|
+
const { rowSpansMap, selectValuesByColumn, onRangeCopy, onRangeCut, onRangeClear, onRangePaste, onPasteAtCell, inActiveRange, rangeCanClear, editingEnabled, focusedCell, editingCell, pendingByRow, settlementByRow, editSeed, focusCellSync, startEditSync, cancelEdit, commitEdit, commitBatch, refuseEdit, onExtendCell, onAddCell, handleRootPointerDown, handleRootPointerDownCapture, handleRootClickCapture, onEditorTab, onEditorEnter, } = useGridTableInteractionModel({
|
|
73
|
+
rootRef,
|
|
74
|
+
props,
|
|
75
|
+
rows: flatRows,
|
|
76
|
+
visibleRows: visibleRowKeys,
|
|
77
|
+
rowIndex,
|
|
78
|
+
visibleColumns,
|
|
79
|
+
selecting,
|
|
80
|
+
});
|
|
81
|
+
const { scrollXRef, getScroller, surface, registerHeader, headerWheelRef, headerPanHandlers } = useGridScrollSync(rootRef);
|
|
82
|
+
const total = useMemo(() => groups.reduce((n, g) => n + g.items.length, 0), [groups]);
|
|
83
|
+
const empty = grouped ? groups.length === 0 : total === 0;
|
|
84
|
+
const rail = useGridRailReveal({ rootRef, earned: selecting || !!props.alwaysCheckboxes });
|
|
85
|
+
const batchApi = useGridBatchApi({
|
|
86
|
+
enabled: editingEnabled,
|
|
87
|
+
columns: visibleColumns,
|
|
88
|
+
listConfig,
|
|
89
|
+
rows: flatRows,
|
|
90
|
+
getRowId,
|
|
91
|
+
pendingByRow,
|
|
92
|
+
commitBatch,
|
|
93
|
+
});
|
|
94
|
+
const headerDrag = useGridHeaderDrag({
|
|
95
|
+
columns,
|
|
96
|
+
columnState,
|
|
97
|
+
onColumnStateChange,
|
|
98
|
+
visibleColumnIds: visibleColIds,
|
|
99
|
+
scrollXRef,
|
|
100
|
+
getScroller,
|
|
101
|
+
viewBacked: props.viewBacked,
|
|
102
|
+
});
|
|
103
|
+
const rowRangeFor = (rowKey) => rowSpansMap.get(rowKey);
|
|
104
|
+
const renderRow = (row, index, items, groupKey) => {
|
|
105
|
+
const rowId = getRowId(row);
|
|
106
|
+
const rowKey = gridRowKey(groupKey, rowId);
|
|
107
|
+
const above = index > 0 ? items[index - 1] : null;
|
|
108
|
+
return (_jsx(GridRow, { row: row, id: rowId, rowKey: rowKey, gridTemplate: gridTemplate, columns: visibleColumns, selectable: selectable, selected: sel.isSelected(rowId), selectedAbove: above != null && sel.isSelected(getRowId(above)), selecting: selecting, toggle: sel.toggle, toggleRange: sel.toggleRange, contextMenu: props.contextMenu ?? props.rowMenu, rowClassName: rowClassName, rowHref: rowHref, onOpenRow: onOpenRow, onPrefetchRow: onPrefetchRow, onOpenRelation: props.onOpenRelation, entityIcon: props.entityIcon, commands: props.commands, onRowDelete: onRowDelete, deleteLabel: props.deleteLabel, rowActions: rowActions, rowIcon: showRowIcon ? rowIcon : undefined, frozenCount: frozenCount, frozenLeft: frozenLeft, verticalBorders: verticalBorders, wrapCells: wrapCells, optionColors: optionColors, dateStyles: dateStyles, durationStyles: durationStyles, numberFormats: numberFormats, showTimeOverrides: showTimeOverrides, percentDisplays: percentDisplays, editingEnabled: editingEnabled, listConfig: listConfig, focusedColId: focusedCell?.rowId === rowKey ? focusedCell.columnId : null, editingColId: editingCell?.rowId === rowKey ? editingCell.columnId : null, editSeed: editingCell?.rowId === rowKey ? editSeed : null, onEditorTab: onEditorTab, onEditorEnter: onEditorEnter, pendingByCol: pendingByRow.get(rowId), settlementByCol: settlementByRow.get(rowId), selectValues: selectValuesByColumn, rowRange: rowRangeFor(rowKey), onFocusCell: focusCellSync, onStartEdit: startEditSync, onRefuseEdit: refuseEdit, onExtendCell: onExtendCell, onAddCell: onAddCell, onCommitCell: commitEdit, onCancelEdit: cancelEdit, inActiveRange: inActiveRange, rangeCanClear: rangeCanClear, onRangeCopy: onRangeCopy, onRangeCut: onRangeCut, onRangePaste: onRangePaste, onRangeClear: onRangeClear, onPasteAtCell: onPasteAtCell }, rowKey));
|
|
109
|
+
};
|
|
110
|
+
const header = (inline, checkbox) => (_jsx(GridHeader, { inline: inline, showAddColumn: showAddColumn && !inline, checkbox: checkbox, columns: visibleColumns, columnManager: columnManager, gridTemplate: gridTemplate, minWidth: minWidth, sort: sort, selectValues: selectValuesByColumn, optionColors: optionColors, onOptionColorChange: onOptionColorChange, dateStyles: dateStyles, onDateStyleChange: onDateStyleChange, durationStyles: durationStyles, onDurationStyleChange: onDurationStyleChange, numberFormats: numberFormats, onNumberFormatChange: onNumberFormatChange, showTimeOverrides: showTimeOverrides, onShowTimeChange: onShowTimeChange, percentDisplays: percentDisplays, onPercentDisplayChange: onPercentDisplayChange, columnStateEnabled: !!onColumnStateChange, listConfig: listConfig, groupBy: groupBy, viewBacked: props.viewBacked, formatsWritable: props.formatsWritable, renderAddColumn: props.renderAddColumn, renderColumnMenuRows: props.renderColumnMenuRows, resizingId: resizingId, startResize: startResize, moveResize: moveResize, endResize: endResize, resetColumnWidth: resetColumnWidth, hideColumn: hideColumn, moveColumn: moveColumn, headerDrag: headerDrag, registerHeader: registerHeader, frozenCount: frozenCount, frozenLeft: frozenLeft }));
|
|
111
|
+
const footer = (group) => (_jsx(GridFooter, { group: group, columns: visibleColumns, gridTemplate: gridTemplate, selecting: selecting, aggregates: aggregates, numberFormats: numberFormats, renderAggregate: renderAggregate, onAggregateChange: onAggregateChange, viewBacked: props.viewBacked, frozenCount: frozenCount, frozenLeft: frozenLeft, continuation: props.renderGroupFooter?.(group), defaultCurrency: props.defaultCurrency }));
|
|
112
|
+
const groupCheckbox = (items) => (_jsx(GridHeadCheck, { selecting: selecting, ...groupSelection(items), "aria-label": messages({ key: "views.grid.select-group" }) }));
|
|
113
|
+
return (_jsx(GridTableSurface, { rootRef: rootRef, style: { ...widthVarsStyle, ...scaleVarsStyle }, selecting: selecting, railRootProps: rail.rootProps, onPointerDown: (event) => {
|
|
114
|
+
if (checkDrag.tryArm(event))
|
|
115
|
+
return;
|
|
116
|
+
handleRootPointerDown(event);
|
|
117
|
+
}, onPointerDownCapture: handleRootPointerDownCapture, onClickCapture: (event) => {
|
|
118
|
+
if (checkDrag.consumeDrag()) {
|
|
119
|
+
event.preventDefault();
|
|
120
|
+
event.stopPropagation();
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
handleRootClickCapture(event);
|
|
124
|
+
}, railProbe: _jsx(GridRailProbe, { probeRef: rail.probeRef }), body: _jsx(GridBody, { empty: empty, emptyState: emptyState, grouped: grouped, groups: groups, rows: flatRows, isMobile: isMobile, selectable: selectable, selecting: selecting, allSelected: sel.allSelected, someSelected: sel.someSelected, selectAll: sel.selectAll, clearSelection: sel.clear, isCollapsed: isCollapsed, countOf: countOf, sort: sort, sortOptions: sortOptions, groupSummary: groupSummary, onToggleGroup: onToggleGroup, onGroupSummaryChange: onGroupSummaryChange, renderGroupLabel: renderGroupLabel, onHideGroup: onHideGroup, figures: groupFigures, countNoun: countNoun, renderHeader: header, renderGroupCheckbox: groupCheckbox, renderRow: renderRow, renderFooter: footer, minWidth: minWidth, surface: surface, headerWheelRef: headerWheelRef, headerPanHandlers: headerPanHandlers }), loadMore: loadMore?.hasMore ? _jsx(LoadMore, { onReveal: loadMore.onReveal, label: loadMore.label }) : undefined, selectionBar: selection?.renderBar(sel, batchApi) }));
|
|
125
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { CSSProperties, HTMLAttributes, PointerEventHandler, MouseEventHandler, ReactNode, RefObject } from "react";
|
|
2
|
+
export declare function GridTableSurface({ rootRef, style, selecting, railRootProps, onPointerDown, onPointerDownCapture, onClickCapture, railProbe, body, loadMore, selectionBar, }: {
|
|
3
|
+
rootRef: RefObject<HTMLDivElement | null>;
|
|
4
|
+
style: CSSProperties;
|
|
5
|
+
selecting: boolean;
|
|
6
|
+
railRootProps: HTMLAttributes<HTMLDivElement>;
|
|
7
|
+
onPointerDown: PointerEventHandler<HTMLDivElement>;
|
|
8
|
+
/** Marks a press as the grid's own, its portaled popups' included: the click-away reads it. */
|
|
9
|
+
onPointerDownCapture: PointerEventHandler<HTMLDivElement>;
|
|
10
|
+
onClickCapture: MouseEventHandler<HTMLDivElement>;
|
|
11
|
+
railProbe: ReactNode;
|
|
12
|
+
body: ReactNode;
|
|
13
|
+
loadMore?: ReactNode;
|
|
14
|
+
selectionBar?: ReactNode;
|
|
15
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cx } from "../../internal/cx.js";
|
|
4
|
+
export function GridTableSurface({ rootRef, style, selecting, railRootProps, onPointerDown, onPointerDownCapture, onClickCapture, railProbe, body, loadMore, selectionBar, }) {
|
|
5
|
+
return (_jsxs("div", { ref: rootRef, style: style, className: cx("group/gridtable relative animate-fade-in", selecting && "pb-14"), "data-slot": "vk-grid", ...railRootProps, onPointerDown: onPointerDown, onPointerDownCapture: onPointerDownCapture, onClickCapture: onClickCapture, children: [body, loadMore, selectionBar, railProbe] }));
|
|
6
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function GridTextEditor({ initial, strong, onCommit, onCancel, onTab, onEnter, }: {
|
|
2
|
+
initial: string;
|
|
3
|
+
/** Title columns render medium-weight — match it while editing. */
|
|
4
|
+
strong?: boolean;
|
|
5
|
+
onCommit: (value: string) => void;
|
|
6
|
+
onCancel: () => void;
|
|
7
|
+
/** Commit happened via Tab — move to the next cell in reading order. */
|
|
8
|
+
onTab?: (backwards: boolean) => void;
|
|
9
|
+
/** Commit happened via Enter — advance one row down (Sheets). */
|
|
10
|
+
onEnter?: () => void;
|
|
11
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
import { cx } from "../../internal/cx.js";
|
|
5
|
+
export function GridTextEditor({ initial, strong = false, onCommit, onCancel, onTab, onEnter, }) {
|
|
6
|
+
const inputRef = useRef(null);
|
|
7
|
+
const doneRef = useRef(false);
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const el = inputRef.current;
|
|
10
|
+
if (!el)
|
|
11
|
+
return;
|
|
12
|
+
el.focus();
|
|
13
|
+
const len = el.value.length;
|
|
14
|
+
el.setSelectionRange(len, len);
|
|
15
|
+
}, []);
|
|
16
|
+
const commit = () => {
|
|
17
|
+
if (doneRef.current)
|
|
18
|
+
return;
|
|
19
|
+
doneRef.current = true;
|
|
20
|
+
onCommit(inputRef.current?.value ?? "");
|
|
21
|
+
};
|
|
22
|
+
return (_jsx("input", { ref: inputRef, defaultValue: initial, "data-slot": "vk-grid-editor", "data-grid-editor": true, onKeyDown: (e) => {
|
|
23
|
+
e.stopPropagation();
|
|
24
|
+
if (e.key === "Enter") {
|
|
25
|
+
e.preventDefault();
|
|
26
|
+
commit();
|
|
27
|
+
onEnter?.();
|
|
28
|
+
}
|
|
29
|
+
else if (e.key === "Escape") {
|
|
30
|
+
doneRef.current = true;
|
|
31
|
+
onCancel();
|
|
32
|
+
}
|
|
33
|
+
else if (e.key === "Tab") {
|
|
34
|
+
e.preventDefault();
|
|
35
|
+
const backwards = e.shiftKey;
|
|
36
|
+
commit();
|
|
37
|
+
onTab?.(backwards);
|
|
38
|
+
}
|
|
39
|
+
}, onBlur: () => commit(), onClick: (e) => e.stopPropagation(), className: cx("h-full w-full min-w-0 select-text bg-transparent text-(length:--vk-text) text-(color:--vk-fg) outline-hidden placeholder:text-(color:--vk-fg-subtlest)", strong && "font-medium") }));
|
|
40
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FieldDefOf, MultipleType, ValueItem } from "@viewkitjs/fields";
|
|
2
|
+
/**
|
|
3
|
+
* The GRID's host around the shared `ValueListEditor`. Anchored, like the name
|
|
4
|
+
* editor: a list of rows does not fit a cell, so it opens in a panel under it
|
|
5
|
+
* while the cell's own values stay on screen. No seed: a key typed on a list
|
|
6
|
+
* cell opens the list as it is (`useGridKeyboard`'s `seedable`).
|
|
7
|
+
*/
|
|
8
|
+
export declare function GridValueListEditor({ field, initial, labels, allowEmpty, onCommit, onCancel, onTab, onEnter, }: {
|
|
9
|
+
field: FieldDefOf<MultipleType>;
|
|
10
|
+
initial: unknown;
|
|
11
|
+
labels: boolean;
|
|
12
|
+
allowEmpty?: boolean;
|
|
13
|
+
onCommit: (payload: ValueItem<unknown>[] | null) => void;
|
|
14
|
+
onCancel: () => void;
|
|
15
|
+
onTab?: (backwards: boolean) => void;
|
|
16
|
+
/** Commit happened via Enter — advance one row down. */
|
|
17
|
+
onEnter?: () => void;
|
|
18
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useRef } from "react";
|
|
4
|
+
import { useAnchoredEditSession } from "../../editors/edit-session.js";
|
|
5
|
+
import { ValueListEditor } from "../../editors/ValueListEditor.js";
|
|
6
|
+
import { useViews } from "../../provider/context.js";
|
|
7
|
+
export function GridValueListEditor({ field, initial, labels, allowEmpty = false, onCommit, onCancel, onTab, onEnter, }) {
|
|
8
|
+
const { Popover } = useViews().components;
|
|
9
|
+
const anchorRef = useRef(null);
|
|
10
|
+
const editorRef = useRef(null);
|
|
11
|
+
const viaRef = useRef(null);
|
|
12
|
+
const { open, close } = useAnchoredEditSession({
|
|
13
|
+
editorRef,
|
|
14
|
+
onDone: (resolution) => {
|
|
15
|
+
if (resolution.kind === "commit") {
|
|
16
|
+
onCommit(resolution.payload);
|
|
17
|
+
if (viaRef.current === "enter")
|
|
18
|
+
onEnter?.();
|
|
19
|
+
if (viaRef.current === "tab")
|
|
20
|
+
onTab?.(false);
|
|
21
|
+
if (viaRef.current === "shift-tab")
|
|
22
|
+
onTab?.(true);
|
|
23
|
+
}
|
|
24
|
+
else
|
|
25
|
+
onCancel();
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
const closeVia = (reason) => {
|
|
29
|
+
viaRef.current = reason;
|
|
30
|
+
close(reason);
|
|
31
|
+
};
|
|
32
|
+
return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(Popover, { open: open, onOpenChange: (next) => {
|
|
33
|
+
if (!next)
|
|
34
|
+
closeVia("outside");
|
|
35
|
+
}, anchor: anchorRef, align: "start", sideOffset: 4, onEscape: () => closeVia("escape"), onOutsidePress: () => closeVia("outside"), initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "z-90 w-96 p-2", children: _jsx(ValueListEditor, { ref: editorRef, field: field, initial: initial, labels: labels, allowEmpty: allowEmpty, onRequestClose: closeVia }) })] }));
|
|
36
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Says when the sticky header right after it is STUCK — `data-stuck="true"`
|
|
3
|
+
* on that header, while it stands below where it would rest (Mihai,
|
|
4
|
+
* 2026-10-05).
|
|
5
|
+
*
|
|
6
|
+
* The header's ground leaves a 2px sliver at its foot see-through
|
|
7
|
+
* (GRID_HEADER_BG): at rest it is where the first row's selection ring draws
|
|
8
|
+
* its top edge. Stuck, rows pass under the header, and through that sliver a
|
|
9
|
+
* row's top showed a pixel or two above the header's line. So the header goes
|
|
10
|
+
* solid while stuck (`data-[stuck=true]:bg-(color:--vk-ground)`) and keeps the sliver
|
|
11
|
+
* at rest, where nothing passes under it.
|
|
12
|
+
*
|
|
13
|
+
* Zero-height and in flow, so it marks exactly where the header would rest;
|
|
14
|
+
* the header is stuck once its top has left that mark.
|
|
15
|
+
*/
|
|
16
|
+
export declare function StuckMarker(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
export function StuckMarker() {
|
|
5
|
+
const ref = useRef(null);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
const marker = ref.current;
|
|
8
|
+
const header = marker?.nextElementSibling;
|
|
9
|
+
if (!marker || !header)
|
|
10
|
+
return;
|
|
11
|
+
let raf = 0;
|
|
12
|
+
const apply = () => {
|
|
13
|
+
raf = 0;
|
|
14
|
+
const stuck = header.getBoundingClientRect().top - marker.getBoundingClientRect().top > 0.5;
|
|
15
|
+
if ((header.dataset.stuck === "true") !== stuck)
|
|
16
|
+
header.dataset.stuck = String(stuck);
|
|
17
|
+
};
|
|
18
|
+
const schedule = () => {
|
|
19
|
+
if (!raf)
|
|
20
|
+
raf = requestAnimationFrame(apply);
|
|
21
|
+
};
|
|
22
|
+
apply();
|
|
23
|
+
window.addEventListener("scroll", schedule, true);
|
|
24
|
+
window.addEventListener("resize", schedule);
|
|
25
|
+
return () => {
|
|
26
|
+
window.removeEventListener("scroll", schedule, true);
|
|
27
|
+
window.removeEventListener("resize", schedule);
|
|
28
|
+
if (raf)
|
|
29
|
+
cancelAnimationFrame(raf);
|
|
30
|
+
delete header.dataset.stuck;
|
|
31
|
+
};
|
|
32
|
+
}, []);
|
|
33
|
+
return _jsx("div", { ref: ref, "aria-hidden": true, className: "h-0" });
|
|
34
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ViewsClipboardPort } from "../../provider/ports.js";
|
|
2
|
+
import { type GridCellClipboard, type GridClipboardCell } from "../core/clipboard-model.js";
|
|
3
|
+
import type { ListColumn } from "../../model/column-schema.js";
|
|
4
|
+
export { cellClearPrev, cellEditBaseline, cellPrevPayload, rowHoldsCurrency, coercePaste, parseTsvText, type GridPasteSource, } from "../core/clipboard-model.js";
|
|
5
|
+
export declare function getGridClipboard(): GridCellClipboard | null;
|
|
6
|
+
/** Puts one cell's text on the system clipboard through the app's port, and keeps the typed entry
|
|
7
|
+
* the grid pastes from — which survives a refused system write. */
|
|
8
|
+
export declare function copyCell<Row>(write: ViewsClipboardPort["writeText"], col: ListColumn<Row>, baseline: unknown, unit?: string): Promise<string>;
|
|
9
|
+
export declare function copyCells(write: ViewsClipboardPort["writeText"], matrix: GridClipboardCell[][]): Promise<string>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { cellCopyText, serializeClipboardMatrix, } from "../core/clipboard-model.js";
|
|
2
|
+
export { cellClearPrev, cellEditBaseline, cellPrevPayload, rowHoldsCurrency, coercePaste, parseTsvText, } from "../core/clipboard-model.js";
|
|
3
|
+
let clipboard = null;
|
|
4
|
+
export function getGridClipboard() {
|
|
5
|
+
return clipboard;
|
|
6
|
+
}
|
|
7
|
+
export async function copyCell(write, col, baseline, unit) {
|
|
8
|
+
const text = cellCopyText(col, baseline);
|
|
9
|
+
clipboard = { text, value: baseline, type: col.type, unit };
|
|
10
|
+
try {
|
|
11
|
+
await write(text);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
}
|
|
15
|
+
return text;
|
|
16
|
+
}
|
|
17
|
+
export async function copyCells(write, matrix) {
|
|
18
|
+
if (matrix.length === 0 || matrix[0].length === 0)
|
|
19
|
+
return "";
|
|
20
|
+
const text = serializeClipboardMatrix(matrix);
|
|
21
|
+
clipboard = { ...matrix[0][0], text, matrix };
|
|
22
|
+
try {
|
|
23
|
+
await write(text);
|
|
24
|
+
}
|
|
25
|
+
catch {
|
|
26
|
+
}
|
|
27
|
+
return text;
|
|
28
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import type { GridCellOptions } from "../../cells/cell-format.js";
|
|
3
|
+
import type { ListColumn } from "../../model/column-schema.js";
|
|
4
|
+
export { formatDate, formatNumber } from "../../cells/cell-format.js";
|
|
5
|
+
/**
|
|
6
|
+
* Renders a typed cell, then appends the column's `indicator` if it has one.
|
|
7
|
+
*
|
|
8
|
+
* `indicator` is declared on EVERY column in the schema but used to be read only
|
|
9
|
+
* inside the `title` branch — so it looked generic and was honoured by exactly
|
|
10
|
+
* one type. That gap is why a column needing a per-row adornment (Subscriptions'
|
|
11
|
+
* next-charge urgency) reached for a full custom `render` instead, throwing away
|
|
12
|
+
* the typed renderer's date formatting and hover tooltip to get it.
|
|
13
|
+
*
|
|
14
|
+
* `title` still places its own indicator: its cell has layout rules about where
|
|
15
|
+
* the click target ends, and the adornment has to sit inside them.
|
|
16
|
+
*/
|
|
17
|
+
export declare function renderTypedCell<Row>(col: ListColumn<Row>, row: Row, opts?: GridCellOptions): ReactNode;
|
|
18
|
+
/** Renders an `action` column's cell — a centered row of icon buttons. Real
|
|
19
|
+
* `<button>`s so GridRow's click contract treats them as interactive (the row
|
|
20
|
+
* does not open / select on an action click). */
|
|
21
|
+
export declare function renderActionCell<Row>(col: ListColumn<Row>, row: Row): ReactNode;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cx } from "../../internal/cx.js";
|
|
4
|
+
import { GridActionButton } from "./GridRowActions.js";
|
|
5
|
+
import { renderTypedCellValue } from "../../cells/cell-values.js";
|
|
6
|
+
export { formatDate, formatNumber } from "../../cells/cell-format.js";
|
|
7
|
+
export function renderTypedCell(col, row, opts) {
|
|
8
|
+
const cell = renderTypedCellValue(col, row, opts);
|
|
9
|
+
if (col.type === "title")
|
|
10
|
+
return cell;
|
|
11
|
+
const indicator = col.indicator?.(row);
|
|
12
|
+
if (!indicator)
|
|
13
|
+
return cell;
|
|
14
|
+
return (_jsxs("span", { className: cx("flex min-w-0 flex-1 flex-wrap content-start items-center gap-x-1.5 overflow-hidden", !opts?.wrap && "h-(--vk-line-h) leading-(--vk-line-h)"), children: [_jsx("span", { className: cx("max-w-full", opts?.wrap ? "min-w-0" : "flex-none truncate"), children: cell }), indicator] }));
|
|
15
|
+
}
|
|
16
|
+
export function renderActionCell(col, row) {
|
|
17
|
+
if (!col.actions?.length)
|
|
18
|
+
return null;
|
|
19
|
+
return (_jsx("span", { className: "flex items-center justify-center gap-1", children: col.actions.map((a) => (_jsx(GridActionButton, { variant: "bare", label: a.label?.(row), onClick: a.onClick ? () => a.onClick?.(row) : undefined, children: a.icon(row) }, a.id))) }));
|
|
20
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** Empty rail segment — keeps the opaque lane continuous across the header and
|
|
2
|
+
* footer rows, which have no checkbox of their own. `bordered` follows whether
|
|
3
|
+
* that surface's own cells draw a bottom rule: the header's do, the footer's
|
|
4
|
+
* don't. */
|
|
5
|
+
export declare function GridRailSpacer({ selecting, bordered, }: {
|
|
6
|
+
selecting: boolean;
|
|
7
|
+
bordered?: boolean;
|
|
8
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
/** Row checkbox — reveals while the row (`group/gridrow`) is hovered. */
|
|
10
|
+
export declare function GridRowCheck({ selecting, checked, revealed, onChange, "aria-label": ariaLabel, }: {
|
|
11
|
+
selecting: boolean;
|
|
12
|
+
checked: boolean;
|
|
13
|
+
revealed: boolean;
|
|
14
|
+
onChange: (next: boolean, shift: boolean) => void;
|
|
15
|
+
"aria-label"?: string;
|
|
16
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
17
|
+
/**
|
|
18
|
+
* Select-all / group checkbox — the SAME rail slot the rows use, mounted as the
|
|
19
|
+
* header's leading track rather than as an overlay beside it.
|
|
20
|
+
*
|
|
21
|
+
* It used to be a page-anchored overlay, on the reasoning that the header strip
|
|
22
|
+
* sits outside the scrollers and its cells were slid by JS, so a checkbox in the
|
|
23
|
+
* flow would have had to be counter-translated. Both halves of that stopped
|
|
24
|
+
* being true: the strip is a real scroll container now, and the rail travels
|
|
25
|
+
* with its row instead of standing still. An overlay would be the one piece of
|
|
26
|
+
* leading chrome that didn't move — parked at a fixed x while every row's
|
|
27
|
+
* checkbox slid away from it and stopped somewhere else.
|
|
28
|
+
*/
|
|
29
|
+
export declare function GridHeadCheck({ selecting, allSelected, someSelected, onToggle, "aria-label": ariaLabel, }: {
|
|
30
|
+
selecting: boolean;
|
|
31
|
+
allSelected: boolean;
|
|
32
|
+
someSelected: boolean;
|
|
33
|
+
onToggle: (next: boolean) => void;
|
|
34
|
+
"aria-label"?: string;
|
|
35
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { useViews } from "../../provider/context.js";
|
|
4
|
+
import { cx } from "../../internal/cx.js";
|
|
5
|
+
import { gridFrozenBg } from "./GridCellOutline.js";
|
|
6
|
+
import { GRID_GROUND } from "./grid-styles.js";
|
|
7
|
+
import { SelectCheckbox } from "../../selection/SelectCheckbox.js";
|
|
8
|
+
function RailSlot({ selecting, selected = false, bordered = false, children, }) {
|
|
9
|
+
return (_jsx("div", { "data-slot": "vk-grid-rail", className: "sticky left-(--vk-rail-w) z-10 h-full", "data-action-menu": true, onClick: (e) => e.stopPropagation(), children: _jsxs("div", { "data-row-check": selecting ? "" : undefined, className: cx("relative flex h-full w-[calc(var(--vk-gutter,0px)+var(--vk-indent,0px))] -translate-x-full items-start justify-end", "pr-[calc(var(--vk-rail-gap)+((var(--vk-rail-w)-16px)/2-var(--vk-rail-gap))*var(--vk-parked,0)*(1-var(--vk-frozen-on,0)))]", "transition-[padding-right] duration-150"), children: [_jsx("span", { "aria-hidden": true, className: cx("absolute inset-0", gridFrozenBg(selected), "opacity-(--vk-frozen-on,0) transition-opacity duration-150", "group-data-[rail=on]/gridtable:opacity-100") }), bordered && (_jsx("span", { "aria-hidden": true, className: cx("pointer-events-none absolute inset-x-0 bottom-0 h-px bg-(color:--vk-border-subtle) transition-opacity duration-150", "opacity-[calc(var(--vk-parked,0)*var(--vk-frozen-on,0))]", "group-data-[rail=on]/gridtable:opacity-(--vk-parked,0)") })), children ? (_jsx("span", { "data-row-check": true, className: "relative flex h-(--vk-chrome-h,100%) items-center", children: children })) : null] }) }));
|
|
10
|
+
}
|
|
11
|
+
export function GridRailSpacer({ selecting, bordered = false, }) {
|
|
12
|
+
return _jsx(RailSlot, { selecting: selecting, bordered: bordered });
|
|
13
|
+
}
|
|
14
|
+
export function GridRowCheck({ selecting, checked, revealed, onChange, "aria-label": ariaLabel, }) {
|
|
15
|
+
return (_jsx(RailSlot, { selecting: selecting, selected: checked, bordered: true, children: _jsx(SelectCheckbox, { checked: checked, revealed: revealed, onChange: onChange, "aria-label": ariaLabel, className: cx(GRID_GROUND, "transition-opacity duration-150 group-hover/gridrow:opacity-100 group-data-[rail=on]/gridtable:opacity-100") }) }));
|
|
16
|
+
}
|
|
17
|
+
export function GridHeadCheck({ selecting, allSelected, someSelected, onToggle, "aria-label": ariaLabel, }) {
|
|
18
|
+
const { Checkbox } = useViews().components;
|
|
19
|
+
return (_jsx(RailSlot, { selecting: selecting, bordered: true, children: _jsx(Checkbox, { checked: allSelected, indeterminate: !allSelected && someSelected, onCheckedChange: (next) => onToggle(next), "aria-label": ariaLabel, partialTone: "brand", className: cx(cx(GRID_GROUND, "transition-opacity duration-150"), selecting || allSelected || someSelected
|
|
20
|
+
? "opacity-100"
|
|
21
|
+
: "opacity-0 group-hover/gridhead:opacity-100 group-data-[rail=on]/gridtable:opacity-100") }) }));
|
|
22
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ComponentType, ReactNode } from "react";
|
|
2
|
+
import type { ListColumn } from "../../model/column-schema.js";
|
|
3
|
+
import type { ViewsIcons } from "../../provider/icons.js";
|
|
4
|
+
type GridGlyphs = {
|
|
5
|
+
icons: ViewsIcons;
|
|
6
|
+
AppIcon: ComponentType<{
|
|
7
|
+
name: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
}>;
|
|
10
|
+
};
|
|
11
|
+
/** The column's glyph: its explicit `icon` → its binding's glyph → its field's type → a computed
|
|
12
|
+
* column's mark → its list type's → nothing. */
|
|
13
|
+
export declare function gridColumnGlyph<Row>({ icons, AppIcon }: GridGlyphs, col: ListColumn<Row>, className?: string): ReactNode;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
const LIST_TYPE_GLYPHS = {
|
|
4
|
+
title: "text",
|
|
5
|
+
status: "status",
|
|
6
|
+
text: "text",
|
|
7
|
+
number: "number",
|
|
8
|
+
percent: "percent",
|
|
9
|
+
currency: "currency",
|
|
10
|
+
date: "date",
|
|
11
|
+
datetime: "datetime",
|
|
12
|
+
select: "select",
|
|
13
|
+
multiselect: "multiselect",
|
|
14
|
+
boolean: "boolean",
|
|
15
|
+
relation: "relation",
|
|
16
|
+
user: "user",
|
|
17
|
+
url: "url",
|
|
18
|
+
domain: "domain",
|
|
19
|
+
email: "email",
|
|
20
|
+
phone: "phone",
|
|
21
|
+
location: "location",
|
|
22
|
+
name: "name",
|
|
23
|
+
actor: "actor",
|
|
24
|
+
rich_text: "rich_text",
|
|
25
|
+
range: "range",
|
|
26
|
+
};
|
|
27
|
+
export function gridColumnGlyph({ icons, AppIcon }, col, className = "h-3.5 w-3.5 shrink-0 opacity-70") {
|
|
28
|
+
if (col.icon)
|
|
29
|
+
return col.icon;
|
|
30
|
+
if (col.binding?.icon)
|
|
31
|
+
return _jsx(AppIcon, { name: col.binding.icon, className: className });
|
|
32
|
+
if (col.field) {
|
|
33
|
+
const Glyph = icons[col.field.type];
|
|
34
|
+
return _jsx(Glyph, { className: className });
|
|
35
|
+
}
|
|
36
|
+
if (col.custom) {
|
|
37
|
+
const Glyph = icons.computed;
|
|
38
|
+
return _jsx(Glyph, { className: className });
|
|
39
|
+
}
|
|
40
|
+
if (!col.type)
|
|
41
|
+
return null;
|
|
42
|
+
const Glyph = icons[LIST_TYPE_GLYPHS[col.type]];
|
|
43
|
+
return _jsx(Glyph, { className: className });
|
|
44
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { gridColumnHasEditor, gridEditorKind } from "../../model/column-capabilities.js";
|
|
2
|
+
export { GridTextEditor } from "./GridTextEditor.js";
|
|
3
|
+
export { GridLongTextEditor } from "./GridLongTextEditor.js";
|
|
4
|
+
export { GridSelectEditor } from "./GridSelectEditor.js";
|
|
5
|
+
export { GridChipsEditor } from "./GridChipsEditor.js";
|
|
6
|
+
export { GridNumberEditor } from "./GridNumberEditor.js";
|
|
7
|
+
export { GridRangeEditor } from "./GridRangeEditor.js";
|
|
8
|
+
export { GridDateEditor } from "./GridDateEditor.js";
|
|
9
|
+
export { GridRelationEditor } from "./GridRelationEditor.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
export { gridColumnHasEditor, gridEditorKind } from "../../model/column-capabilities.js";
|
|
3
|
+
export { GridTextEditor } from "./GridTextEditor.js";
|
|
4
|
+
export { GridLongTextEditor } from "./GridLongTextEditor.js";
|
|
5
|
+
export { GridSelectEditor } from "./GridSelectEditor.js";
|
|
6
|
+
export { GridChipsEditor } from "./GridChipsEditor.js";
|
|
7
|
+
export { GridNumberEditor } from "./GridNumberEditor.js";
|
|
8
|
+
export { GridRangeEditor } from "./GridRangeEditor.js";
|
|
9
|
+
export { GridDateEditor } from "./GridDateEditor.js";
|
|
10
|
+
export { GridRelationEditor } from "./GridRelationEditor.js";
|