Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ChartJS] Fix failing build with ChartJS >= 3.9.0 #427

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Chartjs/Resources/assets/dist/controller.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Controller } from '@hotwired/stimulus';
import Chart from 'chart.js/auto';
import { Chart, registerables } from 'chart.js';

Chart.register(...registerables);
class default_1 extends Controller {
connect() {
if (!(this.element instanceof HTMLCanvasElement)) {
Expand Down
3 changes: 2 additions & 1 deletion src/Chartjs/Resources/assets/src/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
'use strict';

import { Controller } from '@hotwired/stimulus';
import Chart from 'chart.js/auto';
import { Chart, registerables } from 'chart.js';
Chart.register(...registerables);

export default class extends Controller {
readonly viewValue: any;
Expand Down
33 changes: 21 additions & 12 deletions src/LiveComponent/assets/dist/live_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1084,8 +1084,8 @@ function getModelDirectiveFromInput(element, throwOnMissing = true) {
}
if (element.getAttribute('name')) {
const formElement = element.closest('form');
if (formElement && formElement.dataset.model) {
const directives = parseDirectives(formElement.dataset.model);
if (formElement && ('model' in formElement.dataset)) {
const directives = parseDirectives(formElement.dataset.model || '*');
const directive = directives[0];
if (directive.args.length > 0 || directive.named.length > 0) {
throw new Error(`The data-model="${formElement.dataset.model}" format is invalid: it does not support passing arguments to the model.`);
Expand Down Expand Up @@ -1222,9 +1222,7 @@ class default_1 extends Controller {
if (!(this.element instanceof HTMLElement)) {
throw new Error('Invalid Element Type');
}
if (this.element.dataset.poll !== undefined) {
this._initiatePolling(this.element.dataset.poll);
}
this._initiatePolling();
window.addEventListener('beforeunload', this.markAsWindowUnloaded);
this._startAttributesMutationObserver();
this.element.addEventListener('live:update-model', this.handleUpdateModelEvent);
Expand All @@ -1234,9 +1232,7 @@ class default_1 extends Controller {
this._dispatchEvent('live:connect', { controller: this });
}
disconnect() {
this.pollingIntervals.forEach((interval) => {
clearInterval(interval);
});
this._stopAllPolling();
window.removeEventListener('beforeunload', this.markAsWindowUnloaded);
this.element.removeEventListener('live:update-model', this.handleUpdateModelEvent);
this.element.removeEventListener('input', this.handleInputEvent);
Expand Down Expand Up @@ -1665,7 +1661,12 @@ class default_1 extends Controller {
}
this._updateModelFromElement(target, 'change');
}
_initiatePolling(rawPollConfig) {
_initiatePolling() {
this._stopAllPolling();
if (this.element.dataset.poll === undefined) {
return;
}
const rawPollConfig = this.element.dataset.poll;
const directives = parseDirectives(rawPollConfig || '$render');
directives.forEach((directive) => {
let duration = 2000;
Expand Down Expand Up @@ -1790,9 +1791,12 @@ class default_1 extends Controller {
const element = this.element;
this.mutationObserver = new MutationObserver((mutations) => {
mutations.forEach((mutation) => {
if (mutation.type === 'attributes' && !element.dataset.originalData) {
this.originalDataJSON = this.valueStore.asJson();
this._exposeOriginalData();
if (mutation.type === 'attributes') {
if (!element.dataset.originalData) {
this.originalDataJSON = this.valueStore.asJson();
this._exposeOriginalData();
}
this._initiatePolling();
}
});
});
Expand All @@ -1803,6 +1807,11 @@ class default_1 extends Controller {
getDefaultDebounce() {
return this.hasDebounceValue ? this.debounceValue : DEFAULT_DEBOUNCE;
}
_stopAllPolling() {
this.pollingIntervals.forEach((interval) => {
clearInterval(interval);
});
}
}
default_1.values = {
url: String,
Expand Down