From 87cd2509b78964c300150a633bb4287118a77b6c Mon Sep 17 00:00:00 2001 From: Wan Qi Chen <495709+wa0x6e@users.noreply.github.com> Date: Fri, 17 Mar 2023 00:49:42 +0400 Subject: [PATCH] fix: fix not unique plugin name, and overwriting each other --- src/index.d.ts | 2 +- src/plugins/CalendarLabel.ts | 13 +++++-------- src/plugins/PluginManager.ts | 4 ++-- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index 578585b1..34e3f688 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -66,7 +66,7 @@ declare namespace CalHeatmap { destroy: () => Promise; } export interface IPluginContructor { - new (calendar: CalHeatmap): IPlugin; + new (calendar?: CalHeatmap): IPlugin; } export interface PluginOptions { diff --git a/src/plugins/CalendarLabel.ts b/src/plugins/CalendarLabel.ts index 3afa4af9..d14a2e67 100644 --- a/src/plugins/CalendarLabel.ts +++ b/src/plugins/CalendarLabel.ts @@ -55,20 +55,17 @@ export default class CalendarLabel implements IPlugin { computedOptions: ComputedOptions; constructor(calendar: CalHeatmap) { - const { - radius, width, height, gutter, - } = - calendar.options.options.subDomain; + const subDomain = calendar?.options?.options?.subDomain; this.calendar = calendar; this.root = null; this.shown = false; this.options = defaultOptions; this.computedOptions = { - radius, - width, - height, - gutter, + radius: subDomain?.radius, + width: subDomain?.width, + height: subDomain?.height, + gutter: subDomain?.gutter, textAlign: 'start', }; } diff --git a/src/plugins/PluginManager.ts b/src/plugins/PluginManager.ts index 65e84305..b4967a16 100644 --- a/src/plugins/PluginManager.ts +++ b/src/plugins/PluginManager.ts @@ -21,10 +21,10 @@ function createPlugin( } function extractPluginName( - pluginClass: IPluginContructor, + PluginClass: IPluginContructor, options?: PluginOptions, ): string { - return `${pluginClass.name}${options?.key || ''}`; + return `${new PluginClass().name}${options?.key || ''}`; } export default class PluginManager {