Skip to content

Commit

Permalink
V3.5.1 (#610)
Browse files Browse the repository at this point in the history
* #600 - added `isDestroyed` property, opts and selectedDates now will have empty values after calendar is destroyed

* #600 - added docs for `isDestroyed`

* #600 - bupm version, added logs

* fixed log
  • Loading branch information
t1m0n authored May 13, 2024
1 parent 1a54ee2 commit a788d34
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 16 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog

### v3.5.1
* improved `destroy()` behavior - added `isDestroyed` property, `opts` and `selectedDates` will still have empty values, instead of `null`, even after AirDatepicker has been destroyed [#600](https://github.com/t1m0n/air-datepicker/issues/600)

### v3.5.0
* added `fixedHeight` option, allows you to have equal weeks number in every month
* added method `disableDate`, allows you to disabled one or multiple dates with datepicker API
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ new AirDatepicker('#el' [, options]);

## Recent updates

### v3.5.1
* improved `destroy()` behavior - added `isDestroyed` property, `opts` and `selectedDates` will still have empty values, instead of `null`, even after AirDatepicker has been destroyed [#600](https://github.com/t1m0n/air-datepicker/issues/600)

### v3.5.0
* added `fixedHeight` option, allows you to have equal weeks number in every month
* added method `disableDate`, allows you to disabled one or multiple dates with datepicker API
Expand Down
12 changes: 10 additions & 2 deletions dist/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,23 @@ new AirDatepicker('#el' [, options]);

## Recent updates

### v3.5.1
* improved `destroy()` behavior - added `isDestroyed` property, `opts` and `selectedDates` will still have empty values, instead of `null`, even after AirDatepicker has been destroyed [#600](https://github.com/t1m0n/air-datepicker/issues/600)

### v3.5.0
* added `fixedHeight` option, allows you to have equal weeks number in every month
* added method `disableDate`, allows you to disabled one or multiple dates with datepicker API
* added prop `disabledDates` - it is a Set which holds all disabled dates
* added possibility to pass `{silent: true}` to `update` and `setCurrentView` methods, [#583](https://github.com/t1m0n/air-datepicker/issues/568)
* changed `update` method - now if you pass `selectedDates` here then calendar will keep selected only those dates
* fixed localization generation
* changed `update` method - now if you pass `selectedDates` then calendar will keep selected only those dates
* fixed selecting time on same date when `range: true`, [#568](https://github.com/t1m0n/air-datepicker/issues/568)
* fixed date conversion to local date when using strings, e.g `selectDate('2024-03-05')` [#589](https://github.com/t1m0n/air-datepicker/issues/589)
* fixed localization generation, thanks to [hreyeslo](https://github.com/hreyeslo) in [#524](https://github.com/t1m0n/air-datepicker/pull/524)
* fixed type definition for `clear` method, thanks to [ahmetzambak](https://github.com/ahmetzambak) in [#591](https://github.com/t1m0n/air-datepicker/pull/591)
* fixed German translation for "clear", thanks to [pbek](https://github.com/pbek) in [#582](https://github.com/t1m0n/air-datepicker/pull/582)
* added Slovenian locale, thanks to [carliblaz](https://github.com/carliblaz) in [#569](https://github.com/t1m0n/air-datepicker/pull/569)
* added Basque locale, thanks to [ikerib](https://github.com/ikerib) in [#529](https://github.com/t1m0n/air-datepicker/pull/529)
* added Norwegian locale, thanks to [MortenSpjotvoll](https://github.com/MortenSpjotvoll) in [#521](https://github.com/t1m0n/air-datepicker/pull/521)

### v3.4.0
* added new options `onFocus` and `onBeforeSelect` grant you more control over range selection behaviour and more [#526](https://github.com/t1m0n/air-datepicker/issues/526)
Expand Down
1 change: 1 addition & 0 deletions dist/air-datepicker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ declare class AirDatepicker<E extends HTMLElement = HTMLInputElement> {
focusDate: Date | false
visible: boolean
disabledDates: Set<string>
isDestroyed: boolean;
}


Expand Down
2 changes: 1 addition & 1 deletion dist/air-datepicker.js

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions dist/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "air-datepicker",
"version": "3.5.0",
"version": "3.5.1",
"scripts": {
"dev": "set NODE_ENV=development&& webpack",
"dev:serve": "npm run browser&& set NODE_ENV=development&& webpack serve",
"prod": "set NODE_ENV=production&& webpack",
"dev": "cross-env NODE_ENV=development webpack",
"dev:serve": "cross-env NODE_ENV=development webpack serve",
"prod": "cross-env NODE_ENV=production webpack",
"browser": "open-cli http://localhost:8080 -- 'chrome' ",
"build": "node scripts/build.js",
"lint-js": "eslint --fix ./src/*.js",
Expand All @@ -26,6 +26,7 @@
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"chalk": "^4.1.1",
"cross-env": "^7.0.3",
"css-loader": "^3.5.3",
"ejs": "^3.1.6",
"eslint": "^7.32.0",
Expand Down
3 changes: 2 additions & 1 deletion docs/locales/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,6 @@ export default {
apiGetViewDates: 'Returns all dates that should be currently displayed in calendar.',
apiDisableDate: 'Disables one or multiple dates.',
apiEnabledDate: 'Enables dates previously disabled.',
apiDisabledDates: 'Set of disabled dates'
apiDisabledDates: 'Set of disabled dates',
apiIsDestroyed: 'If {trueField} then calendar has been destroyed with destroy() method'
};
3 changes: 2 additions & 1 deletion docs/locales/ru.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,5 +265,6 @@ export default {
apiGetViewDates: 'Возвращает все даты, которые должны быть отображены в календаре.',
apiDisableDate: 'Деактивирует одну или несколько дат.',
apiEnabledDate: 'Активирует даты, которые ранее были деактивированы.',
apiDisabledDates: 'Set, где хранятся все деактивированные даты'
apiDisabledDates: 'Set, где хранятся все деактивированные даты',
apiIsDestroyed: 'Если {trueField}, значит календарь был уничтожен с помощью destroy()'
};
3 changes: 3 additions & 0 deletions docs/pages/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ function Methods({} = {}) {
<Param name={'disabledDates'} type={'Set<string>'}>
<Paragraph id={'apiDisabledDates'} />
</Param>
<Param name={'isDestroyed'} type={'boolean'}>
<Paragraph id={'apiIsDestroyed'} values={{trueField}} />
</Param>
</Param.List>
</Section>
</main>
Expand Down
9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "air-datepicker",
"version": "3.5.0",
"version": "3.5.1",
"scripts": {
"dev": "set NODE_ENV=development&& webpack",
"dev:serve": "npm run browser&& set NODE_ENV=development&& webpack serve",
"prod": "set NODE_ENV=production&& webpack",
"dev": "cross-env NODE_ENV=development webpack",
"dev:serve": "cross-env NODE_ENV=development webpack serve",
"prod": "cross-env NODE_ENV=production webpack",
"browser": "open-cli http://localhost:8080 -- 'chrome' ",
"build": "node scripts/build.js",
"lint-js": "eslint --fix ./src/*.js",
Expand All @@ -26,6 +26,7 @@
"babel-eslint": "^10.1.0",
"babel-loader": "^8.1.0",
"chalk": "^4.1.1",
"cross-env": "^7.0.3",
"css-loader": "^3.5.3",
"ejs": "^3.1.6",
"eslint": "^7.32.0",
Expand Down
1 change: 1 addition & 0 deletions src/datepicker.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ declare class AirDatepicker<E extends HTMLElement = HTMLInputElement> {
focusDate: Date | false
visible: boolean
disabledDates: Set<string>
isDestroyed: boolean;
}


Expand Down
11 changes: 8 additions & 3 deletions src/datepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let $datepickersContainer = '',

export default class Datepicker {
static defaults = defaults
static version = '3.5.0'
static version = '3.5.1'
static defaultGlobalContainerId = 'air-datepicker-global-container'
static buildGlobalContainer(id) {
containerBuilt = true;
Expand Down Expand Up @@ -74,6 +74,7 @@ export default class Datepicker {
this.currentView = view;
this.selectedDates = [];
this.disabledDates = new Set();
this.isDestroyed = false;
this.views = {};
this.keys = [];
this.rangeDateFrom = '';
Expand Down Expand Up @@ -1060,6 +1061,8 @@ export default class Datepicker {
}

destroy = () => {
if (this.isDestroyed) return;

let {showEvent, isMobile} = this.opts;

let parent = this.$datepicker.parentNode;
Expand All @@ -1082,14 +1085,16 @@ export default class Datepicker {
this.nav = null;

this.$datepicker = null;
this.opts = null;
this.opts = {};
this.$customContainer = null;

this.viewDate = null;
this.focusDate = null;
this.selectedDates = null;
this.selectedDates = [];
this.rangeDateFrom = null;
this.rangeDateTo = null;

this.isDestroyed = true;
}

/**
Expand Down
28 changes: 28 additions & 0 deletions tests/api.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,4 +264,32 @@ describe('API TESTS', () => {
expect(dp.disabledDates.size).toBe(0);
});
});

describe('destory', () => {
it('should destroy AirDatecpiker', () => {
init();

dp.destroy();

expect(dp.isDestroyed).toBe(true);
expect(dp.$datepicker).toBeNull();
});
it('should not throw error when calling destroy after selectDate', () => {
expect(() => {
init();

dp.selectDate(new Date());
dp.destroy();
}).not.toThrow();
});
it('should not throw error when calling destroy multiple times', () => {
expect(() => {
init();

dp.destroy();
dp.destroy();
dp.destroy();
}).not.toThrow();
});
});
});

0 comments on commit a788d34

Please sign in to comment.