@thoughtspot/ts-chart-sdk 0.0.2-alpha.4 → 0.0.2-alpha.6

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.
Files changed (92) hide show
  1. package/dist/ts-chart-sdk.d.ts +700 -0
  2. package/lib/index.d.ts +11 -0
  3. package/lib/index.d.ts.map +1 -0
  4. package/lib/index.js +11 -0
  5. package/lib/index.js.map +1 -0
  6. package/lib/main/custom-chart-context.d.ts +58 -0
  7. package/lib/main/custom-chart-context.d.ts.map +1 -0
  8. package/lib/main/custom-chart-context.js +334 -0
  9. package/lib/main/custom-chart-context.js.map +1 -0
  10. package/lib/main/custom-chart-context.spec.d.ts +2 -0
  11. package/lib/main/custom-chart-context.spec.d.ts.map +1 -0
  12. package/lib/main/custom-chart-context.spec.js +618 -0
  13. package/lib/main/custom-chart-context.spec.js.map +1 -0
  14. package/lib/main/post-message-event-bridge.d.ts +6 -0
  15. package/lib/main/post-message-event-bridge.d.ts.map +1 -0
  16. package/lib/main/post-message-event-bridge.js +29 -0
  17. package/lib/main/post-message-event-bridge.js.map +1 -0
  18. package/lib/main/post-message-event-bridge.spec.d.ts +2 -0
  19. package/lib/main/post-message-event-bridge.spec.d.ts.map +1 -0
  20. package/lib/main/post-message-event-bridge.spec.js +117 -0
  21. package/lib/main/post-message-event-bridge.spec.js.map +1 -0
  22. package/lib/main/util.d.ts +2 -0
  23. package/lib/main/util.d.ts.map +1 -0
  24. package/lib/main/util.js +9 -0
  25. package/lib/main/util.js.map +1 -0
  26. package/lib/react/mocks/custom-chart-context-mock.d.ts +3 -0
  27. package/lib/react/mocks/custom-chart-context-mock.d.ts.map +1 -0
  28. package/lib/react/mocks/custom-chart-context-mock.js +94 -0
  29. package/lib/react/mocks/custom-chart-context-mock.js.map +1 -0
  30. package/lib/react/use-custom-chart-context.d.ts +4 -0
  31. package/lib/react/use-custom-chart-context.d.ts.map +1 -0
  32. package/lib/react/use-custom-chart-context.js +68 -0
  33. package/lib/react/use-custom-chart-context.js.map +1 -0
  34. package/lib/react/use-custom-chart-context.spec.d.ts +2 -0
  35. package/lib/react/use-custom-chart-context.spec.d.ts.map +1 -0
  36. package/lib/react/use-custom-chart-context.spec.js +318 -0
  37. package/lib/react/use-custom-chart-context.spec.js.map +1 -0
  38. package/lib/react/use-custom-chart-context.util.d.ts +6 -0
  39. package/lib/react/use-custom-chart-context.util.d.ts.map +1 -0
  40. package/lib/react/use-custom-chart-context.util.js +51 -0
  41. package/lib/react/use-custom-chart-context.util.js.map +1 -0
  42. package/lib/react/use-custom-chart-types.d.ts +23 -0
  43. package/lib/react/use-custom-chart-types.d.ts.map +1 -0
  44. package/lib/react/use-custom-chart-types.js +2 -0
  45. package/lib/react/use-custom-chart-types.js.map +1 -0
  46. package/lib/test/test-conditional-formatting-utils.d.ts +5 -0
  47. package/lib/test/test-conditional-formatting-utils.d.ts.map +1 -0
  48. package/lib/test/test-conditional-formatting-utils.js +43 -0
  49. package/lib/test/test-conditional-formatting-utils.js.map +1 -0
  50. package/lib/test/test-utils.d.ts +7 -0
  51. package/lib/test/test-utils.d.ts.map +1 -0
  52. package/lib/test/test-utils.js +11 -0
  53. package/lib/test/test-utils.js.map +1 -0
  54. package/lib/types/answer-column.types.d.ts +114 -0
  55. package/lib/types/answer-column.types.d.ts.map +1 -0
  56. package/lib/types/answer-column.types.js +96 -0
  57. package/lib/types/answer-column.types.js.map +1 -0
  58. package/lib/types/chart-to-ts-event.types.d.ts +98 -0
  59. package/lib/types/chart-to-ts-event.types.d.ts.map +1 -0
  60. package/lib/types/chart-to-ts-event.types.js +29 -0
  61. package/lib/types/chart-to-ts-event.types.js.map +1 -0
  62. package/lib/types/common.types.d.ts +97 -0
  63. package/lib/types/common.types.d.ts.map +1 -0
  64. package/lib/types/common.types.js +16 -0
  65. package/lib/types/common.types.js.map +1 -0
  66. package/lib/types/conditional-formatting.types.d.ts +155 -0
  67. package/lib/types/conditional-formatting.types.d.ts.map +1 -0
  68. package/lib/types/conditional-formatting.types.js +60 -0
  69. package/lib/types/conditional-formatting.types.js.map +1 -0
  70. package/lib/types/configurator.types.d.ts +18 -0
  71. package/lib/types/configurator.types.d.ts.map +1 -0
  72. package/lib/types/configurator.types.js +2 -0
  73. package/lib/types/configurator.types.js.map +1 -0
  74. package/lib/types/ts-to-chart-event.types.d.ts +94 -0
  75. package/lib/types/ts-to-chart-event.types.d.ts.map +1 -0
  76. package/lib/types/ts-to-chart-event.types.js +15 -0
  77. package/lib/types/ts-to-chart-event.types.js.map +1 -0
  78. package/lib/types/visual-prop.types.d.ts +76 -0
  79. package/lib/types/visual-prop.types.d.ts.map +1 -0
  80. package/lib/types/visual-prop.types.js +2 -0
  81. package/lib/types/visual-prop.types.js.map +1 -0
  82. package/lib/utils/conditional-formatting/conditional-formatting.d.ts +10 -0
  83. package/lib/utils/conditional-formatting/conditional-formatting.d.ts.map +1 -0
  84. package/lib/utils/conditional-formatting/conditional-formatting.js +103 -0
  85. package/lib/utils/conditional-formatting/conditional-formatting.js.map +1 -0
  86. package/lib/utils/conditional-formatting/conditional-formatting.spec.d.ts +2 -0
  87. package/lib/utils/conditional-formatting/conditional-formatting.spec.d.ts.map +1 -0
  88. package/lib/utils/conditional-formatting/conditional-formatting.spec.js +122 -0
  89. package/lib/utils/conditional-formatting/conditional-formatting.spec.js.map +1 -0
  90. package/package.json +2 -2
  91. package/src/types/answer-column.types.ts +9 -1
  92. package/src/types/common.types.ts +59 -6
@@ -0,0 +1,29 @@
1
+ import { onMessage, sendMessage } from 'promise-postmessage';
2
+ import { timeout } from './util';
3
+ const TIMEOUT_THRESHOLD = 30000;
4
+ const elSelector = new URL(import.meta.url).searchParams.get('elSelector');
5
+ const target = (elSelector && document.querySelector(elSelector)) ||
6
+ window.parent;
7
+ const globalThis = (target === window.parent ? window : target);
8
+ const init = (handleMessageEvent) => {
9
+ return onMessage(handleMessageEvent, target, 'child');
10
+ };
11
+ const postMessageToHostApp = async (componentId, hostUrl, eventPayload, eventType) => {
12
+ const resp = await timeout(sendMessage(target, {
13
+ componentId,
14
+ payload: {
15
+ ...eventPayload,
16
+ },
17
+ eventType,
18
+ source: 'ts-chart-sdk',
19
+ }, {
20
+ origin: hostUrl,
21
+ endpoint: 'child',
22
+ }), TIMEOUT_THRESHOLD, 'ChartContext: postMessage operation timed out.');
23
+ if (resp === null || resp === void 0 ? void 0 : resp.hasError) {
24
+ throw new Error(resp.error);
25
+ }
26
+ return resp;
27
+ };
28
+ export { init as initMessageListener, postMessageToHostApp, globalThis };
29
+ //# sourceMappingURL=post-message-event-bridge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-message-event-bridge.js","sourceRoot":"","sources":["../../src/main/post-message-event-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEhC,MAAM,UAAU,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;AAC3E,MAAM,MAAM,GACR,CAAC,UAAU,IAAK,QAAQ,CAAC,aAAa,CAAC,UAAU,CAAiB,CAAC;IACnE,MAAM,CAAC,MAAM,CAAC;AAElB,MAAM,UAAU,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAQ,CAAC;AAOvE,MAAM,IAAI,GAAG,CAAC,kBAAqD,EAAE,EAAE;IACnE,OAAO,SAAS,CAAC,kBAAkB,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;AAC1D,CAAC,CAAC;AAUF,MAAM,oBAAoB,GAAG,KAAK,EAC9B,WAAmB,EACnB,OAAe,EACf,YAAiB,EACjB,SAAyB,EACb,EAAE;IACd,MAAM,IAAI,GAAG,MAAM,OAAO,CACtB,WAAW,CACP,MAAM,EACN;QACI,WAAW;QACX,OAAO,EAAE;YACL,GAAG,YAAY;SAClB;QACD,SAAS;QACT,MAAM,EAAE,cAAc;KACzB,EACD;QACI,MAAM,EAAE,OAAO;QACf,QAAQ,EAAE,OAAO;KACpB,CACJ,EACD,iBAAiB,EACjB,gDAAgD,CACnD,CAAC;IACF,IAAI,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,QAAQ,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;KAC/B;IACD,OAAO,IAAI,CAAC;AAChB,CAAC,CAAC;AAEF,OAAO,EAAE,IAAI,IAAI,mBAAmB,EAAE,oBAAoB,EAAE,UAAU,EAAE,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=post-message-event-bridge.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-message-event-bridge.spec.d.ts","sourceRoot":"","sources":["../../src/main/post-message-event-bridge.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,117 @@
1
+ import _ from 'lodash';
2
+ import { postMessageToHostApp } from './post-message-event-bridge';
3
+ const TIMEOUT_THRESHOLD = 30000;
4
+ describe('postMessageToHostApp', () => {
5
+ beforeEach(() => {
6
+ jest.resetAllMocks();
7
+ });
8
+ test('should resolve the promise with data object when successful', async () => {
9
+ const componentId = '123';
10
+ const hostUrl = 'https://example.com';
11
+ const eventPayload = { foo: 'bar' };
12
+ const eventType = 'SOME_EVENT';
13
+ const mockPostMessage = jest.spyOn(global.parent.window, 'postMessage');
14
+ const channel = {
15
+ port1: { onmessage: null, close: jest.fn() },
16
+ port2: {},
17
+ };
18
+ const messageChannelMock = { MessageChannel: jest.fn(() => channel) };
19
+ global.MessageChannel = messageChannelMock.MessageChannel;
20
+ const promise = postMessageToHostApp(componentId, hostUrl, eventPayload, eventType);
21
+ const response = {
22
+ data: { hasError: false, randomData: 'randomString' },
23
+ };
24
+ if (_.isFunction(channel.port1.onmessage)) {
25
+ channel.port1.onmessage(response);
26
+ }
27
+ else {
28
+ throw new Error('on message should have been initialized');
29
+ }
30
+ await expect(promise).resolves.toEqual(response.data);
31
+ expect(mockPostMessage).toHaveBeenCalledWith({
32
+ componentId,
33
+ payload: eventPayload,
34
+ eventType,
35
+ source: 'ts-chart-sdk',
36
+ }, hostUrl, [channel.port2]);
37
+ expect(messageChannelMock.MessageChannel).toHaveBeenCalled();
38
+ });
39
+ test('should reject the promise with an error message when there is an error', async () => {
40
+ const componentId = '123';
41
+ const hostUrl = 'https://example.com';
42
+ const eventPayload = { foo: 'bar' };
43
+ const eventType = 'SOME_EVENT';
44
+ const mockPostMessage = jest.spyOn(global.parent.window, 'postMessage');
45
+ const channel = {
46
+ port1: { onmessage: null, close: jest.fn() },
47
+ port2: {},
48
+ };
49
+ const messageChannelMock = { MessageChannel: jest.fn(() => channel) };
50
+ global.MessageChannel = messageChannelMock.MessageChannel;
51
+ const promise = postMessageToHostApp(componentId, hostUrl, eventPayload, eventType);
52
+ const error = new Error('Some error');
53
+ const response = { data: { hasError: true, error } };
54
+ if (_.isFunction(channel.port1.onmessage)) {
55
+ channel.port1.onmessage(response);
56
+ }
57
+ else {
58
+ throw new Error('on message should have been initialized');
59
+ }
60
+ await expect(promise).rejects.toThrow('Some error');
61
+ expect(mockPostMessage).toHaveBeenCalledWith({
62
+ componentId,
63
+ payload: eventPayload,
64
+ eventType,
65
+ source: 'ts-chart-sdk',
66
+ }, hostUrl, [channel.port2]);
67
+ expect(messageChannelMock.MessageChannel).toHaveBeenCalled();
68
+ });
69
+ test('should reject the promise after a timeout', async () => {
70
+ const componentId = 'some-component-id';
71
+ const hostUrl = 'https://some-host-url.com';
72
+ const eventPayload = { someKey: 'someValue' };
73
+ const eventType = 'some-event-type';
74
+ const mockPostMessage = jest.spyOn(global.parent.window, 'postMessage');
75
+ const channel = {
76
+ port1: { onmessage: null, close: jest.fn() },
77
+ port2: {},
78
+ };
79
+ const messageChannelMock = {
80
+ MessageChannel: jest.fn(() => channel),
81
+ };
82
+ global.MessageChannel = messageChannelMock.MessageChannel;
83
+ const promise = postMessageToHostApp(componentId, hostUrl, eventPayload, eventType);
84
+ expect(mockPostMessage).toHaveBeenCalledWith({
85
+ componentId,
86
+ payload: eventPayload,
87
+ eventType,
88
+ source: 'ts-chart-sdk',
89
+ }, hostUrl, expect.any(Array));
90
+ await expect(promise).rejects.toThrow('ChartContext: postMessage operation timed out.');
91
+ }, TIMEOUT_THRESHOLD + 1000);
92
+ test('should reject the promise if some error in postMessage', async () => {
93
+ const componentId = 'some-component-id';
94
+ const hostUrl = 'https://some-host-url.com';
95
+ const eventPayload = { someKey: 'someValue' };
96
+ const eventType = 'some-event-type';
97
+ const mockPostMessage = jest.spyOn(global.parent.window, 'postMessage');
98
+ mockPostMessage.mockImplementation(() => {
99
+ throw new Error('Some postMessage error');
100
+ });
101
+ const channel = {
102
+ port1: { onmessage: null, close: jest.fn() },
103
+ port2: {},
104
+ };
105
+ const messageChannelMock = { MessageChannel: jest.fn(() => channel) };
106
+ global.MessageChannel = messageChannelMock.MessageChannel;
107
+ const promise = postMessageToHostApp(componentId, hostUrl, eventPayload, eventType);
108
+ await expect(promise).rejects.toThrow('Some postMessage error');
109
+ expect(mockPostMessage).toHaveBeenCalledWith({
110
+ componentId,
111
+ payload: eventPayload,
112
+ eventType,
113
+ source: 'ts-chart-sdk',
114
+ }, hostUrl, expect.any(Array));
115
+ });
116
+ });
117
+ //# sourceMappingURL=post-message-event-bridge.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-message-event-bridge.spec.js","sourceRoot":"","sources":["../../src/main/post-message-event-bridge.spec.ts"],"names":[],"mappings":"AAKA,OAAO,CAAC,MAAM,QAAQ,CAAC;AACvB,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAEnE,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAEhC,QAAQ,CAAC,s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,EACZ,SAAgB,CACnB,CAAC;QAGF,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAC;QAEhE,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CACxC;YACI,WAAW;YACX,OAAO,EAAE,YAAY;YACrB,SAAS;YACT,MAAM,EAAE,cAAc;SACzB,EACD,OAAO,EACP,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,CACpB,CAAC;IACN,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function timeout(promise: Promise<any>, ms: number, message?: string): Promise<any>;
2
+ //# sourceMappingURL=util.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/main/util.ts"],"names":[],"mappings":"AAAA,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,gBAU1E"}
@@ -0,0 +1,9 @@
1
+ export function timeout(promise, ms, message) {
2
+ return Promise.race([
3
+ promise,
4
+ new Promise((resolve, reject) => {
5
+ setTimeout(() => reject(new Error(message || 'Operation timed out.')), ms);
6
+ }),
7
+ ]);
8
+ }
9
+ //# sourceMappingURL=util.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/main/util.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,OAAO,CAAC,OAAqB,EAAE,EAAU,EAAE,OAAgB;IACvE,OAAO,OAAO,CAAC,IAAI,CAAC;QAChB,OAAO;QACP,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAC5B,UAAU,CACN,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,OAAO,IAAI,sBAAsB,CAAC,CAAC,EAC1D,EAAE,CACL,CAAC;QACN,CAAC,CAAC;KACL,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { CustomChartContextProps } from '../../main/custom-chart-context';
2
+ export declare const contextChartProps: CustomChartContextProps;
3
+ //# sourceMappingURL=custom-chart-context-mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-chart-context-mock.d.ts","sourceRoot":"","sources":["../../../src/react/mocks/custom-chart-context-mock.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAK1E,eAAO,MAAM,iBAAiB,EAAE,uBA2G/B,CAAC"}
@@ -0,0 +1,94 @@
1
+ import _ from 'lodash';
2
+ import { ColumnType } from '../../types/answer-column.types';
3
+ export const contextChartProps = {
4
+ getDefaultChartConfig: (chartModel) => {
5
+ const cols = chartModel.columns;
6
+ const measureColumns = _.filter(cols, (col) => col.type === ColumnType.MEASURE);
7
+ const attributeColumns = _.filter(cols, (col) => col.type === ColumnType.ATTRIBUTE);
8
+ const axisConfig = {
9
+ key: 'column',
10
+ dimensions: [
11
+ {
12
+ key: 'x',
13
+ columns: [attributeColumns[0]],
14
+ },
15
+ {
16
+ key: 'y',
17
+ columns: measureColumns.slice(0, 2),
18
+ },
19
+ ],
20
+ };
21
+ return [axisConfig];
22
+ },
23
+ getQueriesFromChartConfig: (chartConfig) => {
24
+ const queries = chartConfig.map((config) => _.reduce(config.dimensions, (acc, dimension) => ({
25
+ queryColumns: [
26
+ ...acc.queryColumns,
27
+ ...dimension.columns,
28
+ ],
29
+ }), {
30
+ queryColumns: [],
31
+ }));
32
+ return queries;
33
+ },
34
+ chartConfigEditorDefinition: [
35
+ {
36
+ key: 'column',
37
+ label: 'Custom Column',
38
+ descriptionText: 'X Axis can only have attributes, Y Axis can only have measures, Color can only have attributes. ' +
39
+ 'Should have just 1 column in Y axis with colors columns.',
40
+ columnSections: [
41
+ {
42
+ key: 'x',
43
+ label: 'Custom X Axis',
44
+ allowAttributeColumns: true,
45
+ allowMeasureColumns: false,
46
+ allowTimeSeriesColumns: true,
47
+ maxColumnCount: 1,
48
+ },
49
+ {
50
+ key: 'y',
51
+ label: 'Custom Y Axis',
52
+ allowAttributeColumns: false,
53
+ allowMeasureColumns: true,
54
+ allowTimeSeriesColumns: false,
55
+ },
56
+ ],
57
+ },
58
+ ],
59
+ visualPropEditorDefinition: {
60
+ elements: [
61
+ {
62
+ key: 'color',
63
+ type: 'radio',
64
+ defaultValue: 'red',
65
+ values: ['red', 'green', 'yellow'],
66
+ label: 'Colors',
67
+ },
68
+ {
69
+ type: 'section',
70
+ key: 'accordion',
71
+ label: 'Accordion',
72
+ children: [
73
+ {
74
+ key: 'Color2',
75
+ type: 'radio',
76
+ defaultValue: 'blue',
77
+ values: ['blue', 'white', 'red'],
78
+ label: 'Color2',
79
+ },
80
+ {
81
+ key: 'datalabels',
82
+ type: 'toggle',
83
+ defaultValue: false,
84
+ label: 'Data Labels',
85
+ },
86
+ ],
87
+ },
88
+ ],
89
+ },
90
+ renderChart: (cx) => {
91
+ return Promise.resolve();
92
+ },
93
+ };
94
+ //# sourceMappingURL=custom-chart-context-mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"custom-chart-context-mock.js","sourceRoot":"","sources":["../../../src/react/mocks/custom-chart-context-mock.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,QAAQ,CAAC;AAEvB,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAI7D,MAAM,CAAC,MAAM,iBAAiB,GAA4B;IACtD,qBAAqB,EAAE,CAAC,UAAsB,EAAiB,EAAE;QAC7D,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC;QAEhC,MAAM,cAAc,GAAG,CAAC,CAAC,MAAM,CAC3B,IAAI,EACJ,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,UAAU,CAAC,OAAO,CAC3C,CAAC;QAEF,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAC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,mBAAmB,EAAE,IAAI;oBACzB,sBAAsB,EAAE,KAAK;iBAChC;aACJ;SACJ;KACJ;IACD,0BAA0B,EAAE;QACxB,QAAQ,EAAE;YACN;gBACI,GAAG,EAAE,OAAO;gBACZ,IAAI,EAAE,OAAO;gBACb,YAAY,EAAE,KAAK;gBACnB,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC;gBAClC,KAAK,EAAE,QAAQ;aAClB;YACD;gBACI,IAAI,EAAE,SAAS;gBACf,GAAG,EAAE,WAAW;gBAChB,KAAK,EAAE,WAAW;gBAClB,QAAQ,EAAE;oBACN;wBACI,GAAG,EAAE,QAAQ;wBACb,IAAI,EAAE,OAAO;wBACb,YAAY,EAAE,MAAM;wBACpB,MAAM,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,KAAK,CAAC;wBAChC,KAAK,EAAE,QAAQ;qBAClB;oBACD;wBACI,GAAG,EAAE,YAAY;wBACjB,IAAI,EAAE,QAAQ;wBACd,YAAY,EAAE,KAAK;wBACnB,KAAK,EAAE,aAAa;qBACvB;iBACJ;aACJ;SACJ;KACJ;IACD,WAAW,EAAE,CAAC,EAAE,EAAE,EAAE;QAChB,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;CACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { CustomChartContextProps } from '../main/custom-chart-context';
2
+ import { ChartContextProps } from './use-custom-chart-types';
3
+ export declare const useChartContext: (props: Omit<CustomChartContextProps, 'renderChart'>) => ChartContextProps;
4
+ //# sourceMappingURL=use-custom-chart-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-custom-chart-context.d.ts","sourceRoot":"","sources":["../../src/react/use-custom-chart-context.tsx"],"names":[],"mappings":"AAUA,OAAO,EAEH,uBAAuB,EAC1B,MAAM,8BAA8B,CAAC;AAYtC,OAAO,EACH,iBAAiB,EAEpB,MAAM,0BAA0B,CAAC;AAUlC,eAAO,MAAM,eAAe,UACjB,KAAK,uBAAuB,EAAE,aAAa,CAAC,KACpD,iBA2IF,CAAC"}
@@ -0,0 +1,68 @@
1
+ import React, { useCallback, useEffect, useState } from 'react';
2
+ import { CustomChartContext, } from '../main/custom-chart-context';
3
+ import { emitter, eventListener, eventOffListener, } from './use-custom-chart-context.util';
4
+ export const useChartContext = (props) => {
5
+ const [hasInitialized, setHasInitialized] = useState(false);
6
+ const [key, setKey] = useState(0);
7
+ const [ctx, setContextState] = useState({});
8
+ const [chartModel, setChartModel] = useState();
9
+ const getChartContextValues = useCallback((ctx) => {
10
+ return {
11
+ hasInitialized,
12
+ chartModel,
13
+ destroy: () => ctx === null || ctx === void 0 ? void 0 : ctx.destroy(),
14
+ ...emitter(ctx),
15
+ ...eventListener(ctx),
16
+ ...eventOffListener(ctx),
17
+ TSChartContext: ({ children }) => {
18
+ return (React.createElement(React.Fragment, { key: key }, children));
19
+ },
20
+ };
21
+ }, [chartModel, key, hasInitialized, ctx]);
22
+ const setupEventListeners = useCallback((context) => {
23
+ const commonUpdateHandler = (payload) => {
24
+ setChartModel(context.getChartModel());
25
+ return {
26
+ triggerRenderChart: true,
27
+ };
28
+ };
29
+ getChartContextValues(context).setOnChartModelUpdate(commonUpdateHandler);
30
+ getChartContextValues(context).setOnVisualPropsUpdate(commonUpdateHandler);
31
+ getChartContextValues(context).setOnDataUpdate(commonUpdateHandler);
32
+ }, []);
33
+ const setupEventOffListeners = useCallback((context) => {
34
+ getChartContextValues(context).setOffChartModelUpdate();
35
+ getChartContextValues(context).setOffDataUpdate();
36
+ getChartContextValues(context).setOffVisualPropsUpdate();
37
+ }, []);
38
+ const initializeContext = async (context) => {
39
+ return context
40
+ .initialize()
41
+ .then(() => {
42
+ setHasInitialized(true);
43
+ setContextState(context);
44
+ setChartModel(context.getChartModel());
45
+ return true;
46
+ })
47
+ .catch((e) => {
48
+ console.log('Error in context initialization', e);
49
+ });
50
+ };
51
+ const renderChart = useCallback((ctx) => {
52
+ setKey((prevKey) => prevKey + 1);
53
+ return Promise.resolve();
54
+ }, [key]);
55
+ useEffect(() => {
56
+ const context = new CustomChartContext({
57
+ ...props,
58
+ renderChart,
59
+ });
60
+ initializeContext(context);
61
+ setupEventListeners(context);
62
+ return () => {
63
+ setupEventOffListeners(context);
64
+ };
65
+ }, []);
66
+ return getChartContextValues(ctx);
67
+ };
68
+ //# sourceMappingURL=use-custom-chart-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-custom-chart-context.js","sourceRoot":"","sources":["../../src/react/use-custom-chart-context.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAChE,OAAO,EACH,kBAAkB,GAErB,MAAM,8BAA8B,CAAC;AAOtC,OAAO,EACH,OAAO,EACP,aAAa,EACb,gBAAgB,GACnB,MAAM,iCAAiC,CAAC;AAczC,MAAM,CAAC,MAAM,eAAe,GAAG,CAC3B,KAAmD,EAClC,EAAE;IAKnB,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAK5D,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAKlC,MAAM,CAAC,GAAG,EAAE,eAAe,CAAC,GAAG,QAAQ,CACnC,EAAwB,CAC3B,CAAC;IAKF,MAAM,CAAC,UAAU,EAAE,aAAa,CAAC,GAAG,QAAQ,EAAc,CAAC;IAS3D,MAAM,qBAAqB,GAAG,WAAW,CACrC,CAAC,GAAuB,EAAqB,EAAE;QAC3C,OAAO;YACH,cAAc;YACd,UAAU;YACV,OAAO,EAAE,GAAG,EAAE,CAAC,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,OAAO,EAAE;YAC7B,GAAG,OAAO,CAAC,GAAG,CAAC;YACf,GAAG,aAAa,CAAC,GAAG,CAAC;YACrB,GAAG,gBAAgB,CAAC,GAAG,C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ACzB,aAAa,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,CAAC;YACvC,OAAO,IAAI,CAAC;QAChB,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE;YACT,OAAO,CAAC,GAAG,CAAC,iCAAiC,EAAE,CAAC,CAAC,CAAC;QACtD,CAAC,CAAC,CAAC;IACX,CAAC,CAAC;IAQF,MAAM,WAAW,GAAG,WAAW,CAC3B,CAAC,GAAuB,EAAE,EAAE;QACxB,MAAM,CAAC,CAAC,OAAe,EAAE,EAAE,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC;QACzC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC,EACD,CAAC,GAAG,CAAC,CACR,CAAC;IAEF,SAAS,CAAC,GAAG,EAAE;QAGX,MAAM,OAAO,GAAG,IAAI,kBAAkB,CAAC;YACnC,GAAG,KAAK;YACR,WAAW;SACd,CAAC,CAAC;QAEH,iBAAiB,CAAC,OAAO,CAAC,CAAC;QAC3B,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAC7B,OAAO,GAAG,EAAE;YACR,sBAAsB,CAAC,OAAO,CAAC,CAAC;QACpC,CAAC,CAAC;IACN,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,qBAAqB,CAAC,GAAG,CAAC,CAAC;AACtC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=use-custom-chart-context.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-custom-chart-context.spec.d.ts","sourceRoot":"","sources":["../../src/react/use-custom-chart-context.spec.tsx"],"names":[],"mappings":""}