@sigmacomputing/plugin 1.1.0 → 1.1.1
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/dist/client/initialize.d.ts +3 -0
- package/dist/client/initialize.d.ts.map +1 -0
- package/dist/client/initialize.js +223 -0
- package/dist/react/Context.d.ts +4 -0
- package/dist/react/Context.d.ts.map +1 -0
- package/dist/react/Context.js +6 -0
- package/dist/react/Provider.d.ts +8 -0
- package/dist/react/Provider.d.ts.map +1 -0
- package/dist/react/Provider.js +9 -0
- package/dist/react/hooks.d.ts +83 -0
- package/dist/react/hooks.d.ts.map +1 -0
- package/dist/react/hooks.js +231 -0
- package/dist/utils/deepEqual.d.ts +2 -0
- package/dist/utils/deepEqual.d.ts.map +1 -0
- package/dist/utils/deepEqual.js +28 -0
- package/dist/utils/polyfillRequestAnimationFrame.d.ts +8 -0
- package/dist/utils/polyfillRequestAnimationFrame.d.ts.map +1 -0
- package/dist/utils/polyfillRequestAnimationFrame.js +16 -0
- package/package.json +5 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../../src/client/initialize.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,cAAc,EAMf,MAAM,UAAU,CAAC;AAElB,wBAAgB,UAAU,CAAC,CAAC,GAAG,EAAE,KAAK,cAAc,CAAC,CAAC,CAAC,CAqQtD"}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initialize = void 0;
|
|
4
|
+
const error_1 = require("../error");
|
|
5
|
+
function initialize() {
|
|
6
|
+
const pluginConfig = {
|
|
7
|
+
config: {},
|
|
8
|
+
};
|
|
9
|
+
let subscribedInteractions = {};
|
|
10
|
+
let subscribedWorkbookVars = {};
|
|
11
|
+
let subscribedUrlParameters = {};
|
|
12
|
+
const registeredEffects = {};
|
|
13
|
+
const listeners = {};
|
|
14
|
+
for (const [key, value] of new URL(document.location.toString()).searchParams.entries())
|
|
15
|
+
pluginConfig[key] = JSON.parse(value);
|
|
16
|
+
const listener = (e) => {
|
|
17
|
+
emit(e.data.type, e.data.result, e.data.error);
|
|
18
|
+
};
|
|
19
|
+
window.addEventListener('message', listener, false);
|
|
20
|
+
window.addEventListener('click', () => execPromise('wb:plugin:focus'));
|
|
21
|
+
on('wb:plugin:config:update', (config) => {
|
|
22
|
+
var _a;
|
|
23
|
+
Object.assign(pluginConfig, config);
|
|
24
|
+
emit('config', (_a = pluginConfig.config) !== null && _a !== void 0 ? _a : {});
|
|
25
|
+
});
|
|
26
|
+
// send initialize event
|
|
27
|
+
void execPromise('wb:plugin:init', require('../../package.json').version).then(config => {
|
|
28
|
+
Object.assign(pluginConfig, config);
|
|
29
|
+
emit('init', pluginConfig);
|
|
30
|
+
emit('config', pluginConfig.config);
|
|
31
|
+
});
|
|
32
|
+
on('wb:plugin:variable:update', (updatedVariables) => {
|
|
33
|
+
subscribedWorkbookVars = {};
|
|
34
|
+
Object.assign(subscribedWorkbookVars, updatedVariables);
|
|
35
|
+
});
|
|
36
|
+
on('wb:plugin:selection:update', (updatedInteractions) => {
|
|
37
|
+
subscribedInteractions = {};
|
|
38
|
+
Object.assign(subscribedInteractions, updatedInteractions);
|
|
39
|
+
});
|
|
40
|
+
on('wb:plugin:url-parameter:update', (updatedUrlParameters) => {
|
|
41
|
+
subscribedUrlParameters = {};
|
|
42
|
+
Object.assign(subscribedUrlParameters, updatedUrlParameters);
|
|
43
|
+
});
|
|
44
|
+
on('wb:plugin:action-effect:invoke', (configId) => {
|
|
45
|
+
const effect = registeredEffects[configId];
|
|
46
|
+
if (!effect) {
|
|
47
|
+
throw new Error(`Unknown action effect with name: ${configId}`);
|
|
48
|
+
}
|
|
49
|
+
effect();
|
|
50
|
+
});
|
|
51
|
+
function on(event, listener) {
|
|
52
|
+
listeners[event] = listeners[event] || [];
|
|
53
|
+
listeners[event].push(listener);
|
|
54
|
+
}
|
|
55
|
+
function off(event, listener) {
|
|
56
|
+
if (listeners[event] == null)
|
|
57
|
+
return;
|
|
58
|
+
listeners[event] = listeners[event].filter(a => a !== listener);
|
|
59
|
+
}
|
|
60
|
+
function emit(event, ...args) {
|
|
61
|
+
Object.values(listeners[event] || []).forEach(fn => fn(...args));
|
|
62
|
+
}
|
|
63
|
+
function execPromise(event, ...args) {
|
|
64
|
+
return new Promise((resolve, reject) => {
|
|
65
|
+
var _a;
|
|
66
|
+
const callback = (data, error) => {
|
|
67
|
+
if (error)
|
|
68
|
+
reject(error);
|
|
69
|
+
else
|
|
70
|
+
resolve(data);
|
|
71
|
+
off(event, callback);
|
|
72
|
+
};
|
|
73
|
+
on(event, callback);
|
|
74
|
+
window.parent.postMessage({ type: event, args, elementId: pluginConfig.id }, (_a = pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.wbOrigin) !== null && _a !== void 0 ? _a : '*');
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
get sigmaEnv() {
|
|
79
|
+
return pluginConfig.sigmaEnv;
|
|
80
|
+
},
|
|
81
|
+
get isScreenshot() {
|
|
82
|
+
return pluginConfig.screenshot;
|
|
83
|
+
},
|
|
84
|
+
config: {
|
|
85
|
+
// @ts-ignore
|
|
86
|
+
getKey(key) {
|
|
87
|
+
var _a;
|
|
88
|
+
return (_a = pluginConfig === null || pluginConfig === void 0 ? void 0 : pluginConfig.config) === null || _a === void 0 ? void 0 : _a[key];
|
|
89
|
+
},
|
|
90
|
+
get() {
|
|
91
|
+
return pluginConfig.config;
|
|
92
|
+
},
|
|
93
|
+
set(partialConfig) {
|
|
94
|
+
void execPromise('wb:plugin:config:update', partialConfig);
|
|
95
|
+
},
|
|
96
|
+
setKey(key, value) {
|
|
97
|
+
void execPromise('wb:plugin:config:update', {
|
|
98
|
+
[key]: value,
|
|
99
|
+
});
|
|
100
|
+
},
|
|
101
|
+
subscribe(listener) {
|
|
102
|
+
on('config', listener);
|
|
103
|
+
return () => off('config', listener);
|
|
104
|
+
},
|
|
105
|
+
getVariable(configId) {
|
|
106
|
+
(0, error_1.validateConfigId)(configId, 'variable');
|
|
107
|
+
return subscribedWorkbookVars[configId];
|
|
108
|
+
},
|
|
109
|
+
setVariable(configId, ...values) {
|
|
110
|
+
(0, error_1.validateConfigId)(configId, 'variable');
|
|
111
|
+
void execPromise('wb:plugin:variable:set', configId, ...values);
|
|
112
|
+
},
|
|
113
|
+
getInteraction(configId) {
|
|
114
|
+
(0, error_1.validateConfigId)(configId, 'interaction');
|
|
115
|
+
return subscribedInteractions[configId];
|
|
116
|
+
},
|
|
117
|
+
setInteraction(configId, elementId, selection) {
|
|
118
|
+
(0, error_1.validateConfigId)(configId, 'interaction');
|
|
119
|
+
void execPromise('wb:plugin:selection:set', configId, elementId, selection);
|
|
120
|
+
},
|
|
121
|
+
triggerAction(configId) {
|
|
122
|
+
(0, error_1.validateConfigId)(configId, 'action-trigger');
|
|
123
|
+
void execPromise('wb:plugin:action-trigger:invoke', configId);
|
|
124
|
+
},
|
|
125
|
+
registerEffect(configId, effect) {
|
|
126
|
+
(0, error_1.validateConfigId)(configId, 'action-effect');
|
|
127
|
+
registeredEffects[configId] = effect;
|
|
128
|
+
return () => {
|
|
129
|
+
delete registeredEffects[configId];
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
configureEditorPanel(options) {
|
|
133
|
+
void execPromise('wb:plugin:config:inspector', options);
|
|
134
|
+
},
|
|
135
|
+
setLoadingState(loadingState) {
|
|
136
|
+
void execPromise('wb:plugin:config:loading-state', loadingState);
|
|
137
|
+
},
|
|
138
|
+
subscribeToWorkbookVariable(configId, callback) {
|
|
139
|
+
(0, error_1.validateConfigId)(configId, 'variable');
|
|
140
|
+
const setValues = (values) => {
|
|
141
|
+
callback(values[configId]);
|
|
142
|
+
};
|
|
143
|
+
on('wb:plugin:variable:update', setValues);
|
|
144
|
+
return () => {
|
|
145
|
+
off('wb:plugin:variable:update', setValues);
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
subscribeToWorkbookInteraction(configId, callback) {
|
|
149
|
+
(0, error_1.validateConfigId)(configId, 'interaction');
|
|
150
|
+
const setValues = (values) => {
|
|
151
|
+
callback(values[configId]);
|
|
152
|
+
};
|
|
153
|
+
on('wb:plugin:selection:update', setValues);
|
|
154
|
+
return () => {
|
|
155
|
+
off('wb:plugin:selection:update', setValues);
|
|
156
|
+
};
|
|
157
|
+
},
|
|
158
|
+
subscribeToUrlParameter(configId, callback) {
|
|
159
|
+
(0, error_1.validateConfigId)(configId, 'url-parameter');
|
|
160
|
+
const setValues = (values) => {
|
|
161
|
+
callback(values[configId]);
|
|
162
|
+
};
|
|
163
|
+
setValues(subscribedUrlParameters);
|
|
164
|
+
on('wb:plugin:url-parameter:update', setValues);
|
|
165
|
+
return () => {
|
|
166
|
+
off('wb:plugin:url-parameter:update', setValues);
|
|
167
|
+
};
|
|
168
|
+
},
|
|
169
|
+
getUrlParameter(configId) {
|
|
170
|
+
(0, error_1.validateConfigId)(configId, 'url-parameter');
|
|
171
|
+
return subscribedUrlParameters[configId];
|
|
172
|
+
},
|
|
173
|
+
setUrlParameter(configId, value) {
|
|
174
|
+
(0, error_1.validateConfigId)(configId, 'url-parameter');
|
|
175
|
+
void execPromise('wb:plugin:url-parameter:set', configId, value);
|
|
176
|
+
}
|
|
177
|
+
},
|
|
178
|
+
elements: {
|
|
179
|
+
getElementColumns(configId) {
|
|
180
|
+
(0, error_1.validateConfigId)(configId, 'element');
|
|
181
|
+
return execPromise('wb:plugin:element:columns:get', configId);
|
|
182
|
+
},
|
|
183
|
+
subscribeToElementColumns(configId, callback) {
|
|
184
|
+
(0, error_1.validateConfigId)(configId, 'element');
|
|
185
|
+
const eventName = `wb:plugin:element:${configId}:columns`;
|
|
186
|
+
on(eventName, callback);
|
|
187
|
+
void execPromise('wb:plugin:element:subscribe:columns', configId);
|
|
188
|
+
return () => {
|
|
189
|
+
off(eventName, callback);
|
|
190
|
+
void execPromise('wb:plugin:element:unsubscribe:columns', configId);
|
|
191
|
+
};
|
|
192
|
+
},
|
|
193
|
+
subscribeToElementData(configId, callback) {
|
|
194
|
+
(0, error_1.validateConfigId)(configId, 'element');
|
|
195
|
+
const eventName = `wb:plugin:element:${configId}:data`;
|
|
196
|
+
on(eventName, callback);
|
|
197
|
+
void execPromise('wb:plugin:element:subscribe:data', configId);
|
|
198
|
+
return () => {
|
|
199
|
+
off(eventName, callback);
|
|
200
|
+
void execPromise('wb:plugin:element:unsubscribe:data', configId);
|
|
201
|
+
};
|
|
202
|
+
},
|
|
203
|
+
fetchMoreElementData(configId) {
|
|
204
|
+
(0, error_1.validateConfigId)(configId, 'element');
|
|
205
|
+
void execPromise('wb:plugin:element:fetch-more', configId);
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
style: {
|
|
209
|
+
subscribe(callback) {
|
|
210
|
+
on('wb:plugin:style:update', callback);
|
|
211
|
+
return () => off('wb:plugin:style:update', callback);
|
|
212
|
+
},
|
|
213
|
+
get() {
|
|
214
|
+
return execPromise('wb:plugin:style:get');
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
destroy() {
|
|
218
|
+
Object.keys(listeners).forEach(event => delete listeners[event]);
|
|
219
|
+
window.removeEventListener('message', listener, false);
|
|
220
|
+
},
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
exports.initialize = initialize;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Context.d.ts","sourceRoot":"","sources":["../../src/react/Context.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,eAAO,MAAM,aAAa,8CAAwC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import { PluginInstance } from '../types';
|
|
3
|
+
export interface SigmaClientProviderProps<T = any> {
|
|
4
|
+
client: PluginInstance<T>;
|
|
5
|
+
children?: ReactNode;
|
|
6
|
+
}
|
|
7
|
+
export declare function SigmaClientProvider<T = any>(props: SigmaClientProviderProps<T>): import("react/jsx-runtime").JSX.Element;
|
|
8
|
+
//# sourceMappingURL=Provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../src/react/Provider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGvC,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,MAAM,WAAW,wBAAwB,CAAC,CAAC,GAAG,GAAG;IAC/C,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;IAC1B,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,wBAAgB,mBAAmB,CAAC,CAAC,GAAG,GAAG,EACzC,KAAK,EAAE,wBAAwB,CAAC,CAAC,CAAC,2CAOnC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SigmaClientProvider = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const Context_1 = require("./Context");
|
|
6
|
+
function SigmaClientProvider(props) {
|
|
7
|
+
return ((0, jsx_runtime_1.jsx)(Context_1.PluginContext.Provider, Object.assign({ value: props.client }, { children: props.children })));
|
|
8
|
+
}
|
|
9
|
+
exports.SigmaClientProvider = SigmaClientProvider;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { PluginInstance, CustomPluginConfigOptions, WorkbookElementColumns, WorkbookElementData, WorkbookVariable, PluginStyle, UrlParameter } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Gets the entire plugin instance
|
|
4
|
+
* @returns {PluginInstance} Context for the current plugin instance
|
|
5
|
+
*/
|
|
6
|
+
export declare function usePlugin(): PluginInstance<any>;
|
|
7
|
+
/**
|
|
8
|
+
* Provides a setter for the Plugin's Config Options
|
|
9
|
+
* @param {CustomPluginConfigOptions[]} nextOptions Updated possible Config Options
|
|
10
|
+
*/
|
|
11
|
+
export declare function useEditorPanelConfig(nextOptions: CustomPluginConfigOptions[]): void;
|
|
12
|
+
/**
|
|
13
|
+
* React hook for Plugin Config loading state
|
|
14
|
+
* @param {boolean} initialState Initial value to set loading state to
|
|
15
|
+
* @returns {[boolean, Function]} Boolean value corresponding to loading state for plugin config and setter for loading state
|
|
16
|
+
*/
|
|
17
|
+
export declare function useLoadingState(initialState: boolean): [boolean, (nextState: boolean) => void];
|
|
18
|
+
/**
|
|
19
|
+
* Provides the latest column values from corresponding config element
|
|
20
|
+
* @param {string} configId ID from the config for fetching element columns, with type: 'element'
|
|
21
|
+
* @returns {WorkbookElementColumns} Values of corresponding columns contained
|
|
22
|
+
* within the config element
|
|
23
|
+
*/
|
|
24
|
+
export declare function useElementColumns(configId: string): WorkbookElementColumns;
|
|
25
|
+
/**
|
|
26
|
+
* Provides the latest data values from config element (max 25_000)
|
|
27
|
+
* @param {string} configId ID from the config for fetching element data, with type: 'element'
|
|
28
|
+
* @returns {WorkbookElementData} Element Data for config element, if any
|
|
29
|
+
*/
|
|
30
|
+
export declare function useElementData(configId: string): WorkbookElementData;
|
|
31
|
+
/**
|
|
32
|
+
* Provides the latest data values from corresponding config element with a callback to
|
|
33
|
+
* fetch more in chunks of 25_000 data points
|
|
34
|
+
* @param {string} configId ID from the config for fetching paginated
|
|
35
|
+
* element data, with type: 'element'
|
|
36
|
+
* @returns {WorkbookElementData} Element Data for configured config element, if any
|
|
37
|
+
*/
|
|
38
|
+
export declare function usePaginatedElementData(configId: string): [WorkbookElementData, () => void];
|
|
39
|
+
/**
|
|
40
|
+
* Provides the latest value for entire config or certain key within the config
|
|
41
|
+
* @param {string} key Key within Plugin Config, optional
|
|
42
|
+
* @returns Entire config if no key passed in or value for key within plugin config
|
|
43
|
+
*/
|
|
44
|
+
export declare function useConfig(key?: string): any;
|
|
45
|
+
/**
|
|
46
|
+
* React hook for accessing a workbook control variable
|
|
47
|
+
* @param {string} id ID from the config of type: 'variable'
|
|
48
|
+
* @returns {[(WorkbookVariable | undefined), Function]} Constantly updating
|
|
49
|
+
* value of the control variable and setter for the variable
|
|
50
|
+
*/
|
|
51
|
+
export declare function useVariable(id: string): [WorkbookVariable | undefined, Function];
|
|
52
|
+
/**
|
|
53
|
+
* React hook for accessing a url parameter
|
|
54
|
+
* @param {string} id ID from the config of type: 'url-parameter'
|
|
55
|
+
* @returns {[(UrlParameter | undefined), Function]} Constantly updating value of the url parameter and setter for the url parameter
|
|
56
|
+
*/
|
|
57
|
+
export declare function useUrlParameter(id: string): [UrlParameter | undefined, (value: string) => void];
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated Use Action API instead
|
|
60
|
+
* React hook for accessing a workbook interaction selections state
|
|
61
|
+
* @param {string} id ID from the config of type: 'interaction'
|
|
62
|
+
* @returns {[(WorkbookSelection | undefined), Function]} Constantly updating selection state and setter thereof
|
|
63
|
+
*/
|
|
64
|
+
export declare function useInteraction(id: string, elementId: string): [unknown, Function];
|
|
65
|
+
/**
|
|
66
|
+
* React hook for returning a triggering callback function for the registered
|
|
67
|
+
* action trigger
|
|
68
|
+
* @param {string} configId ID from the config of type: 'action-trigger'
|
|
69
|
+
* @returns {Function} A callback function to trigger the action
|
|
70
|
+
*/
|
|
71
|
+
export declare function useActionTrigger(configId: string): () => void;
|
|
72
|
+
/**
|
|
73
|
+
* React hook for registering and unregistering an action effect
|
|
74
|
+
* @param {string} configId ID from the config of type: 'action-effect'
|
|
75
|
+
* @param {Function} effect The function to be called when the action is triggered
|
|
76
|
+
*/
|
|
77
|
+
export declare function useActionEffect(configId: string, effect: () => void): void;
|
|
78
|
+
/**
|
|
79
|
+
* React hook for accessing plugin style with live updates
|
|
80
|
+
* @returns {PluginStyle | undefined} Style properties from the workbook if available
|
|
81
|
+
*/
|
|
82
|
+
export declare function usePluginStyle(): PluginStyle | undefined;
|
|
83
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/react/hooks.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,cAAc,EACd,yBAAyB,EACzB,sBAAsB,EACtB,mBAAmB,EAEnB,gBAAgB,EAChB,WAAW,EACX,YAAY,EACb,MAAM,UAAU,CAAC;AAGlB;;;GAGG;AACH,wBAAgB,SAAS,IAAI,cAAc,CAAC,GAAG,CAAC,CAE/C;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,yBAAyB,EAAE,GACvC,IAAI,CAWN;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,OAAO,GACpB,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC,CAezC;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,QAAQ,EAAE,MAAM,GAAG,sBAAsB,CAW1E;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,GAAG,mBAAmB,CAWpE;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,QAAQ,EAAE,MAAM,GACf,CAAC,mBAAmB,EAAE,MAAM,IAAI,CAAC,CAiBnC;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAmB3C;AAED;;;;;GAKG;AACH,wBAAgB,WAAW,CACzB,EAAE,EAAE,MAAM,GACT,CAAC,gBAAgB,GAAG,SAAS,EAAE,QAAQ,CAAC,CAoB1C;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,EAAE,EAAE,MAAM,GACT,CAAC,YAAY,GAAG,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,CAoBrD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,MAAM,GAChB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAoBrB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,IAAI,CAM7D;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,QAYnE;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,WAAW,GAAG,SAAS,CAWxD"}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePluginStyle = exports.useActionEffect = exports.useActionTrigger = exports.useInteraction = exports.useUrlParameter = exports.useVariable = exports.useConfig = exports.usePaginatedElementData = exports.useElementData = exports.useElementColumns = exports.useLoadingState = exports.useEditorPanelConfig = exports.usePlugin = void 0;
|
|
4
|
+
const react_1 = require("react");
|
|
5
|
+
const Context_1 = require("./Context");
|
|
6
|
+
const deepEqual_1 = require("../utils/deepEqual");
|
|
7
|
+
/**
|
|
8
|
+
* Gets the entire plugin instance
|
|
9
|
+
* @returns {PluginInstance} Context for the current plugin instance
|
|
10
|
+
*/
|
|
11
|
+
function usePlugin() {
|
|
12
|
+
return (0, react_1.useContext)(Context_1.PluginContext);
|
|
13
|
+
}
|
|
14
|
+
exports.usePlugin = usePlugin;
|
|
15
|
+
/**
|
|
16
|
+
* Provides a setter for the Plugin's Config Options
|
|
17
|
+
* @param {CustomPluginConfigOptions[]} nextOptions Updated possible Config Options
|
|
18
|
+
*/
|
|
19
|
+
function useEditorPanelConfig(nextOptions) {
|
|
20
|
+
const client = usePlugin();
|
|
21
|
+
const optionsRef = (0, react_1.useRef)({});
|
|
22
|
+
(0, react_1.useEffect)(() => {
|
|
23
|
+
if (nextOptions == null)
|
|
24
|
+
return;
|
|
25
|
+
if (!(0, deepEqual_1.deepEqual)(nextOptions, optionsRef.current)) {
|
|
26
|
+
client.config.configureEditorPanel(nextOptions);
|
|
27
|
+
optionsRef.current = nextOptions;
|
|
28
|
+
}
|
|
29
|
+
}, [client, nextOptions]);
|
|
30
|
+
}
|
|
31
|
+
exports.useEditorPanelConfig = useEditorPanelConfig;
|
|
32
|
+
/**
|
|
33
|
+
* React hook for Plugin Config loading state
|
|
34
|
+
* @param {boolean} initialState Initial value to set loading state to
|
|
35
|
+
* @returns {[boolean, Function]} Boolean value corresponding to loading state for plugin config and setter for loading state
|
|
36
|
+
*/
|
|
37
|
+
function useLoadingState(initialState) {
|
|
38
|
+
const client = usePlugin();
|
|
39
|
+
const [loading, setLoading] = (0, react_1.useState)(() => {
|
|
40
|
+
client.config.setLoadingState(initialState);
|
|
41
|
+
return initialState;
|
|
42
|
+
});
|
|
43
|
+
return [
|
|
44
|
+
loading,
|
|
45
|
+
nextState => {
|
|
46
|
+
if (nextState === loading)
|
|
47
|
+
return;
|
|
48
|
+
setLoading(nextState);
|
|
49
|
+
client.config.setLoadingState(nextState);
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
}
|
|
53
|
+
exports.useLoadingState = useLoadingState;
|
|
54
|
+
/**
|
|
55
|
+
* Provides the latest column values from corresponding config element
|
|
56
|
+
* @param {string} configId ID from the config for fetching element columns, with type: 'element'
|
|
57
|
+
* @returns {WorkbookElementColumns} Values of corresponding columns contained
|
|
58
|
+
* within the config element
|
|
59
|
+
*/
|
|
60
|
+
function useElementColumns(configId) {
|
|
61
|
+
const client = usePlugin();
|
|
62
|
+
const [columns, setColumns] = (0, react_1.useState)({});
|
|
63
|
+
(0, react_1.useEffect)(() => {
|
|
64
|
+
if (configId) {
|
|
65
|
+
return client.elements.subscribeToElementColumns(configId, setColumns);
|
|
66
|
+
}
|
|
67
|
+
}, [client, configId]);
|
|
68
|
+
return columns;
|
|
69
|
+
}
|
|
70
|
+
exports.useElementColumns = useElementColumns;
|
|
71
|
+
/**
|
|
72
|
+
* Provides the latest data values from config element (max 25_000)
|
|
73
|
+
* @param {string} configId ID from the config for fetching element data, with type: 'element'
|
|
74
|
+
* @returns {WorkbookElementData} Element Data for config element, if any
|
|
75
|
+
*/
|
|
76
|
+
function useElementData(configId) {
|
|
77
|
+
const client = usePlugin();
|
|
78
|
+
const [data, setData] = (0, react_1.useState)({});
|
|
79
|
+
(0, react_1.useEffect)(() => {
|
|
80
|
+
if (configId) {
|
|
81
|
+
return client.elements.subscribeToElementData(configId, setData);
|
|
82
|
+
}
|
|
83
|
+
}, [client, configId]);
|
|
84
|
+
return data;
|
|
85
|
+
}
|
|
86
|
+
exports.useElementData = useElementData;
|
|
87
|
+
/**
|
|
88
|
+
* Provides the latest data values from corresponding config element with a callback to
|
|
89
|
+
* fetch more in chunks of 25_000 data points
|
|
90
|
+
* @param {string} configId ID from the config for fetching paginated
|
|
91
|
+
* element data, with type: 'element'
|
|
92
|
+
* @returns {WorkbookElementData} Element Data for configured config element, if any
|
|
93
|
+
*/
|
|
94
|
+
function usePaginatedElementData(configId) {
|
|
95
|
+
const client = usePlugin();
|
|
96
|
+
const [data, setData] = (0, react_1.useState)({});
|
|
97
|
+
const loadMore = (0, react_1.useCallback)(() => {
|
|
98
|
+
if (configId) {
|
|
99
|
+
client.elements.fetchMoreElementData(configId);
|
|
100
|
+
}
|
|
101
|
+
}, [configId]);
|
|
102
|
+
(0, react_1.useEffect)(() => {
|
|
103
|
+
if (configId) {
|
|
104
|
+
return client.elements.subscribeToElementData(configId, setData);
|
|
105
|
+
}
|
|
106
|
+
}, [client, configId]);
|
|
107
|
+
return [data, loadMore];
|
|
108
|
+
}
|
|
109
|
+
exports.usePaginatedElementData = usePaginatedElementData;
|
|
110
|
+
/**
|
|
111
|
+
* Provides the latest value for entire config or certain key within the config
|
|
112
|
+
* @param {string} key Key within Plugin Config, optional
|
|
113
|
+
* @returns Entire config if no key passed in or value for key within plugin config
|
|
114
|
+
*/
|
|
115
|
+
function useConfig(key) {
|
|
116
|
+
const client = usePlugin();
|
|
117
|
+
const [config, setConfig] = (0, react_1.useState)(key != null ? client.config.getKey(key) : client.config.get());
|
|
118
|
+
(0, react_1.useEffect)(() => client.config.subscribe(newConfig => {
|
|
119
|
+
if (key != null && newConfig[key] !== config[key]) {
|
|
120
|
+
setConfig(newConfig[key]);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
setConfig(newConfig);
|
|
124
|
+
}
|
|
125
|
+
}), [client]);
|
|
126
|
+
return config;
|
|
127
|
+
}
|
|
128
|
+
exports.useConfig = useConfig;
|
|
129
|
+
/**
|
|
130
|
+
* React hook for accessing a workbook control variable
|
|
131
|
+
* @param {string} id ID from the config of type: 'variable'
|
|
132
|
+
* @returns {[(WorkbookVariable | undefined), Function]} Constantly updating
|
|
133
|
+
* value of the control variable and setter for the variable
|
|
134
|
+
*/
|
|
135
|
+
function useVariable(id) {
|
|
136
|
+
const client = usePlugin();
|
|
137
|
+
const [workbookVariable, setWorkbookVariable] = (0, react_1.useState)();
|
|
138
|
+
const isFirstRender = (0, react_1.useRef)(true);
|
|
139
|
+
(0, react_1.useEffect)(() => {
|
|
140
|
+
if (isFirstRender.current) {
|
|
141
|
+
setWorkbookVariable(client.config.getVariable(id));
|
|
142
|
+
isFirstRender.current = false;
|
|
143
|
+
}
|
|
144
|
+
return client.config.subscribeToWorkbookVariable(id, setWorkbookVariable);
|
|
145
|
+
}, [client, id]);
|
|
146
|
+
const setVariable = (0, react_1.useCallback)((...values) => client.config.setVariable(id, ...values), [id]);
|
|
147
|
+
return [workbookVariable, setVariable];
|
|
148
|
+
}
|
|
149
|
+
exports.useVariable = useVariable;
|
|
150
|
+
/**
|
|
151
|
+
* React hook for accessing a url parameter
|
|
152
|
+
* @param {string} id ID from the config of type: 'url-parameter'
|
|
153
|
+
* @returns {[(UrlParameter | undefined), Function]} Constantly updating value of the url parameter and setter for the url parameter
|
|
154
|
+
*/
|
|
155
|
+
function useUrlParameter(id) {
|
|
156
|
+
const client = usePlugin();
|
|
157
|
+
const [urlParameter, setUrlParameter] = (0, react_1.useState)();
|
|
158
|
+
const isFirstRender = (0, react_1.useRef)(true);
|
|
159
|
+
(0, react_1.useEffect)(() => {
|
|
160
|
+
if (isFirstRender.current) {
|
|
161
|
+
setUrlParameter(client.config.getUrlParameter(id));
|
|
162
|
+
isFirstRender.current = false;
|
|
163
|
+
}
|
|
164
|
+
return client.config.subscribeToUrlParameter(id, setUrlParameter);
|
|
165
|
+
}, [client, id]);
|
|
166
|
+
const setter = (0, react_1.useCallback)((value) => client.config.setUrlParameter(id, value), [client, id]);
|
|
167
|
+
return [urlParameter, setter];
|
|
168
|
+
}
|
|
169
|
+
exports.useUrlParameter = useUrlParameter;
|
|
170
|
+
/**
|
|
171
|
+
* @deprecated Use Action API instead
|
|
172
|
+
* React hook for accessing a workbook interaction selections state
|
|
173
|
+
* @param {string} id ID from the config of type: 'interaction'
|
|
174
|
+
* @returns {[(WorkbookSelection | undefined), Function]} Constantly updating selection state and setter thereof
|
|
175
|
+
*/
|
|
176
|
+
function useInteraction(id, elementId) {
|
|
177
|
+
const client = usePlugin();
|
|
178
|
+
const [workbookInteraction, setWorkbookInteraction] = (0, react_1.useState)();
|
|
179
|
+
(0, react_1.useEffect)(() => {
|
|
180
|
+
return client.config.subscribeToWorkbookInteraction(id, setWorkbookInteraction);
|
|
181
|
+
}, [client, id]);
|
|
182
|
+
const setInteraction = (0, react_1.useCallback)((value) => {
|
|
183
|
+
client.config.setInteraction(id, elementId, value);
|
|
184
|
+
}, [id]);
|
|
185
|
+
return [workbookInteraction, setInteraction];
|
|
186
|
+
}
|
|
187
|
+
exports.useInteraction = useInteraction;
|
|
188
|
+
/**
|
|
189
|
+
* React hook for returning a triggering callback function for the registered
|
|
190
|
+
* action trigger
|
|
191
|
+
* @param {string} configId ID from the config of type: 'action-trigger'
|
|
192
|
+
* @returns {Function} A callback function to trigger the action
|
|
193
|
+
*/
|
|
194
|
+
function useActionTrigger(configId) {
|
|
195
|
+
const client = usePlugin();
|
|
196
|
+
return (0, react_1.useCallback)(() => {
|
|
197
|
+
client.config.triggerAction(configId);
|
|
198
|
+
}, [client, configId]);
|
|
199
|
+
}
|
|
200
|
+
exports.useActionTrigger = useActionTrigger;
|
|
201
|
+
/**
|
|
202
|
+
* React hook for registering and unregistering an action effect
|
|
203
|
+
* @param {string} configId ID from the config of type: 'action-effect'
|
|
204
|
+
* @param {Function} effect The function to be called when the action is triggered
|
|
205
|
+
*/
|
|
206
|
+
function useActionEffect(configId, effect) {
|
|
207
|
+
const client = usePlugin();
|
|
208
|
+
const effectRef = (0, react_1.useRef)(effect);
|
|
209
|
+
(0, react_1.useEffect)(() => {
|
|
210
|
+
effectRef.current = effect;
|
|
211
|
+
});
|
|
212
|
+
(0, react_1.useEffect)(() => {
|
|
213
|
+
return client.config.registerEffect(configId, effectRef.current);
|
|
214
|
+
}, [client, configId, effect]);
|
|
215
|
+
}
|
|
216
|
+
exports.useActionEffect = useActionEffect;
|
|
217
|
+
/**
|
|
218
|
+
* React hook for accessing plugin style with live updates
|
|
219
|
+
* @returns {PluginStyle | undefined} Style properties from the workbook if available
|
|
220
|
+
*/
|
|
221
|
+
function usePluginStyle() {
|
|
222
|
+
const client = usePlugin();
|
|
223
|
+
const [style, setStyle] = (0, react_1.useState)();
|
|
224
|
+
(0, react_1.useEffect)(() => {
|
|
225
|
+
// Request initial style data on mount and subscribe to updates
|
|
226
|
+
void client.style.get().then(response => setStyle(response));
|
|
227
|
+
return client.style.subscribe(setStyle);
|
|
228
|
+
}, [client]);
|
|
229
|
+
return style;
|
|
230
|
+
}
|
|
231
|
+
exports.usePluginStyle = usePluginStyle;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepEqual.d.ts","sourceRoot":"","sources":["../../src/utils/deepEqual.ts"],"names":[],"mappings":"AAQA,wBAAgB,SAAS,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,uBAc7C"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deepEqual = void 0;
|
|
4
|
+
function isObject(obj) {
|
|
5
|
+
if (typeof obj === 'object' && obj != null) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
else {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
function deepEqual(obj1, obj2) {
|
|
13
|
+
if (obj1 === obj2) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
else if (isObject(obj1) && isObject(obj2)) {
|
|
17
|
+
if (Object.keys(obj1).length !== Object.keys(obj2).length) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
for (const prop in obj1) {
|
|
21
|
+
if (!deepEqual(obj1[prop], obj2[prop])) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
exports.deepEqual = deepEqual;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* requestAnimationFrame() calls are paused in most browsers when running in background tabs or hidden <iframe>s in order to improve performance and battery life
|
|
3
|
+
*
|
|
4
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
|
|
5
|
+
* @param w Window Object
|
|
6
|
+
*/
|
|
7
|
+
export declare function polyfillRequestAnimationFrame(w: Window): void;
|
|
8
|
+
//# sourceMappingURL=polyfillRequestAnimationFrame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfillRequestAnimationFrame.d.ts","sourceRoot":"","sources":["../../src/utils/polyfillRequestAnimationFrame.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,CAAC,EAAE,MAAM,QAKtD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.polyfillRequestAnimationFrame = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* requestAnimationFrame() calls are paused in most browsers when running in background tabs or hidden <iframe>s in order to improve performance and battery life
|
|
6
|
+
*
|
|
7
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame
|
|
8
|
+
* @param w Window Object
|
|
9
|
+
*/
|
|
10
|
+
function polyfillRequestAnimationFrame(w) {
|
|
11
|
+
if ('requestAnimationFrame' in w) {
|
|
12
|
+
w.requestAnimationFrame = cb => w.setTimeout(cb, 1000 / 60);
|
|
13
|
+
w.cancelAnimationFrame = id => w.clearTimeout(id);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
exports.polyfillRequestAnimationFrame = polyfillRequestAnimationFrame;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sigmacomputing/plugin",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Sigma Computing Plugin Client API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/sigmacomputing/plugin",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"packageManager": "yarn@4.4.1",
|
|
17
17
|
"files": [
|
|
18
|
-
"dist
|
|
18
|
+
"dist/**/*"
|
|
19
19
|
],
|
|
20
20
|
"typesVersions": {
|
|
21
21
|
"*": {
|
|
@@ -24,6 +24,9 @@
|
|
|
24
24
|
]
|
|
25
25
|
}
|
|
26
26
|
},
|
|
27
|
+
"publishConfig": {
|
|
28
|
+
"access": "public"
|
|
29
|
+
},
|
|
27
30
|
"scripts": {
|
|
28
31
|
"build": "yarn tsc --build tsconfig.build.json",
|
|
29
32
|
"build:watch": "yarn build --watch",
|