@sigmacomputing/plugin 0.7.40 → 0.7.45

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.
@@ -1 +1 @@
1
- {"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../src/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,8BAA8B,CAAC;AAEvD,wBAAgB,UAAU,CAAC,CAAC,GAAG,EAAE,KAAK,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAgK7D"}
1
+ {"version":3,"file":"initialize.d.ts","sourceRoot":"","sources":["../src/initialize.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,8BAA8B,CAAC;AAEvD,wBAAgB,UAAU,CAAC,CAAC,GAAG,EAAE,KAAK,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAiK7D"}
@@ -88,11 +88,11 @@ function initialize() {
88
88
  on('config', listener);
89
89
  return () => off('config', listener);
90
90
  },
91
- getVariable(name) {
92
- return subscribedWorkbookVars[name];
91
+ getVariable(id) {
92
+ return subscribedWorkbookVars[id];
93
93
  },
94
- setVariable(name, ...values) {
95
- void execPromise('wb:plugin:variable:set', name, ...values);
94
+ setVariable(id, ...values) {
95
+ void execPromise('wb:plugin:variable:set', id, ...values);
96
96
  },
97
97
  configureEditorPanel(options) {
98
98
  void execPromise('wb:plugin:config:inspector', options);
@@ -100,8 +100,10 @@ function initialize() {
100
100
  setLoadingState(loadingState) {
101
101
  void execPromise('wb:plugin:config:loading-state', loadingState);
102
102
  },
103
- subscribeToWorkbookVariable(name, callback) {
104
- const setValues = (values) => callback(values[name]);
103
+ subscribeToWorkbookVariable(id, callback) {
104
+ const setValues = (values) => {
105
+ callback(values[id]);
106
+ };
105
107
  on('wb:plugin:variable:update', setValues);
106
108
  return () => {
107
109
  off('wb:plugin:variable:update', setValues);
@@ -45,8 +45,8 @@ export declare function useElementData(id: string): plugin.WbElementData;
45
45
  export declare function useConfig(key?: string): any;
46
46
  /**
47
47
  * React hook for accessing a workbook variable
48
- * @param {string} name Name of variable within Plugin Config Options to use
48
+ * @param {string} id ID of variable within Plugin Config to use
49
49
  * @returns {[(plugin.WorkbookVariable | undefined), Function]} Constantly updating value of the variable and setter for the variable
50
50
  */
51
- export declare function useVariable(name: string): [plugin.WorkbookVariable | undefined, Function];
51
+ export declare function useVariable(id: string): [plugin.WorkbookVariable | undefined, Function];
52
52
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,MAAM,MAAM,8BAA8B,CAAC;AAOvD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IACzC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IACnC,QAAQ,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAChC,eAIA;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAEtD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,CAAC,yBAAyB,EAAE,GAC9C,IAAI,CAUN;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,OAAO,GACpB,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC,CAczC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,gBAAgB,CASrE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,aAAa,CAO/D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAiB3C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,GACX,CAAC,MAAM,CAAC,gBAAgB,GAAG,SAAS,EAAE,QAAQ,CAAC,CAcjD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAON,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,MAAM,MAAM,8BAA8B,CAAC;AAOvD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE;IACzC,MAAM,EAAE,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IACnC,QAAQ,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC;CAChC,eAIA;AAED;;;GAGG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,CAEtD;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,WAAW,EAAE,MAAM,CAAC,yBAAyB,EAAE,GAC9C,IAAI,CAUN;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAC7B,YAAY,EAAE,OAAO,GACpB,CAAC,OAAO,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC,CAczC;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,gBAAgB,CASrE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAAC,aAAa,CAO/D;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,CAiB3C;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,EAAE,EAAE,MAAM,GACT,CAAC,MAAM,CAAC,gBAAgB,GAAG,SAAS,EAAE,QAAQ,CAAC,CAcjD"}
@@ -137,18 +137,18 @@ function useConfig(key) {
137
137
  exports.useConfig = useConfig;
138
138
  /**
139
139
  * React hook for accessing a workbook variable
140
- * @param {string} name Name of variable within Plugin Config Options to use
140
+ * @param {string} id ID of variable within Plugin Config to use
141
141
  * @returns {[(plugin.WorkbookVariable | undefined), Function]} Constantly updating value of the variable and setter for the variable
142
142
  */
143
- function useVariable(name) {
143
+ function useVariable(id) {
144
144
  const client = usePlugin();
145
145
  const [workbookVariable, setWorkbookVariable] = (0, react_1.useState)();
146
146
  (0, react_1.useEffect)(() => {
147
- return client.config.subscribeToWorkbookVariable(name, setWorkbookVariable);
148
- }, [client, name]);
147
+ return client.config.subscribeToWorkbookVariable(id, setWorkbookVariable);
148
+ }, [client, id]);
149
149
  return [
150
150
  workbookVariable,
151
- react_1.default.useCallback((...values) => client.config.setVariable(name, ...values), [name]),
151
+ react_1.default.useCallback((...values) => client.config.setVariable(id, ...values), [id]),
152
152
  ];
153
153
  }
154
154
  exports.useVariable = useVariable;
package/package.json CHANGED
@@ -1,27 +1,33 @@
1
1
  {
2
2
  "name": "@sigmacomputing/plugin",
3
- "version": "0.7.40",
3
+ "version": "0.7.45",
4
4
  "description": "Plugin client api",
5
5
  "module": "./src/index.ts",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
+ "files": [
9
+ "/dist",
10
+ "/src",
11
+ "!/src/**/__tests__/**"
12
+ ],
8
13
  "scripts": {
9
- "clean": "rimraf dist tsconfig.tsbuildinfo",
10
- "build": "yarn run clean && tsc --build",
11
- "build:watch": "yarn run build --watch",
14
+ "clean": "rimraf dist tsconfig*.tsbuildinfo",
15
+ "build": "yarn clean && yarn tsc",
16
+ "build:watch": "yarn build --watch",
12
17
  "format": "prettier --write 'src/**/*.ts' 'jest.config.js' '.eslintrc.js'",
13
18
  "lint": "eslint --cache src jest.config.js .eslintrc.js",
14
19
  "lint:clean": "rimraf .eslintcache",
15
20
  "lint:fix": "yarn lint --fix",
21
+ "prepublish": "yarn build",
16
22
  "test": "cd ../.. && jest --ci --selectProjects @sigmacomputing/plugin",
17
23
  "test:watch": "yarn test --watch",
18
- "prepublish": "yarn run build"
24
+ "tsc": "tsc --build tsconfig.build.json"
19
25
  },
20
26
  "dependencies": {
21
- "@sigmacomputing/plugin-types": "^0.7.40"
27
+ "@sigmacomputing/plugin-types": "^0.7.45"
22
28
  },
23
29
  "peerDependencies": {
24
30
  "react": "^16.8.0 || ^17.0.0 | ^18.0.0"
25
31
  },
26
- "gitHead": "2145b33a44866c1d3b1520ccdc11ad42f09baaa2"
32
+ "gitHead": "c32a8950b88a2f0e106055b65157cc6b3b62a247"
27
33
  }
package/src/client.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { initialize } from './initialize';
2
+
3
+ export const client = initialize();
@@ -0,0 +1,42 @@
1
+ // Deep Equality comparison example
2
+ //
3
+ // This is an example of how to implement an object-comparison function in
4
+ // JavaScript (ES5+). A few points of interest here:
5
+ //
6
+ // * You can get an array of all an object's properties in ES5+ by calling
7
+ // the class method Object.keys(obj).
8
+ // * The function recursively calls itself in the for / in loop when it
9
+ // compares the contents of each property
10
+ // * You can hide a "private" function inside a function of this kind by
11
+ // placing one function declaration inside of another. The inner function
12
+ // is not hoisted out into the global scope, so it is only visible inside
13
+ // of the parent function.
14
+ // * The reason this nested helper function is necessary is that
15
+ // `typeof null` is still "object" in JS, a major "gotcha" to watch out for.
16
+ //
17
+ // https://gist.github.com/egardner/efd34f270cc33db67c0246e837689cb9
18
+
19
+ export function deepEqual(obj1: any, obj2: any) {
20
+ if (obj1 === obj2) {
21
+ return true;
22
+ } else if (isObject(obj1) && isObject(obj2)) {
23
+ if (Object.keys(obj1).length !== Object.keys(obj2).length) {
24
+ return false;
25
+ }
26
+ for (const prop in obj1) {
27
+ if (!deepEqual(obj1[prop], obj2[prop])) {
28
+ return false;
29
+ }
30
+ }
31
+ return true;
32
+ }
33
+
34
+ // Private
35
+ function isObject(obj: any) {
36
+ if (typeof obj === 'object' && obj != null) {
37
+ return true;
38
+ } else {
39
+ return false;
40
+ }
41
+ }
42
+ }
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ export { initialize } from './initialize';
2
+ export { client } from './client';
3
+ /* Ideally we want this to be tree-shakeable.
4
+ * Node 12 added support for `exports` in package.json,
5
+ * however typescript does not yet support this.
6
+ * Tracked: https://github.com/microsoft/TypeScript/issues/33079
7
+ */
8
+ export * from './react';
@@ -0,0 +1,28 @@
1
+ import { initialize } from './initialize';
2
+
3
+ describe('initialize', () => {
4
+ let originalAddEventListener: any;
5
+ let originalRemoveEventListener: any;
6
+ beforeAll(() => {
7
+ originalAddEventListener = window.addEventListener;
8
+ originalRemoveEventListener = window.removeEventListener;
9
+ window.addEventListener = jest.fn();
10
+ window.removeEventListener = jest.fn();
11
+ });
12
+
13
+ beforeEach(() => {
14
+ jest.resetAllMocks();
15
+ });
16
+ test('should initialize and be destroyable', () => {
17
+ const client = initialize();
18
+ expect(window.addEventListener).toHaveBeenCalled();
19
+
20
+ client.destroy();
21
+ expect(window.removeEventListener).toHaveBeenCalled();
22
+ });
23
+
24
+ afterAll(() => {
25
+ window.addEventListener = originalAddEventListener;
26
+ window.removeEventListener = originalRemoveEventListener;
27
+ });
28
+ });
@@ -0,0 +1,164 @@
1
+ import * as plugin from '@sigmacomputing/plugin-types';
2
+
3
+ export function initialize<T = {}>(): plugin.PluginInstance<T> {
4
+ const pluginConfig: Partial<plugin.PluginConfig<T>> = {
5
+ config: {} as T,
6
+ };
7
+ let subscribedInteractions: Record<string, unknown> = {};
8
+ let subscribedWorkbookVars: Record<string, plugin.WorkbookVariable> = {};
9
+
10
+ const listeners: {
11
+ [event: string]: Function[];
12
+ } = {};
13
+
14
+ for (const [key, value] of new URL(
15
+ document.location.toString(),
16
+ ).searchParams.entries())
17
+ pluginConfig[key] = JSON.parse(value);
18
+
19
+ const listener = (e: plugin.PluginMessageResponse) => {
20
+ emit(e.data.type, e.data.result, e.data.error);
21
+ };
22
+
23
+ window.addEventListener('message', listener, false);
24
+ window.addEventListener('click', () => execPromise('wb:plugin:focus'));
25
+
26
+ on('wb:plugin:config:update', (config: plugin.PluginConfig<T>) => {
27
+ Object.assign(pluginConfig, config);
28
+ emit('config', pluginConfig.config ?? {});
29
+ });
30
+
31
+ // send initialize event
32
+ void execPromise('wb:plugin:init', require('../package.json').version).then(
33
+ config => {
34
+ Object.assign(pluginConfig, config);
35
+ emit('init', pluginConfig);
36
+ emit('config', pluginConfig.config);
37
+ },
38
+ );
39
+
40
+ on(
41
+ 'wb:plugin:variable:update',
42
+ (updatedVariables: Record<string, plugin.WorkbookVariable>) => {
43
+ subscribedWorkbookVars = {};
44
+ Object.assign(subscribedWorkbookVars, updatedVariables);
45
+ },
46
+ );
47
+
48
+ on('wb:plugin:interaction:update', (updatedInteractions: unknown) => {
49
+ subscribedInteractions = {};
50
+ Object.assign(subscribedInteractions, updatedInteractions);
51
+ });
52
+
53
+ function on(event: string, listener: Function) {
54
+ listeners[event] = listeners[event] || [];
55
+ listeners[event].push(listener);
56
+ }
57
+
58
+ function off(event: string, listener: Function) {
59
+ if (listeners[event] == null) return;
60
+ listeners[event] = listeners[event].filter(a => a !== listener);
61
+ }
62
+
63
+ function emit(event: string, ...args: any) {
64
+ Object.values(listeners[event] || []).forEach(fn => fn(...args));
65
+ }
66
+
67
+ function execPromise<R>(event: string, ...args: any): Promise<R> {
68
+ return new Promise((resolve, reject) => {
69
+ const callback = (data: R, error: any) => {
70
+ if (error) reject(error);
71
+ else resolve(data);
72
+ off(event, callback);
73
+ };
74
+ on(event, callback);
75
+ window.parent.postMessage(
76
+ { type: event, args, elementId: pluginConfig.id },
77
+ pluginConfig?.wbOrigin ?? '*',
78
+ );
79
+ });
80
+ }
81
+
82
+ return {
83
+ get sigmaEnv() {
84
+ return pluginConfig.sigmaEnv;
85
+ },
86
+ get isScreenshot() {
87
+ return pluginConfig.screenshot;
88
+ },
89
+ config: {
90
+ // @ts-ignore
91
+ getKey(key) {
92
+ return pluginConfig?.config?.[key]!;
93
+ },
94
+ get() {
95
+ return pluginConfig.config;
96
+ },
97
+ set(partialConfig) {
98
+ void execPromise('wb:plugin:config:update', partialConfig);
99
+ },
100
+ setKey(key, value) {
101
+ void execPromise('wb:plugin:config:update', {
102
+ [key]: value,
103
+ });
104
+ },
105
+ subscribe(listener) {
106
+ on('config', listener);
107
+ return () => off('config', listener);
108
+ },
109
+ getVariable(id: string): plugin.WorkbookVariable {
110
+ return subscribedWorkbookVars[id];
111
+ },
112
+ setVariable(id: string, ...values: unknown[]) {
113
+ void execPromise('wb:plugin:variable:set', id, ...values);
114
+ },
115
+ configureEditorPanel(options) {
116
+ void execPromise('wb:plugin:config:inspector', options);
117
+ },
118
+ setLoadingState(loadingState) {
119
+ void execPromise('wb:plugin:config:loading-state', loadingState);
120
+ },
121
+ subscribeToWorkbookVariable(
122
+ id: string,
123
+ callback: (input: plugin.WorkbookVariable) => void,
124
+ ): plugin.Unsubscriber {
125
+ const setValues = (values: Record<string, plugin.WorkbookVariable>) => {
126
+ callback(values[id]);
127
+ };
128
+ on('wb:plugin:variable:update', setValues);
129
+ return () => {
130
+ off('wb:plugin:variable:update', setValues);
131
+ };
132
+ },
133
+ },
134
+ elements: {
135
+ getElementColumns(id) {
136
+ return execPromise('wb:plugin:element:columns:get', id);
137
+ },
138
+ subscribeToElementColumns(id, callback) {
139
+ const eventName = `wb:plugin:element:${id}:columns`;
140
+ on(eventName, callback);
141
+ void execPromise('wb:plugin:element:subscribe:columns', id);
142
+
143
+ return () => {
144
+ off(eventName, callback);
145
+ void execPromise('wb:plugin:element:unsubscribe:columns', id);
146
+ };
147
+ },
148
+ subscribeToElementData(id, callback) {
149
+ const eventName = `wb:plugin:element:${id}:data`;
150
+ on(eventName, callback);
151
+ void execPromise('wb:plugin:element:subscribe:data', id);
152
+
153
+ return () => {
154
+ off(eventName, callback);
155
+ void execPromise('wb:plugin:element:unsubscribe:data', id);
156
+ };
157
+ },
158
+ },
159
+ destroy: function () {
160
+ Object.keys(listeners).forEach(event => delete listeners[event]);
161
+ window.removeEventListener('message', listener, false);
162
+ },
163
+ };
164
+ }
@@ -0,0 +1,154 @@
1
+ import React, {
2
+ Context,
3
+ createContext,
4
+ useContext,
5
+ useEffect,
6
+ useRef,
7
+ useState,
8
+ } from 'react';
9
+ import * as plugin from '@sigmacomputing/plugin-types';
10
+
11
+ import { deepEqual } from '../deepEqual';
12
+ import { client } from '../client';
13
+
14
+ const Context = createContext<plugin.PluginInstance<any>>(client);
15
+
16
+ /**
17
+ * Wrapper for plugin client using a Provider
18
+ * @param {{client: plugin.PluginInstance, children: React.ReachChildren}} props Plugin instance and any children elements
19
+ * @returns {JSXElement} Context Provider for passed in props
20
+ */
21
+ export function SigmaClientProvider(props: {
22
+ client: plugin.PluginInstance<any>;
23
+ children?: React.ReactChildren;
24
+ }) {
25
+ return (
26
+ <Context.Provider value={props.client}>{props.children}</Context.Provider>
27
+ );
28
+ }
29
+
30
+ /**
31
+ * A constantly updating getter for the entire Plugin Instance
32
+ * @returns {plugin.PluginInstance} Context for the current plugin instance
33
+ */
34
+ export function usePlugin(): plugin.PluginInstance<any> {
35
+ return useContext(Context);
36
+ }
37
+
38
+ /**
39
+ * Provides a setter for the Plugin's Config Options
40
+ * @param {plugin.CustomPluginConfigOptions[]} nextOptions Updated possible Config Options
41
+ */
42
+ export function useEditorPanelConfig(
43
+ nextOptions: plugin.CustomPluginConfigOptions[],
44
+ ): void {
45
+ const client = usePlugin();
46
+ const optionsRef = useRef({});
47
+ useEffect(() => {
48
+ if (nextOptions == null) return;
49
+ if (!deepEqual(nextOptions, optionsRef.current)) {
50
+ client.config.configureEditorPanel(nextOptions);
51
+ optionsRef.current = nextOptions;
52
+ }
53
+ }, [client, nextOptions]);
54
+ }
55
+
56
+ /**
57
+ * React hook for Plugin Config loading state
58
+ * @param {boolean} initialState Initial value to set loading state to
59
+ * @returns {[boolean, Function]} Boolean value corresponding to loading state for plugin config and setter for loading state
60
+ */
61
+ export function useLoadingState(
62
+ initialState: boolean,
63
+ ): [boolean, (nextState: boolean) => void] {
64
+ const client = usePlugin();
65
+ const [loading, setLoading] = useState(() => {
66
+ client.config.setLoadingState(initialState);
67
+ return initialState;
68
+ });
69
+ return [
70
+ loading,
71
+ nextState => {
72
+ if (nextState === loading) return;
73
+ setLoading(nextState);
74
+ client.config.setLoadingState(nextState);
75
+ },
76
+ ];
77
+ }
78
+
79
+ /**
80
+ * Provides constantly updating column values from corresponding sheet
81
+ * @param {string} id Sheet ID to retrieve from workbook
82
+ * @returns {plugin.WbElementColumns} Values of corresponding columns contained within the sheet
83
+ */
84
+ export function useElementColumns(id: string): plugin.WbElementColumns {
85
+ const client = usePlugin();
86
+ const [columns, setColumns] = useState<plugin.WbElementColumns>({});
87
+ useEffect(() => {
88
+ if (id) {
89
+ return client.elements.subscribeToElementColumns(id, setColumns);
90
+ }
91
+ }, [client, id]);
92
+ return columns;
93
+ }
94
+
95
+ /**
96
+ * Provides constantly updating data values from corresponding sheet
97
+ * @param {string} id Sheet ID to get element data from
98
+ * @returns {plugin.WbElementData} Element Data for corresponding sheet, if any
99
+ */
100
+ export function useElementData(id: string): plugin.WbElementData {
101
+ const client = usePlugin();
102
+ const [data, setData] = useState<plugin.WbElementData>({});
103
+ useEffect(() => {
104
+ if (id) return client.elements.subscribeToElementData(id, setData);
105
+ }, [client, id]);
106
+ return data;
107
+ }
108
+
109
+ /**
110
+ * Provides a constantly updating value for entire config or certain key within config
111
+ * @param {string} key Key within Plugin Config, optional
112
+ * @returns Entire config if no key passed in or value for key within plugin config
113
+ */
114
+ export function useConfig(key?: string): any {
115
+ const client = usePlugin();
116
+ const [config, setConfig] = useState<any>(
117
+ key != null ? client.config.getKey(key) : client.config.get(),
118
+ );
119
+ useEffect(
120
+ () =>
121
+ client.config.subscribe(newConfig => {
122
+ if (key != null && newConfig[key] !== config[key]) {
123
+ setConfig(newConfig[key]);
124
+ } else {
125
+ setConfig(newConfig);
126
+ }
127
+ }),
128
+ [client],
129
+ );
130
+ return config;
131
+ }
132
+
133
+ /**
134
+ * React hook for accessing a workbook variable
135
+ * @param {string} id ID of variable within Plugin Config to use
136
+ * @returns {[(plugin.WorkbookVariable | undefined), Function]} Constantly updating value of the variable and setter for the variable
137
+ */
138
+ export function useVariable(
139
+ id: string,
140
+ ): [plugin.WorkbookVariable | undefined, Function] {
141
+ const client = usePlugin();
142
+ const [workbookVariable, setWorkbookVariable] =
143
+ useState<plugin.WorkbookVariable>();
144
+ useEffect(() => {
145
+ return client.config.subscribeToWorkbookVariable(id, setWorkbookVariable);
146
+ }, [client, id]);
147
+ return [
148
+ workbookVariable,
149
+ React.useCallback(
150
+ (...values: unknown[]) => client.config.setVariable(id, ...values),
151
+ [id],
152
+ ),
153
+ ];
154
+ }
package/.eslintcache DELETED
@@ -1 +0,0 @@
1
- [{"/Users/xiaoyu/sigma/slate/packages/plugin/src/client.ts":"1","/Users/xiaoyu/sigma/slate/packages/plugin/src/index.ts":"2","/Users/xiaoyu/sigma/slate/packages/plugin/src/initialize.test.ts":"3","/Users/xiaoyu/sigma/slate/packages/plugin/src/initialize.ts":"4","/Users/xiaoyu/sigma/slate/packages/plugin/src/react/index.tsx":"5","/Users/xiaoyu/sigma/slate/packages/plugin/jest.config.js":"6","/Users/xiaoyu/sigma/slate/packages/plugin/.eslintrc.js":"7"},{"size":80,"mtime":1649717551898,"results":"8","hashOfConfig":"9"},{"size":323,"mtime":1649717551900,"results":"10","hashOfConfig":"9"},{"size":815,"mtime":1634060358370,"results":"11","hashOfConfig":"9"},{"size":3698,"mtime":1651009692945,"results":"12","hashOfConfig":"9"},{"size":1633,"mtime":1651773240873,"results":"13","hashOfConfig":"9"},{"size":71,"mtime":1650050561442,"results":"14","hashOfConfig":"9"},{"size":181,"mtime":1651189769339,"results":"15","hashOfConfig":"9"},{"filePath":"16","messages":"17","suppressedMessages":"18","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"11yml40",{"filePath":"19","messages":"20","suppressedMessages":"21","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"22","messages":"23","suppressedMessages":"24","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"25","messages":"26","suppressedMessages":"27","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"28","messages":"29","suppressedMessages":"30","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"31","messages":"32","suppressedMessages":"33","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},{"filePath":"34","messages":"35","suppressedMessages":"36","errorCount":0,"fatalErrorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"/Users/xiaoyu/sigma/slate/packages/plugin/src/client.ts",[],[],"/Users/xiaoyu/sigma/slate/packages/plugin/src/index.ts",[],[],"/Users/xiaoyu/sigma/slate/packages/plugin/src/initialize.test.ts",[],[],"/Users/xiaoyu/sigma/slate/packages/plugin/src/initialize.ts",[],[],"/Users/xiaoyu/sigma/slate/packages/plugin/src/react/index.tsx",[],[],"/Users/xiaoyu/sigma/slate/packages/plugin/jest.config.js",[],[],"/Users/xiaoyu/sigma/slate/packages/plugin/.eslintrc.js",[],[]]
package/.eslintrc.js DELETED
@@ -1,6 +0,0 @@
1
- // @ts-ignore - file exists outside of package structure
2
- const { overrides } = require('../../config/eslint');
3
-
4
- module.exports = {
5
- overrides: [overrides.typescript],
6
- };
package/jest.config.js DELETED
@@ -1,4 +0,0 @@
1
- module.exports = {
2
- preset: 'ts-jest',
3
- testEnvironment: 'jsdom',
4
- };
package/tsconfig.json DELETED
@@ -1,13 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- "rootDir": "./src",
6
-
7
- "jsx": "react-jsx",
8
-
9
- "composite": true
10
- },
11
- "include": ["src", "jest.config.js", ".eslintrc.js"],
12
- "references": [{ "path": "../plugin-types" }]
13
- }