Export plugin as an ESM compatible module#222
Conversation
…labels into chartjs-next # Conflicts: # docs/.vuepress/plugins/chart-editor/index.js # package-lock.json # package.json # test/utils.js # types/index.d.ts
|
@simonbrunel if you like this PR, and decide to merge it, could you consider releasing the target branch under the |
simonbrunel
left a comment
There was a problem hiding this comment.
@santam85 Thanks you for your help in migrating this plugin.
I can't guarantee that I will release a beta right after but I will try to do my best to have it released soon. The documentation will also need to be updated to reflect Chart.js 3 changes about registering plugins.
|
@simonbrunel latest beta broke several tests, any clue what the cause might be? Can't link these errors to any of the listed breaking changes... |
|
@santam85 its mostly the proxied options that default to scriptable being true, and thus tries to resolve the event handlers etc. Adding something like that to the plugin should help (from #221): descriptors: {
_scriptable: function(name) {
return !['formatter', 'enter', 'leave', 'click'].includes(name);
},
}, |
|
@santam85 This plugin doesn't rely on proxied options (and I'm not sure I would like to) so it's probably better to fully disable this feature for now ( @kurkle Shouldn't proxied options for plugins default to |
|
@simonbrunel yes, it should default to false for plugins. |
|
So, to make this work with beta.11 you'll need to add this: descriptors: {
_scriptable: false,
listeners: {
_scriptable: false
}
},And this should not be needed after next release. |
13f7092 to
40d42df
Compare
Some docs samples are broken, this needs to be investigated before merging.
|
@santam85 A few samples are broken compared to the
|
kurkle
left a comment
There was a problem hiding this comment.
Looks like the samples issue persists, I'll take a closer look at it.
|
|
||
| declare module 'chart.js' { | ||
| interface ChartDatasetProperties<TType extends ChartType, TData extends unknown[]> { | ||
| interface ChartDatasetProperties<TType extends ChartType, TData> { |
There was a problem hiding this comment.
This is probably an issue with the types in beta.12
There was a problem hiding this comment.
If the generic base type is still needed, maybe the core could export a nice alias:
// chart.js
export type AnyArray = unknown[];// chart-plugin-datalabels
import { AnyArray } from 'chart.js';
declare module 'chart.js' {
interface ChartDatasetProperties<TType extends ChartType, TData extends AnyArray> {
//...
}There was a problem hiding this comment.
Could even be AnyData instead of AnyArray.
There was a problem hiding this comment.
I am just matching the definition here to prevent errors. If only array data-types are needed, would TData extends Array<any> work? Or even ChartDatasetProperties<TType extends ChartType, Array<any>>?
There was a problem hiding this comment.
I think it needs to be the exact same definition as in the core repo, so it would not work. Also, I disabled the use of any and enforce array type consistency in this project, so it would need to be unknown[].
There was a problem hiding this comment.
@santam85 I think I misunderstood your previous comment. Are you suggesting to use Array<any> in the core repo?
If so, I would not go that way because any isn't good for typing, unknown is better because it forces a check of the actual type before using it. Using an alias such as AnyData would allow to extend this data type later (if needed) without breaking existing integrations (e.g. type AnyData = AnyArray | AnyObject) or type AnyData = (number | string | DataObject)[], etc.).
There was a problem hiding this comment.
Yeah, I meant in the core repo. Sounds good, will adjust accordingly once decided.
Fixes doc samples
|
Thanks @santam85. Samples are still broken: legend and tooltip should not be visible. It looks like an issue in the core lib where registering a plugin (and probably other types) doesn't preserve existing defaults: import {Chart, registrables} from 'chart.js';
Chart.defaults.set({
plugin: {
legend: {
display: false;
}
}
})
Chart.register(...registrables);
// Chart.defaults.plugin.legend.display === trueI will see how to fix the docs after merging this PR. |
Avoids getting errors like:
Uncaught TypeError: helpers$1.merge is not a functionwhen loading the plugin as a module.