@eristack/line-grid
Version:
Editable QUPS line table with patchLine recalculation hook
55 lines (52 loc) • 2.53 kB
JavaScript
;
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/index.ts
var index_exports = {};
__export(index_exports, {
LineGrid: () => LineGrid,
useLineGridRecalc: () => useLineGridRecalc
});
module.exports = __toCommonJS(index_exports);
// src/line-grid.tsx
var import_jsx_runtime = require("react/jsx-runtime");
function LineGrid({ line, columns, renderCell }) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("table", { className: "erista-line-grid", "data-component": "line-grid", children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("th", { scope: "col", children: column.header }, column.id)) }) }),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: columns.map((column) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { children: renderCell(column.id, line) }, column.id)) }) })
] });
}
// src/use-line-grid-recalc.ts
var import_qups = require("@eristack/qups");
var import_react = require("react");
function useLineGridRecalc(initial) {
const [line, setLine] = (0, import_react.useState)(() => (0, import_qups.calculateLine)(initial));
const applyPatch = (0, import_react.useCallback)((patch) => {
setLine((current) => (0, import_qups.patchLine)(current, patch));
}, []);
const recalculate = (0, import_react.useCallback)((input) => {
setLine((0, import_qups.calculateLine)(input));
}, []);
return { line, applyPatch, recalculate };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
LineGrid,
useLineGridRecalc
});
//# sourceMappingURL=index.cjs.map