Skip to content

Commit a32953b

Browse files
committed
add request style
1 parent 0f65af6 commit a32953b

File tree

3 files changed

+8
-43
lines changed

3 files changed

+8
-43
lines changed

src/client/initialize.ts

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,8 @@ export function initialize<T = {}>(): PluginInstance<T> {
3737
emit('config', pluginConfig.config ?? {});
3838
});
3939

40-
on('wb:plugin:style:update', (styleColors: any) => {
41-
pluginConfig.styleColors = styleColors;
42-
emit('style', styleColors);
40+
on('wb:plugin:style:update', (style: any) => {
41+
emit('style', style);
4342
});
4443

4544
// send initialize event
@@ -229,29 +228,14 @@ export function initialize<T = {}>(): PluginInstance<T> {
229228
},
230229
},
231230

232-
// Style management functions for hooks
233231
style: {
234-
/**
235-
* Subscribe to style updates
236-
* @param callback Function to call when style updates
237-
* @returns Unsubscriber function
238-
*/
239-
subscribe(callback: (style: any) => void) {
232+
subscribeToStyle(callback: (style: any) => void) {
240233
on('style', callback);
241234
return () => off('style', callback);
242235
},
243236

244-
/**
245-
* Request current style from workbook
246-
* @returns Promise with current style
247-
*/
248-
async getStyle() {
249-
try {
250-
return await execPromise('wb:plugin:style:get');
251-
} catch (error) {
252-
// Return default style if request fails
253-
return { backgroundColor: 'transparent' };
254-
}
237+
getStyle() {
238+
return execPromise('wb:plugin:style:get');
255239
},
256240
},
257241

src/react/hooks.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,9 @@ export function usePluginStyle(): PluginStyle | undefined {
257257
const [style, setStyle] = useState<PluginStyle | undefined>(undefined);
258258

259259
useEffect(() => {
260-
const unsubscribe = client.style.subscribe(setStyle);
261-
// Request initial style data on mount
260+
// Request initial style data on mount and subscribe to updates
262261
void client.style.getStyle().then(setStyle);
263-
264-
return unsubscribe;
262+
return client.style.subscribeToStyle(setStyle);
265263
}, [client]);
266264

267265
return style;

src/types.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export interface PluginConfig<T> {
2727
id: string;
2828
config: T;
2929
screenshot: boolean;
30-
// styleColors: PluginStyle;
3130
[key: string]: any;
3231
}
3332

@@ -206,19 +205,6 @@ export type CustomPluginConfigOptions =
206205
export interface PluginInstance<T = any> {
207206
sigmaEnv: 'author' | 'viewer' | 'explorer';
208207

209-
// /**
210-
// * Plugin style colors from the workbook
211-
// * @returns {PluginStyle | undefined} Style colors if available
212-
// */
213-
// styleColors?: PluginStyle | undefined;
214-
215-
// /**
216-
// * Listen to style color changes
217-
// * @param {Function} callback Function to call when style colors change
218-
// * @returns {Function} Unsubscriber function
219-
// */
220-
// onStyleChange(callback: (styleColors: PluginStyle) => void): () => void;
221-
222208
config: {
223209
/**
224210
* Getter for entire Plugin Config
@@ -378,16 +364,13 @@ export interface PluginInstance<T = any> {
378364
fetchMoreElementData(configId: string): void;
379365
};
380366

381-
/**
382-
* Style management for plugins
383-
*/
384367
style: {
385368
/**
386369
* Subscribe to style updates
387370
* @param callback Function to call when style updates
388371
* @returns Unsubscriber function
389372
*/
390-
subscribe(callback: (style: PluginStyle) => void): () => void;
373+
subscribeToStyle(callback: (style: PluginStyle) => void): () => void;
391374

392375
/**
393376
* Request current style from workbook

0 commit comments

Comments
 (0)