@sigmacomputing/plugin 0.7.57 → 1.0.0-rc.2
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/.gitignore +30 -0
- package/.lintstagedrc +3 -0
- package/.nvmrc +1 -0
- package/.prettierrc +5 -0
- package/CHANGELOG.md +25 -0
- package/CONTRIBUTING.md +60 -0
- package/{LICENSE.md → LICENSE} +0 -0
- package/README.md +782 -8
- package/assets/sigma-logo-dark.svg +54 -0
- package/assets/sigma-logo-light.svg +50 -0
- package/dist/client/index.d.ts +4 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/{client.js → client/index.js} +2 -1
- package/dist/client/initialize.d.ts +3 -0
- package/dist/client/initialize.d.ts.map +1 -0
- package/dist/{initialize.js → client/initialize.js} +1 -1
- package/dist/client/react/Context.d.ts +4 -0
- package/dist/client/react/Context.d.ts.map +1 -0
- package/dist/client/react/Context.js +6 -0
- package/dist/client/react/Provider.d.ts +8 -0
- package/dist/client/react/Provider.d.ts.map +1 -0
- package/dist/client/react/Provider.js +9 -0
- package/dist/client/react/hooks.d.ts +48 -0
- package/dist/client/react/hooks.d.ts.map +1 -0
- package/dist/{react/index.js → client/react/hooks.js} +23 -60
- package/dist/client/react/index.d.ts +5 -0
- package/dist/client/react/index.d.ts.map +1 -0
- package/dist/client/react/index.js +22 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -11
- package/dist/types.d.ts +262 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/{deepEqual.d.ts → utils/deepEqual.d.ts} +0 -0
- package/dist/utils/deepEqual.d.ts.map +1 -0
- package/dist/utils/deepEqual.js +28 -0
- package/jest.config.ts +22 -0
- package/package.json +50 -17
- package/src/client/__tests__/initialize.test.ts +30 -0
- package/src/client/index.ts +5 -0
- package/src/client/initialize.ts +199 -0
- package/src/client/react/Context.ts +6 -0
- package/src/client/react/Provider.tsx +19 -0
- package/src/client/react/hooks.ts +178 -0
- package/src/client/react/index.tsx +9 -0
- package/src/index.ts +2 -0
- package/src/types.ts +322 -0
- package/src/utils/deepEqual.ts +23 -0
- package/tsconfig.build.json +9 -0
- package/tsconfig.json +35 -0
- package/yarn.lock +3226 -0
- package/dist/client.d.ts +0 -2
- package/dist/client.d.ts.map +0 -1
- package/dist/deepEqual.d.ts.map +0 -1
- package/dist/deepEqual.js +0 -46
- package/dist/initialize.d.ts +0 -3
- package/dist/initialize.d.ts.map +0 -1
- package/dist/initialize.test.d.ts +0 -2
- package/dist/initialize.test.d.ts.map +0 -1
- package/dist/initialize.test.js +0 -26
- package/dist/react/index.d.ts +0 -58
- package/dist/react/index.d.ts.map +0 -1
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
export declare type ScalarType = 'boolean' | 'datetime' | 'number' | 'integer' | 'text';
|
|
2
|
+
export declare type PrimitiveType = ScalarType | 'variant' | 'link';
|
|
3
|
+
export declare type ValueType = PrimitiveType | 'error';
|
|
4
|
+
/**
|
|
5
|
+
* All mutable workbook control variable types
|
|
6
|
+
*/
|
|
7
|
+
export declare type ControlType = 'boolean' | 'date' | 'number' | 'text' | 'text-list' | 'number-list' | 'date-list' | 'number-range' | 'date-range';
|
|
8
|
+
export interface PluginConfig<T> {
|
|
9
|
+
id: string;
|
|
10
|
+
config: T;
|
|
11
|
+
screenshot: boolean;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @typedef {object} WorkbookVariable
|
|
16
|
+
* @property {string} name Name of Control Variable within Workbook
|
|
17
|
+
* @property {{string}} defaultValue Current Value containing at least type as string
|
|
18
|
+
*/
|
|
19
|
+
export interface WorkbookVariable {
|
|
20
|
+
name: string;
|
|
21
|
+
defaultValue: {
|
|
22
|
+
type: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export declare type WorkbookSelection = Record<string, {
|
|
26
|
+
type: string;
|
|
27
|
+
val?: unknown;
|
|
28
|
+
}>;
|
|
29
|
+
export declare type PluginMessageResponse = MessageEvent<{
|
|
30
|
+
type: string;
|
|
31
|
+
result: any[];
|
|
32
|
+
error: any;
|
|
33
|
+
}>;
|
|
34
|
+
export interface WbElement {
|
|
35
|
+
id: string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @typedef {object} WorkbookElementData
|
|
39
|
+
* @property {Object<string, any>} data Workbook data sorted by column ID
|
|
40
|
+
*/
|
|
41
|
+
export interface WorkbookElementData {
|
|
42
|
+
[colId: string]: any[];
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Column data
|
|
46
|
+
* @typedef {object} WorkbookElementColumn
|
|
47
|
+
* @property {string} id Column ID
|
|
48
|
+
* @property {string} name Column Name
|
|
49
|
+
* @property {string} columnType Type of data contained within column
|
|
50
|
+
*/
|
|
51
|
+
export interface WorkbookElementColumn {
|
|
52
|
+
id: string;
|
|
53
|
+
name: string;
|
|
54
|
+
columnType: ValueType;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Record of Column data with corresponding IDs
|
|
58
|
+
* @typedef {object} WorkbookElementColumns
|
|
59
|
+
* @property {Object<string, WorkbookElementColumn>} column Column ID and corresponding column data
|
|
60
|
+
*/
|
|
61
|
+
export interface WorkbookElementColumns {
|
|
62
|
+
[colId: string]: WorkbookElementColumn;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Function to Unsubscribe from the corresponding elements
|
|
66
|
+
* @typedef {() => void} Unsubscriber
|
|
67
|
+
*/
|
|
68
|
+
export declare type Unsubscriber = () => void;
|
|
69
|
+
/**
|
|
70
|
+
* Different types Plugin Config Options
|
|
71
|
+
* @typedef {object} CustomPluginConfigOptions
|
|
72
|
+
* @property {string} type Type of config option
|
|
73
|
+
* @property {string} name Name ID of config option
|
|
74
|
+
* @property {(string | undefined)} label Displayed label for config option
|
|
75
|
+
*/
|
|
76
|
+
export declare type CustomPluginConfigOptions = {
|
|
77
|
+
type: 'group';
|
|
78
|
+
name: string;
|
|
79
|
+
label?: string;
|
|
80
|
+
} | {
|
|
81
|
+
type: 'element';
|
|
82
|
+
name: string;
|
|
83
|
+
label?: string;
|
|
84
|
+
} | {
|
|
85
|
+
type: 'column';
|
|
86
|
+
name: string;
|
|
87
|
+
label?: string;
|
|
88
|
+
allowedTypes?: ValueType[];
|
|
89
|
+
source: string;
|
|
90
|
+
allowMultiple: boolean;
|
|
91
|
+
} | {
|
|
92
|
+
type: 'text';
|
|
93
|
+
name: string;
|
|
94
|
+
label?: string;
|
|
95
|
+
source?: string;
|
|
96
|
+
secure?: boolean;
|
|
97
|
+
multiline?: boolean;
|
|
98
|
+
placeholder?: string;
|
|
99
|
+
defaultValue?: string;
|
|
100
|
+
} | {
|
|
101
|
+
type: 'toggle';
|
|
102
|
+
name: string;
|
|
103
|
+
label?: string;
|
|
104
|
+
source?: string;
|
|
105
|
+
defaultValue?: boolean;
|
|
106
|
+
} | {
|
|
107
|
+
type: 'checkbox';
|
|
108
|
+
name: string;
|
|
109
|
+
label?: string;
|
|
110
|
+
source?: string;
|
|
111
|
+
defaultValue?: boolean;
|
|
112
|
+
} | {
|
|
113
|
+
type: 'radio';
|
|
114
|
+
name: string;
|
|
115
|
+
label?: string;
|
|
116
|
+
source?: string;
|
|
117
|
+
values: string[];
|
|
118
|
+
singleLine?: boolean;
|
|
119
|
+
defaultValue?: string;
|
|
120
|
+
} | {
|
|
121
|
+
type: 'dropdown';
|
|
122
|
+
name: string;
|
|
123
|
+
label?: string;
|
|
124
|
+
source?: string;
|
|
125
|
+
width?: string;
|
|
126
|
+
values: string[];
|
|
127
|
+
defaultValue?: string;
|
|
128
|
+
} | {
|
|
129
|
+
type: 'color';
|
|
130
|
+
name: string;
|
|
131
|
+
label?: string;
|
|
132
|
+
source?: string;
|
|
133
|
+
} | {
|
|
134
|
+
type: 'variable';
|
|
135
|
+
name: string;
|
|
136
|
+
label?: string;
|
|
137
|
+
allowedTypes?: ControlType[];
|
|
138
|
+
} | {
|
|
139
|
+
type: 'interaction';
|
|
140
|
+
name: string;
|
|
141
|
+
label?: string;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* @typedef {object} PluginInstance
|
|
145
|
+
* @template T Type of Config passed in
|
|
146
|
+
* @property {string} sigmaEnv Permissions within Sigma Environment
|
|
147
|
+
* @property {object} config Set of helper functions for interacting with Plugin Config
|
|
148
|
+
* @property {object} elements Set of helper functions for interacting with Workbook Element Data
|
|
149
|
+
* @property {Function} destroy Destroys Plugin Instance and removes all subscriptions
|
|
150
|
+
*/
|
|
151
|
+
export interface PluginInstance<T = any> {
|
|
152
|
+
sigmaEnv: 'author' | 'viewer' | 'explorer';
|
|
153
|
+
config: {
|
|
154
|
+
/**
|
|
155
|
+
* Getter for entire Plugin Config
|
|
156
|
+
* @template T Config type to be passed in
|
|
157
|
+
* @returns {Partial<T>} Current Plugin Config
|
|
158
|
+
*/
|
|
159
|
+
get(): Partial<T> | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Performs a shallow merge between current config and passed in config
|
|
162
|
+
* @template T Config type to be passed in
|
|
163
|
+
* @param {Partial<T>} config Config to directly assign
|
|
164
|
+
*/
|
|
165
|
+
set(config: Partial<T>): void;
|
|
166
|
+
/**
|
|
167
|
+
* Getter for key within plugin config
|
|
168
|
+
* @template K Possible key within CustomPluginConfigOptions
|
|
169
|
+
* @param {K} key Key within config to retrieve
|
|
170
|
+
* @returns Value within config for passed in key
|
|
171
|
+
*/
|
|
172
|
+
getKey<K extends keyof T>(key: K): Pick<T, K>;
|
|
173
|
+
/**
|
|
174
|
+
* Assigns key value pair within plugin
|
|
175
|
+
* @template K Possible key within CustomPluginConfigOptions
|
|
176
|
+
* @template V Value corresponding to K
|
|
177
|
+
* @param {K} key Key within config to set
|
|
178
|
+
* @param {V} value New value to set key to
|
|
179
|
+
*/
|
|
180
|
+
setKey<K extends keyof T>(key: K, value: Pick<T, K>): void;
|
|
181
|
+
/**
|
|
182
|
+
* Subscriber for Plugin Config
|
|
183
|
+
* @param {Function} listener Function to be called upon changes to Plugin Config
|
|
184
|
+
*/
|
|
185
|
+
subscribe(listener: (arg0: T) => void): Unsubscriber;
|
|
186
|
+
/**
|
|
187
|
+
* Set possible options for plugin config
|
|
188
|
+
* @param {CustomPluginConfigOptions[]} options Possible config options
|
|
189
|
+
*/
|
|
190
|
+
configureEditorPanel(options: CustomPluginConfigOptions[]): void;
|
|
191
|
+
/**
|
|
192
|
+
* Gets a static image of a workbook variable
|
|
193
|
+
* @param {string} id ID of the workbook variable in config
|
|
194
|
+
* @returns {WorkbookVariable} Current value of the workbook variable
|
|
195
|
+
*/
|
|
196
|
+
getVariable(id: string): WorkbookVariable;
|
|
197
|
+
/**
|
|
198
|
+
* Setter for workbook variable passed in
|
|
199
|
+
* @param {string} id ID of the workbook variable in config
|
|
200
|
+
* @param {unknown[]} values Values to assign to the workbook variable
|
|
201
|
+
*/
|
|
202
|
+
setVariable(id: string, ...values: unknown[]): void;
|
|
203
|
+
/**
|
|
204
|
+
* Getter for interaction selection state
|
|
205
|
+
* @param {string} id ID from interaction type in Plugin Config
|
|
206
|
+
*/
|
|
207
|
+
getInteraction(id: string): WorkbookSelection[];
|
|
208
|
+
/**
|
|
209
|
+
* Setter for interaction selection state
|
|
210
|
+
* @param {string} id ID from interaction type in Plugin Config
|
|
211
|
+
* @param {string} elementId Source element ID from element type in Plugin Config
|
|
212
|
+
* @param {Object} selection List of column IDs or Columns and values and key-value pairs to select
|
|
213
|
+
*/
|
|
214
|
+
setInteraction(id: string, elementId: string, selection: WorkbookSelection[]): void;
|
|
215
|
+
/**
|
|
216
|
+
* Overrider function for Config Ready state
|
|
217
|
+
* @param {boolean} loadingState Boolean representing if Plugin Config is still loading
|
|
218
|
+
*/
|
|
219
|
+
setLoadingState(ready: boolean): void;
|
|
220
|
+
/**
|
|
221
|
+
* Allows users to subscribe to changes in the passed in variable
|
|
222
|
+
* @param {string} id ID of the workbook variable in config
|
|
223
|
+
* @callback callback Function to be called upon receiving an updated workbook variable
|
|
224
|
+
* @returns {Unsubscriber} A callable unsubscriber
|
|
225
|
+
*/
|
|
226
|
+
subscribeToWorkbookVariable(id: string, callback: (input: WorkbookVariable) => void): Unsubscriber;
|
|
227
|
+
/**
|
|
228
|
+
* Allows users to subscribe to changes in the passed in interaction ID
|
|
229
|
+
* @param {string} id ID of the interaction variable within Plugin Config
|
|
230
|
+
* @callback callback Function to be called upon receiving an updated interaction selection state
|
|
231
|
+
* @returns {Unsubscriber} A callable unsubscriber
|
|
232
|
+
*/
|
|
233
|
+
subscribeToWorkbookInteraction(id: string, callback: (input: WorkbookSelection[]) => void): Unsubscriber;
|
|
234
|
+
};
|
|
235
|
+
elements: {
|
|
236
|
+
/**
|
|
237
|
+
* Getter for Column Data by parent sheet ID
|
|
238
|
+
* @param {string} id Sheet ID to retrieve columns from
|
|
239
|
+
* @returns {WorkbookElementColumns} Column values contained within corresponding sheet
|
|
240
|
+
*/
|
|
241
|
+
getElementColumns(id: string): Promise<WorkbookElementColumns>;
|
|
242
|
+
/**
|
|
243
|
+
* Subscriber to changes in column data by ID
|
|
244
|
+
* @param {string} id Column ID to subscribe to
|
|
245
|
+
* @callback callback Callback function to be called upon changes to column data
|
|
246
|
+
* @returns {Unsubscriber} Callable unsubscriber to column data changes
|
|
247
|
+
*/
|
|
248
|
+
subscribeToElementColumns(id: string, callback: (cols: WorkbookElementColumns) => void): Unsubscriber;
|
|
249
|
+
/**
|
|
250
|
+
* Subscriber for the data within a given sheet
|
|
251
|
+
* @param {string} id Sheet ID to get element data from
|
|
252
|
+
* @callback callback Function to call on data passed in
|
|
253
|
+
* @returns {Unsubscriber} A callable unsubscriber to changes in the data
|
|
254
|
+
*/
|
|
255
|
+
subscribeToElementData(id: string, callback: (data: WorkbookElementData) => void): Unsubscriber;
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Destroys plugin instance and removes all subscribers
|
|
259
|
+
*/
|
|
260
|
+
destroy(): void;
|
|
261
|
+
}
|
|
262
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU,GAAG,SAAS,GAAG,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAChF,oBAAY,aAAa,GAAG,UAAU,GAAG,SAAS,GAAG,MAAM,CAAC;AAC5D,oBAAY,SAAS,GAAG,aAAa,GAAG,OAAO,CAAC;AAEhD;;GAEG;AACH,oBAAY,WAAW,GACnB,SAAS,GACT,MAAM,GACN,QAAQ,GACR,MAAM,GACN,WAAW,GACX,aAAa,GACb,WAAW,GACX,cAAc,GACd,YAAY,CAAC;AAEjB,MAAM,WAAW,YAAY,CAAC,CAAC;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,CAAC,CAAC;IACV,UAAU,EAAE,OAAO,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CAChC;AAED,oBAAY,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,CAAC;AAEhF,oBAAY,qBAAqB,GAAG,YAAY,CAAC;IAC/C,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,GAAG,EAAE,CAAC;IACd,KAAK,EAAE,GAAG,CAAC;CACZ,CAAC,CAAC;AAEH,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,CAAC,KAAK,EAAE,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,EAAE,MAAM,EACV,QAAQ,EAAE,CAAC,KAAK,EAAE,iBAAiB,EAAE,KAAK,IAAI,GAC7C,YAAY,CAAC;KACjB,CAAC;IAEF,QAAQ,EAAE;QACR;;;;WAIG;QACH,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,sBAAsB,CAAC,CAAC;QAE/D;;;;;WAKG;QACH,yBAAyB,CACvB,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,CAAC,IAAI,EAAE,sBAAsB,KAAK,IAAI,GAC/C,YAAY,CAAC;QAEhB;;;;;WAKG;QACH,sBAAsB,CACpB,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,CAAC,IAAI,EAAE,mBAAmB,KAAK,IAAI,GAC5C,YAAY,CAAC;KACjB,CAAC;IAEF;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB"}
|
package/dist/types.js
ADDED
|
File without changes
|
|
@@ -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;
|
package/jest.config.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { Config } from '@jest/types';
|
|
3
|
+
|
|
4
|
+
const config: Config.InitialOptions = {
|
|
5
|
+
globals: {
|
|
6
|
+
'ts-jest': {
|
|
7
|
+
tsconfig: path.resolve(__dirname, 'tsconfig.json'),
|
|
8
|
+
isolatedModules: true,
|
|
9
|
+
},
|
|
10
|
+
},
|
|
11
|
+
|
|
12
|
+
preset: 'ts-jest',
|
|
13
|
+
testEnvironment: 'jsdom',
|
|
14
|
+
testMatch: ['<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}'],
|
|
15
|
+
|
|
16
|
+
watchPlugins: [
|
|
17
|
+
'jest-watch-typeahead/filename',
|
|
18
|
+
'jest-watch-typeahead/testname',
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export default config;
|
package/package.json
CHANGED
|
@@ -1,34 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sigmacomputing/plugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Plugin
|
|
3
|
+
"version": "1.0.0-rc.2",
|
|
4
|
+
"description": "Sigma Computing Plugin Client API",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"homepage": "https://github.com/sigmacomputing/plugin",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/sigmacomputing/plugin.git"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"email": "support@sigmacomputing.com",
|
|
13
|
+
"url": "https://github.com/sigmacomputing/plugin/issues"
|
|
14
|
+
},
|
|
5
15
|
"module": "./src/index.ts",
|
|
6
16
|
"main": "./dist/index.js",
|
|
7
17
|
"types": "./dist/index.d.ts",
|
|
8
18
|
"files": [
|
|
9
|
-
"/dist"
|
|
19
|
+
"/dist",
|
|
20
|
+
"/src",
|
|
21
|
+
"!/src/**/__tests__/**"
|
|
10
22
|
],
|
|
23
|
+
"exports": {
|
|
24
|
+
".": "./dist/index.js",
|
|
25
|
+
"./react": "./dist/client/react/index.js",
|
|
26
|
+
"./package.json": "./package.json"
|
|
27
|
+
},
|
|
28
|
+
"typesVersions": {
|
|
29
|
+
"*": {
|
|
30
|
+
"react": [
|
|
31
|
+
"dist/client/react/index.d.ts"
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
11
35
|
"scripts": {
|
|
12
36
|
"clean": "rimraf dist tsconfig*.tsbuildinfo",
|
|
13
37
|
"build": "yarn clean && yarn tsc",
|
|
14
38
|
"build:watch": "yarn build --watch",
|
|
15
|
-
"format": "prettier --write 'src/**/*.ts' 'jest.config.ts'
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"prepublish": "yarn clean && tsc --build tsconfig.publish.json",
|
|
20
|
-
"test": "cd ../.. && jest --ci --selectProjects @sigmacomputing/plugin",
|
|
39
|
+
"format": "prettier --write 'src/**/*.{ts,tsx}' 'jest.config.ts'",
|
|
40
|
+
"precommit": "lint-staged",
|
|
41
|
+
"prepublish": "yarn build",
|
|
42
|
+
"test": "jest --ci",
|
|
21
43
|
"test:watch": "yarn test --watch",
|
|
22
|
-
"tsc": "
|
|
23
|
-
},
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"@sigmacomputing/plugin-types": "^0.7.57"
|
|
26
|
-
},
|
|
27
|
-
"devDependencies": {
|
|
28
|
-
"@jest/types": "^27.5.1"
|
|
44
|
+
"tsc": "ttsc --build tsconfig.build.json"
|
|
29
45
|
},
|
|
30
46
|
"peerDependencies": {
|
|
31
47
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
32
48
|
},
|
|
33
|
-
"
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@jest/types": "^27.5.1",
|
|
51
|
+
"@types/jest": "^27.5.1",
|
|
52
|
+
"@types/node": "^18.7.14",
|
|
53
|
+
"@types/react": "^18.0.18",
|
|
54
|
+
"@types/react-dom": "^18.0.6",
|
|
55
|
+
"jest": "^27.5.1",
|
|
56
|
+
"jest-watch-typeahead": "^2.1.1",
|
|
57
|
+
"lint-staged": "^13.0.3",
|
|
58
|
+
"prettier": "^2.7.1",
|
|
59
|
+
"react": "^18.2.0",
|
|
60
|
+
"react-dom": "^18.2.0",
|
|
61
|
+
"ts-jest": "^27.1.4",
|
|
62
|
+
"ts-node": "^10.9.1",
|
|
63
|
+
"ttypescript": "^1.5.13",
|
|
64
|
+
"typescript": "^4.8.2",
|
|
65
|
+
"typescript-transform-paths": "^3.3.1"
|
|
66
|
+
}
|
|
34
67
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { initialize } from '../initialize';
|
|
2
|
+
|
|
3
|
+
describe('initialize', () => {
|
|
4
|
+
let originalAddEventListener: any;
|
|
5
|
+
let originalRemoveEventListener: any;
|
|
6
|
+
|
|
7
|
+
beforeAll(() => {
|
|
8
|
+
originalAddEventListener = window.addEventListener;
|
|
9
|
+
originalRemoveEventListener = window.removeEventListener;
|
|
10
|
+
window.addEventListener = jest.fn();
|
|
11
|
+
window.removeEventListener = jest.fn();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
jest.resetAllMocks();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should initialize and be destroyable', () => {
|
|
19
|
+
const client = initialize();
|
|
20
|
+
expect(window.addEventListener).toHaveBeenCalled();
|
|
21
|
+
|
|
22
|
+
client.destroy();
|
|
23
|
+
expect(window.removeEventListener).toHaveBeenCalled();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterAll(() => {
|
|
27
|
+
window.addEventListener = originalAddEventListener;
|
|
28
|
+
window.removeEventListener = originalRemoveEventListener;
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import {
|
|
2
|
+
PluginConfig,
|
|
3
|
+
PluginInstance,
|
|
4
|
+
PluginMessageResponse,
|
|
5
|
+
WorkbookSelection,
|
|
6
|
+
WorkbookVariable,
|
|
7
|
+
Unsubscriber,
|
|
8
|
+
} from 'types';
|
|
9
|
+
|
|
10
|
+
export function initialize<T = {}>(): PluginInstance<T> {
|
|
11
|
+
const pluginConfig: Partial<PluginConfig<T>> = {
|
|
12
|
+
config: {} as T,
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
let subscribedInteractions: Record<string, WorkbookSelection[]> = {};
|
|
16
|
+
let subscribedWorkbookVars: Record<string, WorkbookVariable> = {};
|
|
17
|
+
|
|
18
|
+
const listeners: {
|
|
19
|
+
[event: string]: Function[];
|
|
20
|
+
} = {};
|
|
21
|
+
|
|
22
|
+
for (const [key, value] of new URL(
|
|
23
|
+
document.location.toString(),
|
|
24
|
+
).searchParams.entries())
|
|
25
|
+
pluginConfig[key] = JSON.parse(value);
|
|
26
|
+
|
|
27
|
+
const listener = (e: PluginMessageResponse) => {
|
|
28
|
+
emit(e.data.type, e.data.result, e.data.error);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
window.addEventListener('message', listener, false);
|
|
32
|
+
window.addEventListener('click', () => execPromise('wb:plugin:focus'));
|
|
33
|
+
|
|
34
|
+
on('wb:plugin:config:update', (config: PluginConfig<T>) => {
|
|
35
|
+
Object.assign(pluginConfig, config);
|
|
36
|
+
emit('config', pluginConfig.config ?? {});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
// send initialize event
|
|
40
|
+
void execPromise(
|
|
41
|
+
'wb:plugin:init',
|
|
42
|
+
require('../../package.json').version,
|
|
43
|
+
).then(config => {
|
|
44
|
+
Object.assign(pluginConfig, config);
|
|
45
|
+
emit('init', pluginConfig);
|
|
46
|
+
emit('config', pluginConfig.config);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
on(
|
|
50
|
+
'wb:plugin:variable:update',
|
|
51
|
+
(updatedVariables: Record<string, WorkbookVariable>) => {
|
|
52
|
+
subscribedWorkbookVars = {};
|
|
53
|
+
Object.assign(subscribedWorkbookVars, updatedVariables);
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
on('wb:plugin:selection:update', (updatedInteractions: unknown) => {
|
|
58
|
+
subscribedInteractions = {};
|
|
59
|
+
Object.assign(subscribedInteractions, updatedInteractions);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
function on(event: string, listener: Function) {
|
|
63
|
+
listeners[event] = listeners[event] || [];
|
|
64
|
+
listeners[event].push(listener);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function off(event: string, listener: Function) {
|
|
68
|
+
if (listeners[event] == null) return;
|
|
69
|
+
listeners[event] = listeners[event].filter(a => a !== listener);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function emit(event: string, ...args: any) {
|
|
73
|
+
Object.values(listeners[event] || []).forEach(fn => fn(...args));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function execPromise<R>(event: string, ...args: any): Promise<R> {
|
|
77
|
+
return new Promise((resolve, reject) => {
|
|
78
|
+
const callback = (data: R, error: any) => {
|
|
79
|
+
if (error) reject(error);
|
|
80
|
+
else resolve(data);
|
|
81
|
+
off(event, callback);
|
|
82
|
+
};
|
|
83
|
+
on(event, callback);
|
|
84
|
+
window.parent.postMessage(
|
|
85
|
+
{ type: event, args, elementId: pluginConfig.id },
|
|
86
|
+
pluginConfig?.wbOrigin ?? '*',
|
|
87
|
+
);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
get sigmaEnv() {
|
|
93
|
+
return pluginConfig.sigmaEnv;
|
|
94
|
+
},
|
|
95
|
+
|
|
96
|
+
get isScreenshot() {
|
|
97
|
+
return pluginConfig.screenshot;
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
config: {
|
|
101
|
+
// @ts-ignore
|
|
102
|
+
getKey(key) {
|
|
103
|
+
return pluginConfig?.config?.[key]!;
|
|
104
|
+
},
|
|
105
|
+
get() {
|
|
106
|
+
return pluginConfig.config;
|
|
107
|
+
},
|
|
108
|
+
set(partialConfig) {
|
|
109
|
+
void execPromise('wb:plugin:config:update', partialConfig);
|
|
110
|
+
},
|
|
111
|
+
setKey(key, value) {
|
|
112
|
+
void execPromise('wb:plugin:config:update', {
|
|
113
|
+
[key]: value,
|
|
114
|
+
});
|
|
115
|
+
},
|
|
116
|
+
subscribe(listener) {
|
|
117
|
+
on('config', listener);
|
|
118
|
+
return () => off('config', listener);
|
|
119
|
+
},
|
|
120
|
+
getVariable(id: string): WorkbookVariable {
|
|
121
|
+
return subscribedWorkbookVars[id];
|
|
122
|
+
},
|
|
123
|
+
setVariable(id: string, ...values: unknown[]) {
|
|
124
|
+
void execPromise('wb:plugin:variable:set', id, ...values);
|
|
125
|
+
},
|
|
126
|
+
getInteraction(id: string) {
|
|
127
|
+
return subscribedInteractions[id];
|
|
128
|
+
},
|
|
129
|
+
setInteraction(
|
|
130
|
+
id: string,
|
|
131
|
+
elementId: string,
|
|
132
|
+
selection:
|
|
133
|
+
| string[]
|
|
134
|
+
| Array<Record<string, { type: string; val?: unknown }>>,
|
|
135
|
+
) {
|
|
136
|
+
void execPromise('wb:plugin:selection:set', id, elementId, selection);
|
|
137
|
+
},
|
|
138
|
+
configureEditorPanel(options) {
|
|
139
|
+
void execPromise('wb:plugin:config:inspector', options);
|
|
140
|
+
},
|
|
141
|
+
setLoadingState(loadingState) {
|
|
142
|
+
void execPromise('wb:plugin:config:loading-state', loadingState);
|
|
143
|
+
},
|
|
144
|
+
subscribeToWorkbookVariable(
|
|
145
|
+
id: string,
|
|
146
|
+
callback: (input: WorkbookVariable) => void,
|
|
147
|
+
): Unsubscriber {
|
|
148
|
+
const setValues = (values: Record<string, WorkbookVariable>) => {
|
|
149
|
+
callback(values[id]);
|
|
150
|
+
};
|
|
151
|
+
on('wb:plugin:variable:update', setValues);
|
|
152
|
+
return () => {
|
|
153
|
+
off('wb:plugin:variable:update', setValues);
|
|
154
|
+
};
|
|
155
|
+
},
|
|
156
|
+
subscribeToWorkbookInteraction(
|
|
157
|
+
id: string,
|
|
158
|
+
callback: (input: WorkbookSelection[]) => void,
|
|
159
|
+
): Unsubscriber {
|
|
160
|
+
const setValues = (values: Record<string, WorkbookSelection[]>) => {
|
|
161
|
+
callback(values[id]);
|
|
162
|
+
};
|
|
163
|
+
on('wb:plugin:selection:update', setValues);
|
|
164
|
+
return () => {
|
|
165
|
+
off('wb:plugin:selection:update', setValues);
|
|
166
|
+
};
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
elements: {
|
|
170
|
+
getElementColumns(id) {
|
|
171
|
+
return execPromise('wb:plugin:element:columns:get', id);
|
|
172
|
+
},
|
|
173
|
+
subscribeToElementColumns(id, callback) {
|
|
174
|
+
const eventName = `wb:plugin:element:${id}:columns`;
|
|
175
|
+
on(eventName, callback);
|
|
176
|
+
void execPromise('wb:plugin:element:subscribe:columns', id);
|
|
177
|
+
|
|
178
|
+
return () => {
|
|
179
|
+
off(eventName, callback);
|
|
180
|
+
void execPromise('wb:plugin:element:unsubscribe:columns', id);
|
|
181
|
+
};
|
|
182
|
+
},
|
|
183
|
+
subscribeToElementData(id, callback) {
|
|
184
|
+
const eventName = `wb:plugin:element:${id}:data`;
|
|
185
|
+
on(eventName, callback);
|
|
186
|
+
void execPromise('wb:plugin:element:subscribe:data', id);
|
|
187
|
+
|
|
188
|
+
return () => {
|
|
189
|
+
off(eventName, callback);
|
|
190
|
+
void execPromise('wb:plugin:element:unsubscribe:data', id);
|
|
191
|
+
};
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
destroy() {
|
|
195
|
+
Object.keys(listeners).forEach(event => delete listeners[event]);
|
|
196
|
+
window.removeEventListener('message', listener, false);
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import { PluginContext } from 'client/react/Context';
|
|
4
|
+
import { PluginInstance } from 'types';
|
|
5
|
+
|
|
6
|
+
export interface SigmaClientProviderProps<T = any> {
|
|
7
|
+
client: PluginInstance<T>;
|
|
8
|
+
children?: ReactNode;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function SigmaClientProvider<T = any>(
|
|
12
|
+
props: SigmaClientProviderProps<T>,
|
|
13
|
+
) {
|
|
14
|
+
return (
|
|
15
|
+
<PluginContext.Provider value={props.client}>
|
|
16
|
+
{props.children}
|
|
17
|
+
</PluginContext.Provider>
|
|
18
|
+
);
|
|
19
|
+
}
|