Skip to content

Commit

Permalink
Release v2.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
uvarov-frontend committed Nov 8, 2022
1 parent fd5714e commit f746554
Show file tree
Hide file tree
Showing 9 changed files with 198 additions and 128 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ calendar.init();
<head>
</head>
<body>
<div id="calendar"></div>
<div class="vanilla-calendar" id="calendar"></div>
</body>
</html>
```
Expand All @@ -67,7 +67,7 @@ If you downloaded the files manually or decided to use a CDN, then instead of th
<script src="./vanilla-calendar.min.js" defer></script>
</head>
<body>
<div id="calendar"></div>
<div class="vanilla-calendar" id="calendar"></div>

<script>
document.addEventListener('DOMContentLoaded', () => {
Expand Down
2 changes: 1 addition & 1 deletion build/vanilla-calendar.min.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@uvarov.frontend/vanilla-calendar",
"version": "2.1.5",
"version": "2.1.6",
"description": "Vanilla JS calendar without using additional packages. A lightweight date and time picker written in pure JavaScript using TypeScript.",
"homepage": "https://vanilla-calendar.frontend.uvarov.tech/",
"keywords": [
Expand Down Expand Up @@ -36,9 +36,10 @@
"source": "./src/scripts/vanilla-calendar.ts",
"types": "./src/index.d.ts",
"scripts": {
"ssr-fix": "node ./ssr-fix.cjs",
"dev": "webpack",
"start": "webpack serve",
"build": "cross-env NODE_ENV=production webpack"
"build": "cross-env NODE_ENV=production webpack && npm run ssr-fix"
},
"devDependencies": {
"@types/node": "^18.11.0",
Expand All @@ -59,6 +60,7 @@
"postcss": "^8.4.18",
"postcss-loader": "^7.0.1",
"postcss-preset-env": "^7.8.2",
"replace-in-file": "^6.3.5",
"sass": "^1.55.0",
"sass-loader": "^13.1.0",
"terser-webpack-plugin": "^5.3.6",
Expand Down
77 changes: 19 additions & 58 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,65 +1,26 @@
import { FormatDateString } from './types';
import {
IActions, IDate, ILocale, IPopups, IRange, ISelected, ISelection, IVisibility,
} from './types';

export interface IOptions {
type Settings = {
lang: string;
iso8601: boolean;
range: Partial<IRange>;
selection: Partial<ISelection>;
selected: Partial<ISelected>;
visibility: Partial<IVisibility>;
}

export type Options = {
type?: string;
date?: {
min?: string;
max?: string;
today?: Date;
};
settings?: {
lang?: string;
iso8601?: boolean;
range?: {
min?: FormatDateString,
max?: FormatDateString,
disabled?: FormatDateString[] | null,
enabled?: FormatDateString[] | null,
};
selection?: {
day?: false | 'single' | 'multiple' | 'multiple-ranged';
month?: boolean;
year?: boolean;
time?: boolean | number;
controlTime?: 'all' | 'range';
stepHours?: number;
stepMinutes?: number;
};
selected?: {
dates?: FormatDateString[] | undefined | null;
month?: number | null;
year?: number | null;
holidays?: FormatDateString[] | null;
time?: string | null;
};
visibility?: {
templateHeader?: string;
monthShort?: boolean;
weekNumbers?: boolean;
weekend?: boolean;
today?: boolean;
disabled?: boolean;
};
};
locale?: {
months?: string[] | [];
weekday?: string[] | [];
};
actions?: {
clickDay?: ((e: MouseEvent, dates: string[] | undefined) => void) | null;
clickMonth?: ((e: MouseEvent, month: number) => void) | null;
clickYear?: ((e: MouseEvent, year: number) => void) | null;
changeTime?: ((e: Event, time: string, hours: string, minutes: string, keeping: string) => void) | null;
};
popups?: {
[date in FormatDateString]: {
modifier: string | null;
html: string;
} | null;
} | null;
date?: Partial<IDate>;
settings?: Partial<Settings>;
locale?: Partial<ILocale>;
actions?: Partial<IActions>;
popups?: IPopups | null;
}

declare class VanillaCalendar<T extends (HTMLElement | string), R extends IOptions> {
declare class VanillaCalendar<T extends (HTMLElement | string), R extends Partial<Options>> {
constructor(selector: T, option?: R)

update: () => void;
Expand Down
6 changes: 3 additions & 3 deletions src/scripts/vanilla-calendar.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FormatDateString, IOptionsRequire } from 'src/types';
import { FormatDateString, IOptions } from 'src/types';
import updateCalendar from './methods/updateCalendar';
import initCalendar from './methods/initCalendar';

export default class VanillaCalendar<T extends (HTMLElement | string), R extends IOptionsRequire> {
export default class VanillaCalendar<T extends (HTMLElement | string), R extends IOptions> {
HTMLElement: HTMLElement | null;

type!: string;
Expand Down Expand Up @@ -62,7 +62,7 @@ export default class VanillaCalendar<T extends (HTMLElement | string), R extends

popups!: {
[date in FormatDateString]: {
modifier: string | null;
modifier?: string | null;
html: string;
} | null;
} | null;
Expand Down
132 changes: 75 additions & 57 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,66 +4,84 @@ type MM = `0${oneToNine}` | `1${0|1|2}`;
type DD = `${0}${oneToNine}` | `${1|2}${zeroToNine}` | `3${0|1}`;
export type FormatDateString = `${number}-${MM}-${DD}`;

export interface IOptionsRequire {
type: string;
date: {
min: string;
max: string;
today: Date;
};
settings: {
lang: string;
iso8601: boolean;
range: {
min: FormatDateString,
max: FormatDateString,
disabled: FormatDateString[] | null,
enabled: FormatDateString[] | null,
};
selection: {
day: false | 'single' | 'multiple' | 'multiple-ranged';
month: boolean;
year: boolean;
time: boolean | number;
controlTime: 'all' | 'range';
stepHours: number;
stepMinutes: number;
};
selected: {
dates: FormatDateString[] | undefined | null;
month: number | null;
year: number | null;
holidays: FormatDateString[] | null;
time: string | null;
};
visibility: {
templateHeader: string;
monthShort: boolean;
weekNumbers: boolean;
weekend: boolean;
today: boolean;
disabled: boolean;
};
};
locale: {
months: string[] | [];
weekday: string[] | [];
};
actions: {
clickDay: ((e: MouseEvent, dates: string[] | undefined) => void) | null;
clickMonth: ((e: MouseEvent, month: number) => void) | null;
clickYear: ((e: MouseEvent, year: number) => void) | null;
changeTime: ((e: Event, time: string, hours: string, minutes: string, keeping: string) => void) | null;
};
popups: {
[date in FormatDateString]: {
modifier: string | null;
html: string;
} | null;
export interface IDate {
min: string;
max: string;
today: Date;
}

export interface IRange {
min: FormatDateString,
max: FormatDateString,
disabled: FormatDateString[] | null,
enabled: FormatDateString[] | null,
}

export interface ISelection {
day: false | 'single' | 'multiple' | 'multiple-ranged';
month: boolean;
year: boolean;
time: boolean | number;
controlTime: 'all' | 'range';
stepHours: number;
stepMinutes: number;
}

export interface ISelected {
dates: FormatDateString[] | undefined | null;
month: number | null;
year: number | null;
holidays: FormatDateString[] | null;
time: string | null;
}

export interface IVisibility {
templateHeader: string;
monthShort: boolean;
weekNumbers: boolean;
weekend: boolean;
today: boolean;
disabled: boolean;
}

export interface ISettings {
lang: string;
iso8601: boolean;
range: IRange;
selection: ISelection;
selected: ISelected;
visibility: IVisibility;
}

export interface ILocale {
months: string[] | [];
weekday: string[] | [];
}

export interface IActions {
clickDay: ((e: MouseEvent, dates: string[] | undefined) => void) | null;
clickMonth: ((e: MouseEvent, month: number) => void) | null;
clickYear: ((e: MouseEvent, year: number) => void) | null;
changeTime: ((e: Event, time: string, hours: string, minutes: string, keeping: string) => void) | null;
}

export type IPopups = {
[date in FormatDateString]: {
modifier?: string | null;
html: string;
} | null;
}

export interface IVariables extends IOptionsRequire {
export interface IOptions {
type: string;
date: IDate;
settings: ISettings;
locale: ILocale;
actions: IActions;
popups?: IPopups | null;
}

export interface IVariables extends IOptions {
HTMLElement: HTMLElement | null;
currentType: string;
selectedKeeping: string | null;
Expand Down
7 changes: 7 additions & 0 deletions ssr-fix.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const replace = require('replace-in-file');

replace({
files: './build/vanilla-calendar.min.js',
from: ['!function', '()));'],
to: ['if(typeof window!==\'undefined\'){!function', '()));}'],
});
5 changes: 4 additions & 1 deletion webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ const config: webpack.Configuration = {
clean: true,
path: path.resolve(__dirname, 'build'),
filename: isProd ? '[name].min.js' : '[name].js',
libraryTarget: 'umd',
library: {
type: 'umd2',
},
publicPath: '/',
},
optimization: {
Expand Down Expand Up @@ -65,6 +67,7 @@ const config: webpack.Configuration = {
module: {
rules: [
{
exclude: /node_modules/,
test: /\.ts$/i,
loader: 'esbuild-loader',
options: {
Expand Down
Loading

0 comments on commit f746554

Please sign in to comment.