@adaptabletools/adaptable-react-aggrid 18.0.0-canary.1 → 18.0.0-canary.10
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/base.css +11 -3
- package/base.css.map +1 -1
- package/index.css +88 -70
- package/index.css.map +1 -1
- package/package.json +4 -4
- package/src/components/AdaptableProvider.d.ts +18 -0
- package/src/components/AdaptableProvider.js +103 -0
- package/src/components/AdaptableReact.d.ts +4 -1
- package/src/components/AdaptableReact.js +9 -13
- package/src/index.d.ts +2 -2
- package/src/index.js +3 -2
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { AgGridReact } from '@ag-grid-community/react';
|
|
3
|
+
import { AdaptableReactProps } from './AdaptableReact';
|
|
4
|
+
import { GridApi, GridOptions } from '@ag-grid-community/core';
|
|
5
|
+
export interface AdaptableProviderProps extends Omit<AdaptableReactProps, 'renderAgGridFrameworkComponent'> {
|
|
6
|
+
gridOptions: GridOptions;
|
|
7
|
+
}
|
|
8
|
+
export type RenderAgGridFrameworkComponentResult = false | GridApi;
|
|
9
|
+
type AgGridReactPropsWithoutGridOptions = Omit<React.ComponentProps<typeof AgGridReact>, 'gridOptions'>;
|
|
10
|
+
export declare const Adaptable: {
|
|
11
|
+
Provider: React.FunctionComponent<AdaptableProviderProps>;
|
|
12
|
+
UI: (props: {
|
|
13
|
+
style?: React.CSSProperties;
|
|
14
|
+
className?: string;
|
|
15
|
+
}) => JSX.Element;
|
|
16
|
+
AgGridReact: (props: AgGridReactPropsWithoutGridOptions) => JSX.Element;
|
|
17
|
+
};
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { AgGridReact } from '@ag-grid-community/react';
|
|
3
|
+
import AdaptableReactComponent from './AdaptableReact';
|
|
4
|
+
var AdaptableAgGridStateTransitions;
|
|
5
|
+
(function (AdaptableAgGridStateTransitions) {
|
|
6
|
+
AdaptableAgGridStateTransitions["AG_GRID_EMIT_PROPS"] = "AG_GRID_EMIT_PROPS";
|
|
7
|
+
AdaptableAgGridStateTransitions["INITIALIZE_ADAPTABLE"] = "INITIALIZE_ADAPTABLE";
|
|
8
|
+
AdaptableAgGridStateTransitions["INITIALIZE_AG_GRID"] = "INITIALIZE_AG_GRID";
|
|
9
|
+
})(AdaptableAgGridStateTransitions || (AdaptableAgGridStateTransitions = {}));
|
|
10
|
+
// -- ADAPTABLE PROVIDER -
|
|
11
|
+
const AdaptableAgGridContext = React.createContext(null);
|
|
12
|
+
const useAdaptableAgGridContext = () => {
|
|
13
|
+
const context = React.useContext(AdaptableAgGridContext);
|
|
14
|
+
if (!context) {
|
|
15
|
+
throw new Error('AdaptableAgGridReact and AdaptableReact');
|
|
16
|
+
}
|
|
17
|
+
return context;
|
|
18
|
+
};
|
|
19
|
+
const AdaptableProvider = (props) => {
|
|
20
|
+
const [currentTransition, setCurrentTransition] = React.useState(AdaptableAgGridStateTransitions.AG_GRID_EMIT_PROPS);
|
|
21
|
+
const [agGridProps, setAgGridProps] = React.useState();
|
|
22
|
+
const [gridOptions, setGridOptions] = React.useState(props.gridOptions);
|
|
23
|
+
const [agGridApi, setAgGridApi] = React.useState();
|
|
24
|
+
const gridApiPromiseResolve = React.useRef();
|
|
25
|
+
const gridApiPromise = React.useMemo(() => {
|
|
26
|
+
return new Promise((resolve) => {
|
|
27
|
+
gridApiPromiseResolve.current = resolve;
|
|
28
|
+
});
|
|
29
|
+
}, []);
|
|
30
|
+
const handleSetGridApi = (api) => {
|
|
31
|
+
setAgGridApi(api);
|
|
32
|
+
gridApiPromiseResolve.current(api);
|
|
33
|
+
};
|
|
34
|
+
return (React.createElement(AdaptableAgGridContext.Provider, { value: {
|
|
35
|
+
transition: currentTransition,
|
|
36
|
+
setTransition: setCurrentTransition,
|
|
37
|
+
gridOptions,
|
|
38
|
+
setGridOptions,
|
|
39
|
+
agGridApi,
|
|
40
|
+
setAgGridApi: handleSetGridApi,
|
|
41
|
+
agGridProps,
|
|
42
|
+
setAgGridProps: (agGridProps) => {
|
|
43
|
+
setAgGridProps(agGridProps);
|
|
44
|
+
// get props and add the to gridOptions
|
|
45
|
+
const newGridOptions = Object.assign(Object.assign({}, gridOptions), agGridProps);
|
|
46
|
+
delete newGridOptions.modules;
|
|
47
|
+
setGridOptions(newGridOptions);
|
|
48
|
+
// Adaptable has everything it needs to initialize
|
|
49
|
+
setCurrentTransition(AdaptableAgGridStateTransitions.INITIALIZE_ADAPTABLE);
|
|
50
|
+
},
|
|
51
|
+
adaptableProps: Object.assign(Object.assign({}, props), { renderAgGridFrameworkComponent: (gridOptions) => {
|
|
52
|
+
setGridOptions(gridOptions);
|
|
53
|
+
setCurrentTransition(AdaptableAgGridStateTransitions.INITIALIZE_AG_GRID);
|
|
54
|
+
return gridApiPromise;
|
|
55
|
+
} }),
|
|
56
|
+
} }, props.children));
|
|
57
|
+
};
|
|
58
|
+
// -- ADAPTABLE UI WRAPPER -
|
|
59
|
+
const AdaptableUI = (props) => {
|
|
60
|
+
const { adaptableProps, agGridProps, gridOptions, transition } = useAdaptableAgGridContext();
|
|
61
|
+
if (transition === AdaptableAgGridStateTransitions.AG_GRID_EMIT_PROPS) {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
return (React.createElement(AdaptableReactComponent, Object.assign({ style: props.style, className: props.className, gridOptions: gridOptions, modules: agGridProps.modules }, adaptableProps)));
|
|
65
|
+
};
|
|
66
|
+
const AdaptableAgGridReact = (props) => {
|
|
67
|
+
const agGridRef = React.useRef(null);
|
|
68
|
+
const { gridOptions, setAgGridApi, transition, setAgGridProps } = useAdaptableAgGridContext();
|
|
69
|
+
React.useEffect(() => {
|
|
70
|
+
const LIST_OF_PROPS_NOT_ON_GRID_OPTIONS = [
|
|
71
|
+
'containerStyle',
|
|
72
|
+
'className',
|
|
73
|
+
'setGridApi',
|
|
74
|
+
'componentWrappingElement',
|
|
75
|
+
'maxComponentCreationTimeMs',
|
|
76
|
+
'children',
|
|
77
|
+
];
|
|
78
|
+
const agGridProps = Object.keys(props).reduce((acc, key) => {
|
|
79
|
+
if (LIST_OF_PROPS_NOT_ON_GRID_OPTIONS.includes(key)) {
|
|
80
|
+
return acc;
|
|
81
|
+
}
|
|
82
|
+
return Object.assign(Object.assign({}, acc), { [key]: props[key] });
|
|
83
|
+
}, {});
|
|
84
|
+
setAgGridProps(agGridProps);
|
|
85
|
+
}, []);
|
|
86
|
+
if (transition !== AdaptableAgGridStateTransitions.INITIALIZE_AG_GRID) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
return (React.createElement(AgGridReact, Object.assign({ ref: agGridRef }, props, { onGridReady: (event) => {
|
|
90
|
+
setAgGridApi(event.api);
|
|
91
|
+
if (props.onGridReady) {
|
|
92
|
+
props.onGridReady(event);
|
|
93
|
+
}
|
|
94
|
+
if (gridOptions.onGridReady) {
|
|
95
|
+
gridOptions.onGridReady(event);
|
|
96
|
+
}
|
|
97
|
+
}, gridOptions: gridOptions })));
|
|
98
|
+
};
|
|
99
|
+
export const Adaptable = {
|
|
100
|
+
Provider: AdaptableProvider,
|
|
101
|
+
UI: AdaptableUI,
|
|
102
|
+
AgGridReact: AdaptableAgGridReact,
|
|
103
|
+
};
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { AdaptableOptions, AdaptableReadyInfo } from '@adaptabletools/adaptable/types';
|
|
3
|
-
import { GridOptions } from '@ag-grid-community/core';
|
|
3
|
+
import { GridOptions, Module } from '@ag-grid-community/core';
|
|
4
|
+
import { RenderAgGridFrameworkComponentResult } from './AdaptableProvider';
|
|
4
5
|
export interface AdaptableReactProps<TData = any> extends React.HTMLProps<HTMLDivElement> {
|
|
5
6
|
adaptableOptions: AdaptableOptions<TData>;
|
|
6
7
|
gridOptions?: GridOptions<TData>;
|
|
7
8
|
onAdaptableReady?: (adaptableReadyInfo: AdaptableReadyInfo) => void;
|
|
9
|
+
renderAgGridFrameworkComponent: (gridOptions: GridOptions<TData>) => Promise<RenderAgGridFrameworkComponentResult>;
|
|
10
|
+
modules?: Module[];
|
|
8
11
|
}
|
|
9
12
|
declare const AdaptableReact: React.FunctionComponent<AdaptableReactProps>;
|
|
10
13
|
export default AdaptableReact;
|
|
@@ -1,17 +1,9 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useMemo } from 'react';
|
|
4
|
-
import
|
|
4
|
+
import { _AdaptableAgGrid } from '@adaptabletools/adaptable/agGrid';
|
|
5
5
|
import { setupFrameworkComponents } from '../setupFrameworkComponents';
|
|
6
6
|
import join from '../utils/join';
|
|
7
|
-
// const suffix = name.endsWith('-cjs') ? '-cjs' : '';
|
|
8
|
-
// if (version !== coreVersion) {
|
|
9
|
-
// console.warn(`
|
|
10
|
-
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
11
|
-
// !!!!!!! "@adaptabletools/adaptable-react-aggrid${suffix}" (v @${version}) and "@adaptabletools/adaptable${suffix}" (v @${coreVersion}) have different versions - they should have the exact same version.
|
|
12
|
-
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
13
|
-
// `);
|
|
14
|
-
// }
|
|
15
7
|
const getRandomInt = (max) => Math.floor(Math.random() * Math.floor(max));
|
|
16
8
|
const AdaptableReact = (_a) => {
|
|
17
9
|
var { adaptableOptions, gridOptions, onAdaptableReady } = _a, props = __rest(_a, ["adaptableOptions", "gridOptions", "onAdaptableReady"]);
|
|
@@ -21,11 +13,15 @@ const AdaptableReact = (_a) => {
|
|
|
21
13
|
let adaptableApi;
|
|
22
14
|
return (node) => {
|
|
23
15
|
if (node) {
|
|
24
|
-
|
|
16
|
+
_AdaptableAgGrid
|
|
17
|
+
._initInternal({
|
|
18
|
+
modules: props.modules,
|
|
19
|
+
adaptableOptions: Object.assign(Object.assign({}, adaptableOptions), { containerOptions: Object.assign(Object.assign({}, adaptableOptions.containerOptions), { adaptableContainer: node }) }),
|
|
25
20
|
gridOptions,
|
|
26
|
-
waitForAgGrid: true,
|
|
27
21
|
variant: 'react',
|
|
28
|
-
|
|
22
|
+
renderAgGridFrameworkComponent: props.renderAgGridFrameworkComponent,
|
|
23
|
+
})
|
|
24
|
+
.then((api) => {
|
|
29
25
|
adaptableApi = api;
|
|
30
26
|
if (onAdaptableReady) {
|
|
31
27
|
adaptableApi.eventApi.on('AdaptableReady', onAdaptableReady);
|
|
@@ -44,6 +40,6 @@ const AdaptableReact = (_a) => {
|
|
|
44
40
|
}
|
|
45
41
|
};
|
|
46
42
|
}, []);
|
|
47
|
-
return (React.createElement("div",
|
|
43
|
+
return (React.createElement("div", { style: props.style, ref: containerRef, id: adaptableContainerId, className: join(props.className, 'ab__react-wrapper') }));
|
|
48
44
|
};
|
|
49
45
|
export default AdaptableReact;
|
package/src/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export { AdaptableQL, AdaptableBooleanExpressionFunctions, AdaptableScalarExpressionFunctions, AdaptableAggregatedBooleanExpressionFunctions, AdaptableAggregatedScalarExpressionFunctions, AdaptableObservableExpressionFunctions, } from '@adaptabletools/adaptable/agGrid';
|
|
1
|
+
export { AdaptableQL } from '@adaptabletools/adaptable/agGrid';
|
|
3
2
|
export { AdaptableOptionsWizardView } from './components/AdaptableOptionsWizardView';
|
|
4
3
|
export * from '@adaptabletools/adaptable/types';
|
|
4
|
+
export { Adaptable } from './components/AdaptableProvider';
|
package/src/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export { default } from './components/AdaptableReact';
|
|
2
|
-
export { AdaptableQL
|
|
1
|
+
// export { default } from './components/AdaptableReact';
|
|
2
|
+
export { AdaptableQL } from '@adaptabletools/adaptable/agGrid';
|
|
3
3
|
export { AdaptableOptionsWizardView } from './components/AdaptableOptionsWizardView';
|
|
4
4
|
export * from '@adaptabletools/adaptable/types';
|
|
5
|
+
export { Adaptable } from './components/AdaptableProvider';
|