UNPKG

7.91 kBJavaScriptView Raw
1// ag-grid-react v26.2.0
2"use strict";
3var __importStar = (this && this.__importStar) || function (mod) {
4 if (mod && mod.__esModule) return mod;
5 var result = {};
6 if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
7 result["default"] = mod;
8 return result;
9};
10var __importDefault = (this && this.__importDefault) || function (mod) {
11 return (mod && mod.__esModule) ? mod : { "default": mod };
12};
13Object.defineProperty(exports, "__esModule", { value: true });
14var ag_grid_community_1 = require("ag-grid-community");
15var react_1 = __importStar(require("react"));
16var beansContext_1 = require("./beansContext");
17var gridHeaderComp_1 = __importDefault(require("./header/gridHeaderComp"));
18var reactComment_1 = __importDefault(require("./reactComment"));
19var rowContainerComp_1 = __importDefault(require("./rows/rowContainerComp"));
20var utils_1 = require("./utils");
21var GridBodyComp = function () {
22 var _a = react_1.useContext(beansContext_1.BeansContext), context = _a.context, agStackComponentsRegistry = _a.agStackComponentsRegistry, resizeObserverService = _a.resizeObserverService;
23 var _b = react_1.useState(''), rowAnimationClass = _b[0], setRowAnimationClass = _b[1];
24 var _c = react_1.useState(0), ariaColCount = _c[0], setAriaColCount = _c[1];
25 var _d = react_1.useState(0), ariaRowCount = _d[0], setAriaRowCount = _d[1];
26 var _e = react_1.useState(0), topHeight = _e[0], setTopHeight = _e[1];
27 var _f = react_1.useState(0), bottomHeight = _f[0], setBottomHeight = _f[1];
28 var _g = react_1.useState(''), topDisplay = _g[0], setTopDisplay = _g[1];
29 var _h = react_1.useState(''), bottomDisplay = _h[0], setBottomDisplay = _h[1];
30 var _j = react_1.useState(null), movingCss = _j[0], setMovingCss = _j[1];
31 var _k = react_1.useState(''), layoutClass = _k[0], setLayoutClass = _k[1];
32 var _l = react_1.useState(null), forceVerticalScrollClass = _l[0], setForceVerticalScrollClass = _l[1];
33 var _m = react_1.useState(''), topAndBottomOverflowY = _m[0], setTopAndBottomOverflowY = _m[1];
34 var _o = react_1.useState(null), cellSelectableCss = _o[0], setCellSelectableCss = _o[1];
35 var eRoot = react_1.useRef(null);
36 var eTop = react_1.useRef(null);
37 var eBodyViewport = react_1.useRef(null);
38 var eBottom = react_1.useRef(null);
39 reactComment_1.default(' AG Grid Body ', eRoot);
40 reactComment_1.default(' AG Pinned Top ', eTop);
41 reactComment_1.default(' AG Middle ', eBodyViewport);
42 reactComment_1.default(' AG Pinned Bottom ', eBottom);
43 react_1.useEffect(function () {
44 var beansToDestroy = [];
45 var destroyFuncs = [];
46 if (!context) {
47 return;
48 }
49 var newComp = function (tag) {
50 var CompClass = agStackComponentsRegistry.getComponentClass(tag);
51 var comp = context.createBean(new CompClass());
52 beansToDestroy.push(comp);
53 return comp;
54 };
55 eRoot.current.appendChild(document.createComment(' AG Fake Horizontal Scroll '));
56 eRoot.current.appendChild(newComp('AG-FAKE-HORIZONTAL-SCROLL').getGui());
57 eRoot.current.appendChild(document.createComment(' AG Overlay Wrapper '));
58 eRoot.current.appendChild(newComp('AG-OVERLAY-WRAPPER').getGui());
59 var compProxy = {
60 setRowAnimationCssOnBodyViewport: setRowAnimationClass,
61 setColumnCount: setAriaColCount,
62 setRowCount: setAriaRowCount,
63 setTopHeight: setTopHeight,
64 setBottomHeight: setBottomHeight,
65 setTopDisplay: setTopDisplay,
66 setBottomDisplay: setBottomDisplay,
67 setColumnMovingCss: setMovingCss,
68 updateLayoutClasses: setLayoutClass,
69 setAlwaysVerticalScrollClass: setForceVerticalScrollClass,
70 setPinnedTopBottomOverflowY: setTopAndBottomOverflowY,
71 setCellSelectableCss: setCellSelectableCss,
72 registerBodyViewportResizeListener: function (listener) {
73 var unsubscribeFromResize = resizeObserverService.observeResize(eBodyViewport.current, listener);
74 destroyFuncs.push(function () { return unsubscribeFromResize(); });
75 }
76 };
77 var ctrl = context.createBean(new ag_grid_community_1.GridBodyCtrl());
78 beansToDestroy.push(ctrl);
79 ctrl.setComp(compProxy, eRoot.current, eBodyViewport.current, eTop.current, eBottom.current);
80 return function () {
81 context.destroyBeans(beansToDestroy);
82 destroyFuncs.forEach(function (f) { return f(); });
83 };
84 }, []);
85 var rootClasses = react_1.useMemo(function () {
86 return utils_1.classesList('ag-root', 'ag-unselectable', movingCss, layoutClass);
87 }, [movingCss, layoutClass]);
88 var bodyViewportClasses = react_1.useMemo(function () {
89 return utils_1.classesList('ag-body-viewport', rowAnimationClass, layoutClass, forceVerticalScrollClass, cellSelectableCss);
90 }, [rowAnimationClass, layoutClass, forceVerticalScrollClass, cellSelectableCss]);
91 var topClasses = react_1.useMemo(function () {
92 return utils_1.classesList('ag-floating-top', cellSelectableCss);
93 }, [cellSelectableCss]);
94 var bottomClasses = react_1.useMemo(function () {
95 return utils_1.classesList('ag-floating-bottom', cellSelectableCss);
96 }, [cellSelectableCss]);
97 var topStyle = react_1.useMemo(function () { return ({
98 height: topHeight,
99 minHeight: topHeight,
100 display: topDisplay,
101 overflowY: topAndBottomOverflowY
102 }); }, [topHeight, topDisplay, topAndBottomOverflowY]);
103 var bottomStyle = react_1.useMemo(function () { return ({
104 height: bottomHeight,
105 minHeight: bottomHeight,
106 display: bottomDisplay,
107 overflowY: topAndBottomOverflowY
108 }); }, [bottomHeight, bottomDisplay, topAndBottomOverflowY]);
109 var createRowContainer = function (container) { return react_1.default.createElement(rowContainerComp_1.default, { name: container, key: container + "-container" }); };
110 var createSection = function (_a) {
111 var section = _a.section, children = _a.children, className = _a.className, style = _a.style, unselectable = _a.unselectable;
112 return (react_1.default.createElement("div", { ref: section, className: className, role: "presentation", style: style, unselectable: unselectable }, children.map(createRowContainer)));
113 };
114 return (react_1.default.createElement("div", { ref: eRoot, className: rootClasses, role: "grid", unselectable: "on", "aria-colcount": ariaColCount, "aria-rowcount": ariaRowCount },
115 react_1.default.createElement(gridHeaderComp_1.default, null),
116 createSection({ section: eTop, className: topClasses, style: topStyle, unselectable: 'on', children: [
117 ag_grid_community_1.RowContainerName.TOP_LEFT,
118 ag_grid_community_1.RowContainerName.TOP_CENTER,
119 ag_grid_community_1.RowContainerName.TOP_RIGHT,
120 ag_grid_community_1.RowContainerName.TOP_FULL_WITH,
121 ] }),
122 createSection({ section: eBodyViewport, className: bodyViewportClasses, children: [
123 ag_grid_community_1.RowContainerName.LEFT,
124 ag_grid_community_1.RowContainerName.CENTER,
125 ag_grid_community_1.RowContainerName.RIGHT,
126 ag_grid_community_1.RowContainerName.FULL_WIDTH,
127 ] }),
128 createSection({ section: eBottom, className: bottomClasses, style: bottomStyle, unselectable: 'on', children: [
129 ag_grid_community_1.RowContainerName.BOTTOM_LEFT,
130 ag_grid_community_1.RowContainerName.BOTTOM_CENTER,
131 ag_grid_community_1.RowContainerName.BOTTOM_RIGHT,
132 ag_grid_community_1.RowContainerName.BOTTOM_FULL_WITH,
133 ] })));
134};
135exports.default = react_1.memo(GridBodyComp);