@adaptabletools/adaptable-react-aggrid-cjs 18.0.0-canary.17 → 18.0.0-canary.19
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adaptabletools/adaptable-react-aggrid-cjs",
|
|
3
|
-
"version": "18.0.0-canary.
|
|
3
|
+
"version": "18.0.0-canary.19",
|
|
4
4
|
"description": "React version of AdapTable - the powerful data-agnostic HTML5 AG Grid extension which provides advanced, cutting-edge functionality to meet all DataGrid requirements",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "contact sales@adaptabletools.com for details",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"typings": "src/index.d.ts",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"tslib": "^2.3.0",
|
|
11
|
-
"@adaptabletools/adaptable-cjs": "18.0.0-canary.
|
|
11
|
+
"@adaptabletools/adaptable-cjs": "18.0.0-canary.19"
|
|
12
12
|
},
|
|
13
13
|
"peerDependencies": {
|
|
14
14
|
"react": "^18.0.0",
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { AgGridReact } from '@ag-grid-community/react';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
export interface AdaptableProviderProps
|
|
6
|
-
gridOptions: GridOptions
|
|
3
|
+
import { GridApi, GridOptions, Module } from '@ag-grid-community/core';
|
|
4
|
+
import { AdaptableOptions, AdaptableReadyInfo } from '..';
|
|
5
|
+
export interface AdaptableProviderProps<TData = any> {
|
|
6
|
+
gridOptions: GridOptions<TData>;
|
|
7
|
+
modules: Module[];
|
|
8
|
+
adaptableOptions: AdaptableOptions<TData>;
|
|
9
|
+
onAdaptableReady?: (adaptableReadyInfo: AdaptableReadyInfo) => void;
|
|
10
|
+
children?: React.ReactNode;
|
|
7
11
|
}
|
|
8
12
|
export type RenderAgGridFrameworkComponentResult = false | GridApi;
|
|
9
|
-
type
|
|
13
|
+
type AgGridReactPropsWithoutGridOptionsAndModules = Omit<React.ComponentProps<typeof AgGridReact>, 'gridOptions' | 'modules'>;
|
|
10
14
|
export declare const Adaptable: {
|
|
11
|
-
Provider: React.FunctionComponent<AdaptableProviderProps
|
|
15
|
+
Provider: React.FunctionComponent<AdaptableProviderProps<any>>;
|
|
12
16
|
UI: (props: {
|
|
13
17
|
style?: React.CSSProperties;
|
|
14
18
|
className?: string;
|
|
15
19
|
}) => JSX.Element;
|
|
16
|
-
AgGridReact: (props:
|
|
20
|
+
AgGridReact: (props: AgGridReactPropsWithoutGridOptionsAndModules) => JSX.Element;
|
|
17
21
|
};
|
|
18
22
|
export {};
|
|
@@ -25,51 +25,73 @@ const AdaptableProvider = (props) => {
|
|
|
25
25
|
const [agGridProps, setAgGridProps] = React.useState();
|
|
26
26
|
const [gridOptions, setGridOptions] = React.useState(props.gridOptions);
|
|
27
27
|
const [agGridApi, setAgGridApi] = React.useState();
|
|
28
|
+
const adaptableAgGridReactRenderedRef = React.useRef(false);
|
|
28
29
|
const gridApiPromiseResolve = React.useRef();
|
|
29
30
|
const gridApiPromise = React.useMemo(() => {
|
|
30
31
|
return new Promise((resolve) => {
|
|
31
32
|
gridApiPromiseResolve.current = resolve;
|
|
32
33
|
});
|
|
33
34
|
}, []);
|
|
34
|
-
const handleSetGridApi = (api) => {
|
|
35
|
+
const handleSetGridApi = React.useCallback((api) => {
|
|
35
36
|
setAgGridApi(api);
|
|
36
37
|
gridApiPromiseResolve.current(api);
|
|
37
|
-
};
|
|
38
|
+
}, []);
|
|
39
|
+
const renderAgGridFrameworkComponent = React.useCallback((gridOptions) => {
|
|
40
|
+
setGridOptions(gridOptions);
|
|
41
|
+
setCurrentTransition(AdaptableAgGridStateTransitions.INITIALIZE_AG_GRID);
|
|
42
|
+
return gridApiPromise;
|
|
43
|
+
}, [gridApiPromise]);
|
|
44
|
+
// this is a check to make sure the user is rendering Adaptable.AgGridReact inside Adaptable.Provider
|
|
45
|
+
// and not AgGridReact directly
|
|
46
|
+
// we're waiting 1s for this to happen
|
|
47
|
+
React.useEffect(() => {
|
|
48
|
+
const timeoutId = setTimeout(() => {
|
|
49
|
+
// this ref is updated in setAgridProps function in the context
|
|
50
|
+
// which is called by the Adaptable.AgGridReact component on mount
|
|
51
|
+
// so if this has not been updated, it means the user is not rendering Adaptable.AgGridReact
|
|
52
|
+
// so we show an error in the console and link to the docs
|
|
53
|
+
if (!adaptableAgGridReactRenderedRef.current) {
|
|
54
|
+
console.error('You are not rendering <Adaptable.AgGridReact /> inside <Adaptable.Provider />.');
|
|
55
|
+
console.error('You are probably rendering <AgGridReact /> directly. Please use <Adaptable.AgGridReact /> instead.');
|
|
56
|
+
console.error('For more details, please see https://docs.adaptabletools.com/guide/react-integration');
|
|
57
|
+
}
|
|
58
|
+
}, 1000);
|
|
59
|
+
return () => {
|
|
60
|
+
clearTimeout(timeoutId);
|
|
61
|
+
};
|
|
62
|
+
}, []);
|
|
38
63
|
return (React.createElement(AdaptableAgGridContext.Provider, { value: {
|
|
39
64
|
transition: currentTransition,
|
|
40
65
|
setTransition: setCurrentTransition,
|
|
66
|
+
modules: props.modules,
|
|
41
67
|
gridOptions,
|
|
42
68
|
setGridOptions,
|
|
43
69
|
agGridApi,
|
|
44
70
|
setAgGridApi: handleSetGridApi,
|
|
45
71
|
agGridProps,
|
|
46
72
|
setAgGridProps: (agGridProps) => {
|
|
73
|
+
adaptableAgGridReactRenderedRef.current = true;
|
|
47
74
|
setAgGridProps(agGridProps);
|
|
48
75
|
// get props and add the to gridOptions
|
|
49
76
|
const newGridOptions = Object.assign(Object.assign({}, gridOptions), agGridProps);
|
|
50
|
-
delete newGridOptions.modules;
|
|
51
77
|
setGridOptions(newGridOptions);
|
|
52
78
|
// Adaptable has everything it needs to initialize
|
|
53
79
|
setCurrentTransition(AdaptableAgGridStateTransitions.INITIALIZE_ADAPTABLE);
|
|
54
80
|
},
|
|
55
|
-
adaptableProps: Object.assign(Object.assign({}, props), { renderAgGridFrameworkComponent
|
|
56
|
-
setGridOptions(gridOptions);
|
|
57
|
-
setCurrentTransition(AdaptableAgGridStateTransitions.INITIALIZE_AG_GRID);
|
|
58
|
-
return gridApiPromise;
|
|
59
|
-
} }),
|
|
81
|
+
adaptableProps: Object.assign(Object.assign({}, props), { renderAgGridFrameworkComponent }),
|
|
60
82
|
} }, props.children));
|
|
61
83
|
};
|
|
62
84
|
// -- ADAPTABLE UI WRAPPER -
|
|
63
85
|
const AdaptableUI = (props) => {
|
|
64
|
-
const { adaptableProps,
|
|
86
|
+
const { adaptableProps, modules, gridOptions, transition } = useAdaptableAgGridContext();
|
|
65
87
|
if (transition === AdaptableAgGridStateTransitions.AG_GRID_EMIT_PROPS) {
|
|
66
88
|
return null;
|
|
67
89
|
}
|
|
68
|
-
return (React.createElement(AdaptableReact_1.default, Object.assign({ style: props.style, className: props.className, gridOptions: gridOptions, modules:
|
|
90
|
+
return (React.createElement(AdaptableReact_1.default, Object.assign({ style: props.style, className: props.className, gridOptions: gridOptions, modules: modules }, adaptableProps)));
|
|
69
91
|
};
|
|
70
92
|
const AdaptableAgGridReact = (props) => {
|
|
71
93
|
const agGridRef = React.useRef(null);
|
|
72
|
-
const { gridOptions, setAgGridApi, transition, setAgGridProps } = useAdaptableAgGridContext();
|
|
94
|
+
const { modules, gridOptions, setAgGridApi, transition, setAgGridProps } = useAdaptableAgGridContext();
|
|
73
95
|
React.useEffect(() => {
|
|
74
96
|
const LIST_OF_PROPS_NOT_ON_GRID_OPTIONS = [
|
|
75
97
|
'containerStyle',
|
|
@@ -90,7 +112,7 @@ const AdaptableAgGridReact = (props) => {
|
|
|
90
112
|
if (transition !== AdaptableAgGridStateTransitions.INITIALIZE_AG_GRID) {
|
|
91
113
|
return null;
|
|
92
114
|
}
|
|
93
|
-
return (React.createElement(react_1.AgGridReact, Object.assign({ ref: agGridRef }, props, { onGridReady: (event) => {
|
|
115
|
+
return (React.createElement(react_1.AgGridReact, Object.assign({ ref: agGridRef }, props, { modules: modules, onGridReady: (event) => {
|
|
94
116
|
setAgGridApi(event.api);
|
|
95
117
|
if (props.onGridReady) {
|
|
96
118
|
props.onGridReady(event);
|
|
@@ -7,7 +7,7 @@ export interface AdaptableReactProps<TData = any> extends React.HTMLProps<HTMLDi
|
|
|
7
7
|
gridOptions?: GridOptions<TData>;
|
|
8
8
|
onAdaptableReady?: (adaptableReadyInfo: AdaptableReadyInfo) => void;
|
|
9
9
|
renderAgGridFrameworkComponent: (gridOptions: GridOptions<TData>) => Promise<RenderAgGridFrameworkComponentResult>;
|
|
10
|
-
modules
|
|
10
|
+
modules: Module[];
|
|
11
11
|
}
|
|
12
12
|
declare const AdaptableReact: React.FunctionComponent<AdaptableReactProps>;
|
|
13
13
|
export default AdaptableReact;
|