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