Skip to content

Commit a67632b

Browse files
committed
refactor: move ts code
1 parent ead395e commit a67632b

File tree

25 files changed

+6288
-6199
lines changed

25 files changed

+6288
-6199
lines changed

src/buttons.ts renamed to components/buttons/buttons.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Component, BaseOptions, InitElements, MElement, Openable } from "./component";
2-
import { Utils } from './utils';
1+
import { Component, BaseOptions, InitElements, MElement, Openable } from '../../src/component';
2+
import { Utils } from '../../src/utils';
33

44
export interface FloatingActionButtonOptions extends BaseOptions {
55
/**
@@ -65,14 +65,10 @@ export class FloatingActionButton
6565
this.el.classList.add(`direction-${this.options.direction}`);
6666
this._anchor.tabIndex = 0;
6767
this._menu.ariaExpanded = 'false';
68-
if (this.options.direction === 'top')
69-
this.offsetY = 40;
70-
else if (this.options.direction === 'right')
71-
this.offsetX = -40;
72-
else if (this.options.direction === 'bottom')
73-
this.offsetY = -40;
74-
else
75-
this.offsetX = 40;
68+
if (this.options.direction === 'top') this.offsetY = 40;
69+
else if (this.options.direction === 'right') this.offsetX = -40;
70+
else if (this.options.direction === 'bottom') this.offsetY = -40;
71+
else this.offsetX = 40;
7672
this._setupEventHandlers();
7773
}
7874

@@ -140,14 +136,14 @@ export class FloatingActionButton
140136
}
141137

142138
_handleFABClick = () => {
143-
this._handleFABToggle()
144-
}
139+
this._handleFABToggle();
140+
};
145141

146142
_handleFABKeyPress = (e) => {
147-
if(Utils.keys.ENTER.includes(e.key)) {
143+
if (Utils.keys.ENTER.includes(e.key)) {
148144
this._handleFABToggle();
149145
}
150-
}
146+
};
151147

152148
_handleFABToggle = () => {
153149
if (this.isOpen) {

src/cards.ts renamed to components/cards/cards.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Utils } from './utils';
2-
import { Component, BaseOptions, InitElements, MElement, Openable } from './component';
1+
import { Utils } from '../../src/utils';
2+
import { Component, BaseOptions, InitElements, MElement, Openable } from '../../src/component';
33

44
export interface CardsOptions extends BaseOptions {
55
onOpen: (el: Element) => void;
@@ -182,7 +182,7 @@ export class Cards extends Component<CardsOptions> implements Openable {
182182
document.addEventListener('DOMContentLoaded', () => {
183183
const cards = document.querySelectorAll('.card');
184184
cards.forEach((el) => {
185-
if (el && (el['M_Card'] == undefined)) this.init((el as HTMLElement));
185+
if (el && el['M_Card'] == undefined) this.init(el as HTMLElement);
186186
});
187187
});
188188
}

src/carousel.ts renamed to components/carousel/carousel.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Utils } from './utils';
2-
import { Component, BaseOptions, InitElements, MElement } from './component';
1+
import { Utils } from '../../src/utils';
2+
import { Component, BaseOptions, InitElements, MElement } from '../../src/component';
33

44
export interface CarouselOptions extends BaseOptions {
55
/**
@@ -240,11 +240,7 @@ export class Carousel extends Component<CarouselOptions> {
240240
window.removeEventListener('resize', this._handleThrottledResize);
241241
}
242242

243-
_handleThrottledResize = (): void => Utils.throttle(
244-
this._handleResize,
245-
200,
246-
null
247-
).bind(this);
243+
_handleThrottledResize = (): void => Utils.throttle(this._handleResize, 200, null).bind(this);
248244

249245
_handleCarouselTap = (e: MouseEvent | TouchEvent) => {
250246
// Fixes firefox draggable image bug

src/slider.ts renamed to components/carousel/slider.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Utils } from './utils';
2-
import { Component, BaseOptions, InitElements, MElement } from './component';
1+
import { Utils } from '../../src/utils';
2+
import { Component, BaseOptions, InitElements, MElement } from '../../src/component';
33

44
export interface SliderOptions extends BaseOptions {
55
/**
@@ -252,8 +252,7 @@ export class Slider extends Component<SliderOptions> {
252252
private _handleInterval = () => {
253253
const activeElem = this._slider.querySelector('.active');
254254
let newActiveIndex = [...activeElem.parentNode.children].indexOf(activeElem);
255-
if (this._slides.length === newActiveIndex + 1)
256-
newActiveIndex = 0; // loop to start
255+
if (this._slides.length === newActiveIndex + 1) newActiveIndex = 0; // loop to start
257256
else newActiveIndex += 1;
258257
this.set(newActiveIndex);
259258
};

src/chips.ts renamed to components/chips/chips.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Utils } from './utils';
2-
import { Autocomplete, AutocompleteOptions } from './autocomplete';
3-
import { Component, BaseOptions, InitElements, MElement } from './component';
1+
import { Utils } from '../../src/utils';
2+
import { Autocomplete, AutocompleteOptions } from '../search/autocomplete';
3+
import { Component, BaseOptions, InitElements, MElement } from '../../src/component';
44

55
export interface ChipData {
66
/**

src/collapsible.ts renamed to components/collapsible/collapsible.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Utils } from './utils';
2-
import { Component, BaseOptions, InitElements, MElement } from './component';
1+
import { Utils } from '../../src/utils';
2+
import { Component, BaseOptions, InitElements, MElement } from '../../src/component';
33

44
export interface CollapsibleOptions extends BaseOptions {
55
/**

src/datepicker.ts renamed to components/datepicker/datepicker.ts

Lines changed: 53 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Utils } from './utils';
2-
import { FormSelect } from './select';
3-
import { BaseOptions, Component, I18nOptions, InitElements, MElement } from './component';
4-
import { DockedDisplayPlugin } from './plugin/dockedDisplayPlugin';
1+
import { Utils } from '../../src/utils';
2+
import { BaseOptions, Component, I18nOptions, InitElements, MElement } from '../../src/component';
3+
import { FormSelect } from '../text-fields/select';
4+
import { DockedDisplayPlugin } from '../../src/dockedDisplayPlugin';
55

66
export interface DateI18nOptions extends I18nOptions {
77
previousMonth: string;
@@ -293,7 +293,7 @@ const _defaults: DatepickerOptions = {
293293
displayPlugin: null,
294294
displayPluginOptions: null,
295295
onConfirm: null,
296-
onCancel: null,
296+
onCancel: null
297297
};
298298

299299
export class Datepicker extends Component<DatepickerOptions> {
@@ -381,7 +381,12 @@ export class Datepicker extends Component<DatepickerOptions> {
381381
this.dateEls.push(el);
382382
}
383383
if (this.options.displayPlugin) {
384-
if (this.options.displayPlugin === 'docked') this.displayPlugin = DockedDisplayPlugin.init(this.el, this.containerEl, this.options.displayPluginOptions);
384+
if (this.options.displayPlugin === 'docked')
385+
this.displayPlugin = DockedDisplayPlugin.init(
386+
this.el,
387+
this.containerEl,
388+
this.options.displayPluginOptions
389+
);
385390
}
386391
}
387392

@@ -493,7 +498,9 @@ export class Datepicker extends Component<DatepickerOptions> {
493498
if (!this.options.dateRangeEndEl) {
494499
this.endDateEl = this.createDateInput();
495500
this.endDateEl.classList.add('datepicker-end-date');
496-
} else if(document.querySelector(this.options.dateRangeEndEl) as HTMLInputElement === undefined) {
501+
} else if (
502+
(document.querySelector(this.options.dateRangeEndEl) as HTMLInputElement) === undefined
503+
) {
497504
console.warn('Specified date range end input element in dateRangeEndEl not found');
498505
} else {
499506
this.endDateEl = document.querySelector(this.options.dateRangeEndEl) as HTMLInputElement;
@@ -509,10 +516,22 @@ export class Datepicker extends Component<DatepickerOptions> {
509516
}
510517
this.doneBtn.innerText = this.options.i18n.done;
511518
this.cancelBtn.innerText = this.options.i18n.cancel;*/
512-
Utils.createButton(this.footer, this.options.i18n.clear, ['datepicker-clear'], this.options.showClearBtn, this._handleClearClick);
519+
Utils.createButton(
520+
this.footer,
521+
this.options.i18n.clear,
522+
['datepicker-clear'],
523+
this.options.showClearBtn,
524+
this._handleClearClick
525+
);
513526

514527
if (!this.options.autoSubmit) {
515-
Utils.createConfirmationContainer(this.footer, this.options.i18n.done, this.options.i18n.cancel, this._confirm, this._cancel);
528+
Utils.createConfirmationContainer(
529+
this.footer,
530+
this.options.i18n.done,
531+
this.options.i18n.cancel,
532+
this._confirm,
533+
this._cancel
534+
);
516535
}
517536

518537
if (this.options.container) {
@@ -523,7 +542,11 @@ export class Datepicker extends Component<DatepickerOptions> {
523542
} else {
524543
//this.containerEl.before(this.el);
525544
const appendTo = !this.endDateEl ? this.el : this.endDateEl;
526-
if (!this.options.openByDefault) (this.containerEl as HTMLElement).setAttribute('style', 'display: none; visibility: hidden;');
545+
if (!this.options.openByDefault)
546+
(this.containerEl as HTMLElement).setAttribute(
547+
'style',
548+
'display: none; visibility: hidden;'
549+
);
527550
appendTo.parentElement.after(this.containerEl);
528551
}
529552
}
@@ -711,7 +734,10 @@ export class Datepicker extends Component<DatepickerOptions> {
711734
this.dateTextEl.innerHTML = this.formatDate(displayDate, 'ddd, mmm d');
712735
} else {
713736
const displayEndDate = Datepicker._isDate(endDate) ? endDate : new Date();
714-
this.dateTextEl.innerHTML = `${this.formatDate(displayDate, 'mmm d')} - ${this.formatDate(displayEndDate, 'mmm d')}`;
737+
this.dateTextEl.innerHTML = `${this.formatDate(displayDate, 'mmm d')} - ${this.formatDate(
738+
displayEndDate,
739+
'mmm d'
740+
)}`;
715741
}
716742
}
717743

@@ -819,8 +845,13 @@ export class Datepicker extends Component<DatepickerOptions> {
819845
(this.options.maxDate && day > this.options.maxDate) ||
820846
(this.options.disableWeekends && Datepicker._isWeekend(day)) ||
821847
(this.options.disableDayFn && this.options.disableDayFn(day)),
822-
isDateRangeStart = this.options.isDateRange && this.date && this.endDate && Datepicker._compareDates(this.date, day),
823-
isDateRangeEnd = this.options.isDateRange && this.endDate && Datepicker._compareDates(this.endDate, day),
848+
isDateRangeStart =
849+
this.options.isDateRange &&
850+
this.date &&
851+
this.endDate &&
852+
Datepicker._compareDates(this.date, day),
853+
isDateRangeEnd =
854+
this.options.isDateRange && this.endDate && Datepicker._compareDates(this.endDate, day),
824855
isDateRange =
825856
this.options.isDateRange &&
826857
Datepicker._isDate(this.endDate) &&
@@ -900,7 +931,11 @@ export class Datepicker extends Component<DatepickerOptions> {
900931
isDateRangeEnd: 'is-daterange-end',
901932
isDateRange: 'is-daterange'
902933
},
903-
ariaSelected = !(['isSelected', 'isDateRange'].filter((prop) => !!(opts.hasOwnProperty(prop) && opts[prop] === true)).length === 0),
934+
ariaSelected = !(
935+
['isSelected', 'isDateRange'].filter(
936+
(prop) => !!(opts.hasOwnProperty(prop) && opts[prop] === true)
937+
).length === 0
938+
),
904939
arr = ['datepicker-day'];
905940

906941
if (opts.isEmpty) {
@@ -1014,7 +1049,9 @@ export class Datepicker extends Component<DatepickerOptions> {
10141049
}
10151050
if (opts.yearRangeReverse) arr.reverse();
10161051

1017-
const yearHtml = `<select class="datepicker-select orig-select-year" tabindex="-1">${arr.join('')}</select>`;
1052+
const yearHtml = `<select class="datepicker-select orig-select-year" tabindex="-1">${arr.join(
1053+
''
1054+
)}</select>`;
10181055

10191056
const leftArrow =
10201057
'<svg height="24" viewBox="0 0 24 24" width="24" xmlns="http://www.w3.org/2000/svg"><path d="M15.41 16.09l-4.58-4.59 4.58-4.59L14 5.5l-6 6 6 6z"/><path d="M0-.5h24v24H0z" fill="none"/></svg>';
@@ -1353,7 +1390,7 @@ export class Datepicker extends Component<DatepickerOptions> {
13531390
_confirm = () => {
13541391
this._finishSelection();
13551392
if (typeof this.options.onConfirm === 'function') this.options.onConfirm.call(this);
1356-
}
1393+
};
13571394

13581395
_cancel = () => {
13591396
if (typeof this.options.onCancel === 'function') this.options.onCancel.call(this);

src/materialbox.ts renamed to components/dialog/materialbox.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Utils } from './utils';
2-
import { BaseOptions, Component, InitElements, MElement } from './component';
1+
import { Utils } from '../../src/utils';
2+
import { BaseOptions, Component, InitElements, MElement } from '../../src/component';
33

44
export interface MaterialboxOptions extends BaseOptions {
55
/**

src/modal.ts renamed to components/dialog/modal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Component, BaseOptions, InitElements, MElement } from './component';
1+
import { Component, BaseOptions, InitElements, MElement } from '../../src/component';
22

33
// Obsolete for versions > 2.1.1
44

src/dropdown.ts renamed to components/dropdown/dropdown.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { Utils } from './utils';
2-
import { Component, BaseOptions, InitElements, MElement, Openable } from './component';
1+
import { Utils } from '../../src/utils';
2+
import { Component, BaseOptions, InitElements, MElement, Openable } from '../../src/component';
33

44
export interface DropdownOptions extends BaseOptions {
55
/**

0 commit comments

Comments
 (0)