184 lines
6.0 KiB
Plaintext
184 lines
6.0 KiB
Plaintext
"use client";
|
|
"use strict";
|
|
var __defProp = Object.defineProperty;
|
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __export = (target, all) => {
|
|
for (var name in all)
|
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
};
|
|
var __copyProps = (to, from, except, desc) => {
|
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
for (let key of __getOwnPropNames(from))
|
|
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
}
|
|
return to;
|
|
};
|
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
|
|
// src/use-table.ts
|
|
var use_table_exports = {};
|
|
__export(use_table_exports, {
|
|
useTable: () => useTable
|
|
});
|
|
module.exports = __toCommonJS(use_table_exports);
|
|
var import_react = require("react");
|
|
var import_table = require("@react-stately/table");
|
|
var import_table2 = require("@react-aria/table");
|
|
var import_system = require("@heroui/system");
|
|
var import_theme = require("@heroui/theme");
|
|
var import_react_utils = require("@heroui/react-utils");
|
|
var import_shared_utils = require("@heroui/shared-utils");
|
|
var import_react2 = require("react");
|
|
function useTable(originalProps) {
|
|
var _a;
|
|
const globalContext = (0, import_system.useProviderContext)();
|
|
const [props, variantProps] = (0, import_system.mapPropsVariants)(originalProps, import_theme.table.variantKeys);
|
|
const {
|
|
ref,
|
|
as,
|
|
baseRef,
|
|
children,
|
|
className,
|
|
classNames,
|
|
removeWrapper = false,
|
|
disableAnimation = (_a = globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _a : false,
|
|
isKeyboardNavigationDisabled = false,
|
|
selectionMode = "none",
|
|
topContentPlacement = "inside",
|
|
bottomContentPlacement = "inside",
|
|
selectionBehavior = selectionMode === "none" ? null : "toggle",
|
|
disabledBehavior = "selection",
|
|
showSelectionCheckboxes = selectionMode === "multiple" && selectionBehavior !== "replace",
|
|
BaseComponent = "div",
|
|
checkboxesProps,
|
|
topContent,
|
|
bottomContent,
|
|
sortIcon,
|
|
onRowAction,
|
|
onCellAction,
|
|
...otherProps
|
|
} = props;
|
|
const Component = as || "table";
|
|
const shouldFilterDOMProps = typeof Component === "string";
|
|
const domRef = (0, import_react_utils.useDOMRef)(ref);
|
|
const domBaseRef = (0, import_react_utils.useDOMRef)(baseRef);
|
|
const state = (0, import_table.useTableState)({
|
|
...originalProps,
|
|
children,
|
|
showSelectionCheckboxes
|
|
});
|
|
if (isKeyboardNavigationDisabled && !state.isKeyboardNavigationDisabled) {
|
|
state.setKeyboardNavigationDisabled(true);
|
|
}
|
|
const { collection } = state;
|
|
const { layout, ...otherOriginalProps } = originalProps;
|
|
const { gridProps } = (0, import_table2.useTable)({ ...otherOriginalProps }, state, domRef);
|
|
const isSelectable = selectionMode !== "none";
|
|
const isMultiSelectable = selectionMode === "multiple";
|
|
const slots = (0, import_react2.useMemo)(
|
|
() => (0, import_theme.table)({
|
|
...variantProps,
|
|
isSelectable,
|
|
isMultiSelectable
|
|
}),
|
|
[(0, import_shared_utils.objectToDeps)(variantProps), isSelectable, isMultiSelectable]
|
|
);
|
|
const baseStyles = (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.base, className);
|
|
const values = (0, import_react2.useMemo)(
|
|
() => {
|
|
var _a2;
|
|
return {
|
|
state,
|
|
slots,
|
|
isSelectable,
|
|
collection,
|
|
classNames,
|
|
color: originalProps == null ? void 0 : originalProps.color,
|
|
disableAnimation,
|
|
checkboxesProps,
|
|
isHeaderSticky: (_a2 = originalProps == null ? void 0 : originalProps.isHeaderSticky) != null ? _a2 : false,
|
|
selectionMode,
|
|
selectionBehavior,
|
|
disabledBehavior,
|
|
showSelectionCheckboxes,
|
|
onRowAction,
|
|
onCellAction
|
|
};
|
|
},
|
|
[
|
|
slots,
|
|
state,
|
|
collection,
|
|
isSelectable,
|
|
classNames,
|
|
selectionMode,
|
|
selectionBehavior,
|
|
checkboxesProps,
|
|
disabledBehavior,
|
|
disableAnimation,
|
|
showSelectionCheckboxes,
|
|
originalProps == null ? void 0 : originalProps.color,
|
|
originalProps == null ? void 0 : originalProps.isHeaderSticky,
|
|
onRowAction,
|
|
onCellAction
|
|
]
|
|
);
|
|
const getBaseProps = (0, import_react.useCallback)(
|
|
(props2) => ({
|
|
...props2,
|
|
ref: domBaseRef,
|
|
className: slots.base({ class: (0, import_shared_utils.clsx)(baseStyles, props2 == null ? void 0 : props2.className) })
|
|
}),
|
|
[baseStyles, slots]
|
|
);
|
|
const getWrapperProps = (0, import_react.useCallback)(
|
|
(props2) => ({
|
|
...props2,
|
|
ref: domBaseRef,
|
|
className: slots.wrapper({ class: (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.wrapper, props2 == null ? void 0 : props2.className) })
|
|
}),
|
|
[classNames == null ? void 0 : classNames.wrapper, slots]
|
|
);
|
|
const getTableProps = (0, import_react.useCallback)(
|
|
(props2) => ({
|
|
...(0, import_shared_utils.mergeProps)(
|
|
gridProps,
|
|
(0, import_react_utils.filterDOMProps)(otherProps, {
|
|
enabled: shouldFilterDOMProps
|
|
}),
|
|
props2
|
|
),
|
|
// avoid typeahead debounce wait for input / textarea
|
|
// so that typing with space won't be blocked
|
|
onKeyDownCapture: void 0,
|
|
ref: domRef,
|
|
className: slots.table({ class: (0, import_shared_utils.clsx)(classNames == null ? void 0 : classNames.table, props2 == null ? void 0 : props2.className) })
|
|
}),
|
|
[classNames == null ? void 0 : classNames.table, shouldFilterDOMProps, slots, gridProps, otherProps]
|
|
);
|
|
return {
|
|
BaseComponent,
|
|
Component,
|
|
children,
|
|
state,
|
|
collection,
|
|
values,
|
|
topContent,
|
|
bottomContent,
|
|
removeWrapper,
|
|
topContentPlacement,
|
|
bottomContentPlacement,
|
|
sortIcon,
|
|
getBaseProps,
|
|
getWrapperProps,
|
|
getTableProps
|
|
};
|
|
}
|
|
// Annotate the CommonJS export names for ESM import in node:
|
|
0 && (module.exports = {
|
|
useTable
|
|
});
|