@sigmacomputing/plugin 0.7.46 → 0.7.47
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/initialize.d.ts.map +1 -1
- package/dist/initialize.js +16 -1
- package/dist/react/index.d.ts +6 -0
- package/dist/react/index.d.ts.map +1 -1
- package/dist/react/index.js +20 -1
- package/package.json +4 -4
- package/src/initialize.ts +28 -2
- package/src/react/index.tsx +29 -0
package/dist/initialize.d.ts.map
CHANGED
|
@@ -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,
|
|
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,CA2L7D"}
|
package/dist/initialize.js
CHANGED
|
@@ -30,7 +30,7 @@ function initialize() {
|
|
|
30
30
|
subscribedWorkbookVars = {};
|
|
31
31
|
Object.assign(subscribedWorkbookVars, updatedVariables);
|
|
32
32
|
});
|
|
33
|
-
on('wb:plugin:
|
|
33
|
+
on('wb:plugin:selection:update', (updatedInteractions) => {
|
|
34
34
|
subscribedInteractions = {};
|
|
35
35
|
Object.assign(subscribedInteractions, updatedInteractions);
|
|
36
36
|
});
|
|
@@ -94,6 +94,12 @@ function initialize() {
|
|
|
94
94
|
setVariable(id, ...values) {
|
|
95
95
|
void execPromise('wb:plugin:variable:set', id, ...values);
|
|
96
96
|
},
|
|
97
|
+
getInteraction(id) {
|
|
98
|
+
return subscribedInteractions[id];
|
|
99
|
+
},
|
|
100
|
+
setInteraction(id, elementId, selection) {
|
|
101
|
+
void execPromise('wb:plugin:selection:set', id, elementId, selection);
|
|
102
|
+
},
|
|
97
103
|
configureEditorPanel(options) {
|
|
98
104
|
void execPromise('wb:plugin:config:inspector', options);
|
|
99
105
|
},
|
|
@@ -109,6 +115,15 @@ function initialize() {
|
|
|
109
115
|
off('wb:plugin:variable:update', setValues);
|
|
110
116
|
};
|
|
111
117
|
},
|
|
118
|
+
subscribeToWorkbookInteraction(id, callback) {
|
|
119
|
+
const setValues = (values) => {
|
|
120
|
+
callback(values[id]);
|
|
121
|
+
};
|
|
122
|
+
on('wb:plugin:selection:update', setValues);
|
|
123
|
+
return () => {
|
|
124
|
+
off('wb:plugin:selection:update', setValues);
|
|
125
|
+
};
|
|
126
|
+
},
|
|
112
127
|
},
|
|
113
128
|
elements: {
|
|
114
129
|
getElementColumns(id) {
|
package/dist/react/index.d.ts
CHANGED
|
@@ -49,4 +49,10 @@ export declare function useConfig(key?: string): any;
|
|
|
49
49
|
* @returns {[(plugin.WorkbookVariable | undefined), Function]} Constantly updating value of the variable and setter for the variable
|
|
50
50
|
*/
|
|
51
51
|
export declare function useVariable(id: string): [plugin.WorkbookVariable | undefined, Function];
|
|
52
|
+
/**
|
|
53
|
+
* React hook for accessing a workbook interaction selections state
|
|
54
|
+
* @param {string} id ID of variable within Plugin Config to use
|
|
55
|
+
* @returns {[(plugin.WorkbookSelection | undefined), Function]} Constantly updating selection state and setter thereof
|
|
56
|
+
*/
|
|
57
|
+
export declare function useInteraction(id: string, elementId: string): [unknown, Function];
|
|
52
58
|
//# 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,mBA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AC,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;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,EAAE,EAAE,MAAM,EACV,SAAS,EAAE,MAAM,GAChB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAmBrB"}
|
package/dist/react/index.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.useVariable = exports.useConfig = exports.useElementData = exports.useElementColumns = exports.useLoadingState = exports.useEditorPanelConfig = exports.usePlugin = exports.SigmaClientProvider = void 0;
|
|
26
|
+
exports.useInteraction = exports.useVariable = exports.useConfig = exports.useElementData = exports.useElementColumns = exports.useLoadingState = exports.useEditorPanelConfig = exports.usePlugin = exports.SigmaClientProvider = void 0;
|
|
27
27
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
28
28
|
const react_1 = __importStar(require("react"));
|
|
29
29
|
const deepEqual_1 = require("../deepEqual");
|
|
@@ -152,3 +152,22 @@ function useVariable(id) {
|
|
|
152
152
|
];
|
|
153
153
|
}
|
|
154
154
|
exports.useVariable = useVariable;
|
|
155
|
+
/**
|
|
156
|
+
* React hook for accessing a workbook interaction selections state
|
|
157
|
+
* @param {string} id ID of variable within Plugin Config to use
|
|
158
|
+
* @returns {[(plugin.WorkbookSelection | undefined), Function]} Constantly updating selection state and setter thereof
|
|
159
|
+
*/
|
|
160
|
+
function useInteraction(id, elementId) {
|
|
161
|
+
const client = usePlugin();
|
|
162
|
+
const [workbookInteraction, setWorkbookInteraction] = (0, react_1.useState)();
|
|
163
|
+
(0, react_1.useEffect)(() => {
|
|
164
|
+
return client.config.subscribeToWorkbookInteraction(id, setWorkbookInteraction);
|
|
165
|
+
}, [client, id]);
|
|
166
|
+
return [
|
|
167
|
+
workbookInteraction,
|
|
168
|
+
react_1.default.useCallback((value) => {
|
|
169
|
+
client.config.setInteraction(id, elementId, value);
|
|
170
|
+
}, [id]),
|
|
171
|
+
];
|
|
172
|
+
}
|
|
173
|
+
exports.useInteraction = useInteraction;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sigmacomputing/plugin",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.47",
|
|
4
4
|
"description": "Plugin client api",
|
|
5
5
|
"module": "./src/index.ts",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -18,16 +18,16 @@
|
|
|
18
18
|
"lint": "eslint --cache src jest.config.js .eslintrc.js",
|
|
19
19
|
"lint:clean": "rimraf .eslintcache",
|
|
20
20
|
"lint:fix": "yarn lint --fix",
|
|
21
|
-
"prepublish": "yarn build",
|
|
21
|
+
"prepublish": "yarn clean && tsc --build tsconfig.publish.json",
|
|
22
22
|
"test": "cd ../.. && jest --ci --selectProjects @sigmacomputing/plugin",
|
|
23
23
|
"test:watch": "yarn test --watch",
|
|
24
24
|
"tsc": "tsc --build tsconfig.build.json"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@sigmacomputing/plugin-types": "^0.7.
|
|
27
|
+
"@sigmacomputing/plugin-types": "^0.7.47"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"react": "^16.8.0 || ^17.0.0 | ^18.0.0"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "146efa6343e32c1abb44287804c424db219a7d28"
|
|
33
33
|
}
|
package/src/initialize.ts
CHANGED
|
@@ -4,7 +4,7 @@ export function initialize<T = {}>(): plugin.PluginInstance<T> {
|
|
|
4
4
|
const pluginConfig: Partial<plugin.PluginConfig<T>> = {
|
|
5
5
|
config: {} as T,
|
|
6
6
|
};
|
|
7
|
-
let subscribedInteractions: Record<string,
|
|
7
|
+
let subscribedInteractions: Record<string, plugin.WorkbookSelection[]> = {};
|
|
8
8
|
let subscribedWorkbookVars: Record<string, plugin.WorkbookVariable> = {};
|
|
9
9
|
|
|
10
10
|
const listeners: {
|
|
@@ -45,7 +45,7 @@ export function initialize<T = {}>(): plugin.PluginInstance<T> {
|
|
|
45
45
|
},
|
|
46
46
|
);
|
|
47
47
|
|
|
48
|
-
on('wb:plugin:
|
|
48
|
+
on('wb:plugin:selection:update', (updatedInteractions: unknown) => {
|
|
49
49
|
subscribedInteractions = {};
|
|
50
50
|
Object.assign(subscribedInteractions, updatedInteractions);
|
|
51
51
|
});
|
|
@@ -112,6 +112,18 @@ export function initialize<T = {}>(): plugin.PluginInstance<T> {
|
|
|
112
112
|
setVariable(id: string, ...values: unknown[]) {
|
|
113
113
|
void execPromise('wb:plugin:variable:set', id, ...values);
|
|
114
114
|
},
|
|
115
|
+
getInteraction(id: string) {
|
|
116
|
+
return subscribedInteractions[id];
|
|
117
|
+
},
|
|
118
|
+
setInteraction(
|
|
119
|
+
id: string,
|
|
120
|
+
elementId: string,
|
|
121
|
+
selection:
|
|
122
|
+
| string[]
|
|
123
|
+
| Array<Record<string, { type: string; val?: unknown }>>,
|
|
124
|
+
) {
|
|
125
|
+
void execPromise('wb:plugin:selection:set', id, elementId, selection);
|
|
126
|
+
},
|
|
115
127
|
configureEditorPanel(options) {
|
|
116
128
|
void execPromise('wb:plugin:config:inspector', options);
|
|
117
129
|
},
|
|
@@ -130,6 +142,20 @@ export function initialize<T = {}>(): plugin.PluginInstance<T> {
|
|
|
130
142
|
off('wb:plugin:variable:update', setValues);
|
|
131
143
|
};
|
|
132
144
|
},
|
|
145
|
+
subscribeToWorkbookInteraction(
|
|
146
|
+
id: string,
|
|
147
|
+
callback: (input: plugin.WorkbookSelection[]) => void,
|
|
148
|
+
): plugin.Unsubscriber {
|
|
149
|
+
const setValues = (
|
|
150
|
+
values: Record<string, plugin.WorkbookSelection[]>,
|
|
151
|
+
) => {
|
|
152
|
+
callback(values[id]);
|
|
153
|
+
};
|
|
154
|
+
on('wb:plugin:selection:update', setValues);
|
|
155
|
+
return () => {
|
|
156
|
+
off('wb:plugin:selection:update', setValues);
|
|
157
|
+
};
|
|
158
|
+
},
|
|
133
159
|
},
|
|
134
160
|
elements: {
|
|
135
161
|
getElementColumns(id) {
|
package/src/react/index.tsx
CHANGED
|
@@ -152,3 +152,32 @@ export function useVariable(
|
|
|
152
152
|
),
|
|
153
153
|
];
|
|
154
154
|
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* React hook for accessing a workbook interaction selections state
|
|
158
|
+
* @param {string} id ID of variable within Plugin Config to use
|
|
159
|
+
* @returns {[(plugin.WorkbookSelection | undefined), Function]} Constantly updating selection state and setter thereof
|
|
160
|
+
*/
|
|
161
|
+
export function useInteraction(
|
|
162
|
+
id: string,
|
|
163
|
+
elementId: string,
|
|
164
|
+
): [unknown, Function] {
|
|
165
|
+
const client = usePlugin();
|
|
166
|
+
const [workbookInteraction, setWorkbookInteraction] =
|
|
167
|
+
useState<plugin.WorkbookSelection[]>();
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
return client.config.subscribeToWorkbookInteraction(
|
|
170
|
+
id,
|
|
171
|
+
setWorkbookInteraction,
|
|
172
|
+
);
|
|
173
|
+
}, [client, id]);
|
|
174
|
+
return [
|
|
175
|
+
workbookInteraction,
|
|
176
|
+
React.useCallback(
|
|
177
|
+
(value: plugin.WorkbookSelection[]) => {
|
|
178
|
+
client.config.setInteraction(id, elementId, value);
|
|
179
|
+
},
|
|
180
|
+
[id],
|
|
181
|
+
),
|
|
182
|
+
];
|
|
183
|
+
}
|