@omegagrid/calendar 0.10.2 → 0.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +48 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/options.d.ts +11 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +21 -0
- package/dist/options.js.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/calendar.d.ts +31 -0
- package/dist/ui/calendar.d.ts.map +1 -0
- package/dist/ui/calendar.js +348 -0
- package/dist/ui/calendar.js.map +1 -0
- package/dist/ui/calendar.style.d.ts +2 -0
- package/dist/ui/calendar.style.d.ts.map +1 -0
- package/dist/ui/calendar.style.js +48 -0
- package/dist/ui/calendar.style.js.map +1 -0
- package/dist/ui/dropdown.d.ts +25 -0
- package/dist/ui/dropdown.d.ts.map +1 -0
- package/dist/ui/dropdown.js +162 -0
- package/dist/ui/dropdown.js.map +1 -0
- package/dist/ui/dropdown.style.d.ts +2 -0
- package/dist/ui/dropdown.style.d.ts.map +1 -0
- package/dist/ui/dropdown.style.js +42 -0
- package/dist/ui/dropdown.style.js.map +1 -0
- package/dist/ui/index.d.ts +3 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +3 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/utils.d.ts +12 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +36 -0
- package/dist/utils.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
declare const _default: {
|
|
2
|
+
PREFIX: string;
|
|
3
|
+
DEFAULT_ACCENT_COLOR: string;
|
|
4
|
+
DEFAULT_ACCENT_COLOR_2: import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | import("color")<string | number | any | ArrayLike<number> | {
|
|
5
|
+
[key: string]: any;
|
|
6
|
+
}> | ArrayLike<number> | {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
}> | ArrayLike<number> | {
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}> | ArrayLike<number> | {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}> | ArrayLike<number> | {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}> | ArrayLike<number> | {
|
|
15
|
+
[key: string]: any;
|
|
16
|
+
}> | ArrayLike<number> | {
|
|
17
|
+
[key: string]: any;
|
|
18
|
+
}> | ArrayLike<number> | {
|
|
19
|
+
[key: string]: any;
|
|
20
|
+
}> | ArrayLike<number> | {
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
}> | ArrayLike<number> | {
|
|
23
|
+
[key: string]: any;
|
|
24
|
+
}> | ArrayLike<number> | {
|
|
25
|
+
[key: string]: any;
|
|
26
|
+
}> | ArrayLike<number> | {
|
|
27
|
+
[key: string]: any;
|
|
28
|
+
}>;
|
|
29
|
+
SIZER_SIZE: number;
|
|
30
|
+
SLIDER_SIZE: number;
|
|
31
|
+
SLIDER_MIN_LENGTH: number;
|
|
32
|
+
EXPANDER_SIZE: number;
|
|
33
|
+
LIST_ITEM_HEIGHT: number;
|
|
34
|
+
LIST_RENDERING_TRESHOLD: number;
|
|
35
|
+
LIST_AUTOSCROLL_TRESHOLD: number;
|
|
36
|
+
LIST_AUTOSCROLL_DELAY: number;
|
|
37
|
+
DEFAULT_TEXT_HIGHLIGHT_COLOR: string;
|
|
38
|
+
TOOLTIP_MARGIN: number;
|
|
39
|
+
MENU_ITEM_HEIGHT: number;
|
|
40
|
+
COLORPICKER_COLOR_SIZE: number;
|
|
41
|
+
DEFAULT_NUMBER_FORMAT: string;
|
|
42
|
+
BUTTON_HEIGHT: number;
|
|
43
|
+
FONT_SIZE: number;
|
|
44
|
+
FLOATING_WINDOW_MAX_WIDTH: number;
|
|
45
|
+
HEADER_HEIGHT: number;
|
|
46
|
+
};
|
|
47
|
+
export default _default;
|
|
48
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,wBAGE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE7D,eAAe;IACd,aAAa,EAAE,EAAE;IACjB,GAAG,aAAa;CAChB,CAAC","sourcesContent":["import { constants as coreConstants } from '@omegagrid/core';\n\nexport default {\n\tHEADER_HEIGHT: 22,\n\t...coreConstants\n};"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC","sourcesContent":["export * from './ui';"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CommonOptions, VerticalPosition } from "@omegagrid/core";
|
|
2
|
+
import type { Day } from "date-fns";
|
|
3
|
+
export type Options = {
|
|
4
|
+
minDate: Date;
|
|
5
|
+
maxDate: Date;
|
|
6
|
+
weekStart: Day;
|
|
7
|
+
todayButton: boolean;
|
|
8
|
+
controlsPosition: VerticalPosition;
|
|
9
|
+
} & CommonOptions;
|
|
10
|
+
export declare function initOptions(options?: Partial<Options>, origOptions?: Options): Options;
|
|
11
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,aAAa,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAGpC,MAAM,MAAM,OAAO,GAAG;IACrB,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,IAAI,CAAC;IACd,SAAS,EAAE,GAAG,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;IACrB,gBAAgB,EAAE,gBAAgB,CAAA;CAClC,GAAG,aAAa,CAAA;AAUjB,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,WAAW,GAAE,OAAc,GAAG,OAAO,CAY5F"}
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { initCommonOptions } from "@omegagrid/core";
|
|
2
|
+
import { endOfWeek, startOfWeek } from "date-fns";
|
|
3
|
+
const DEFAULT_OPTIONS = {
|
|
4
|
+
minDate: new Date(1900, 0, 1, 0, 0, 0),
|
|
5
|
+
maxDate: new Date(2100, 11, 31, 0, 0, 0),
|
|
6
|
+
weekStart: 1, // Monday
|
|
7
|
+
todayButton: true,
|
|
8
|
+
controlsPosition: 'top'
|
|
9
|
+
};
|
|
10
|
+
export function initOptions(options, origOptions = null) {
|
|
11
|
+
const opts = {
|
|
12
|
+
...initCommonOptions(options, origOptions),
|
|
13
|
+
...DEFAULT_OPTIONS,
|
|
14
|
+
...origOptions,
|
|
15
|
+
...options,
|
|
16
|
+
};
|
|
17
|
+
opts.minDate = startOfWeek(opts.minDate, { weekStartsOn: opts.weekStart });
|
|
18
|
+
opts.maxDate = endOfWeek(opts.maxDate, { weekStartsOn: opts.weekStart });
|
|
19
|
+
return opts;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAmC,MAAM,iBAAiB,CAAC;AAErF,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAUlD,MAAM,eAAe,GAAqB;IACzC,OAAO,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACtC,OAAO,EAAE,IAAI,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACxC,SAAS,EAAE,CAAC,EAAE,SAAS;IACvB,WAAW,EAAE,IAAI;IACjB,gBAAgB,EAAE,KAAK;CACvB,CAAC;AAEF,MAAM,UAAU,WAAW,CAAC,OAA0B,EAAE,cAAuB,IAAI;IAClF,MAAM,IAAI,GAAG;QACZ,GAAG,iBAAiB,CAAC,OAAO,EAAE,WAAW,CAAC;QAC1C,GAAG,eAAe;QAClB,GAAG,WAAW;QACd,GAAG,OAAO;KACV,CAAC;IAEF,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;IAC3E,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;IAEzE,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["import { initCommonOptions, CommonOptions, VerticalPosition } from \"@omegagrid/core\";\nimport type { Day } from \"date-fns\";\nimport { endOfWeek, startOfWeek } from \"date-fns\";\n\nexport type Options = {\n\tminDate: Date,\n\tmaxDate: Date,\n\tweekStart: Day,\n\ttodayButton: boolean,\n\tcontrolsPosition: VerticalPosition\n} & CommonOptions\n\nconst DEFAULT_OPTIONS: Partial<Options> = {\n\tminDate: new Date(1900, 0, 1, 0, 0, 0),\n\tmaxDate: new Date(2100, 11, 31, 0, 0, 0),\n\tweekStart: 1, // Monday\n\ttodayButton: true,\n\tcontrolsPosition: 'top'\n};\n\nexport function initOptions(options?: Partial<Options>, origOptions: Options = null): Options {\n\tconst opts = {\n\t\t...initCommonOptions(options, origOptions),\n\t\t...DEFAULT_OPTIONS,\n\t\t...origOptions,\n\t\t...options,\n\t};\n\n\topts.minDate = startOfWeek(opts.minDate, { weekStartsOn: opts.weekStart });\n\topts.maxDate = endOfWeek(opts.maxDate, { weekStartsOn: opts.weekStart });\n\n\treturn opts;\n}"]}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":[""]}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { DropdownList, Layout, OmegaComponent } from '@omegagrid/core';
|
|
2
|
+
import { Grid } from '@omegagrid/grid';
|
|
3
|
+
import { Options } from '../options';
|
|
4
|
+
export declare class Calendar extends OmegaComponent implements Layout {
|
|
5
|
+
#private;
|
|
6
|
+
static styles: import("lit").CSSResult[];
|
|
7
|
+
body: HTMLDivElement;
|
|
8
|
+
options: Options;
|
|
9
|
+
date: Date;
|
|
10
|
+
year: number;
|
|
11
|
+
month: number;
|
|
12
|
+
monthDropdown: DropdownList;
|
|
13
|
+
yearDropdown: DropdownList;
|
|
14
|
+
get dateFormatter(): (date: Date) => string;
|
|
15
|
+
get formattedDate(): string;
|
|
16
|
+
willUpdate(props: Map<string, unknown>): void;
|
|
17
|
+
connectedCallback(): void;
|
|
18
|
+
disconnectedCallback(): void;
|
|
19
|
+
updateBody(): void;
|
|
20
|
+
get grid(): Grid;
|
|
21
|
+
layout(): Promise<void>;
|
|
22
|
+
goto(date?: Date): void;
|
|
23
|
+
updated(props: Map<string, unknown>): void;
|
|
24
|
+
updateDate(date: Date, dispatchEvent?: boolean): void;
|
|
25
|
+
gotoCurrentSelection(): void;
|
|
26
|
+
addYear(offset: number): void;
|
|
27
|
+
addMonth(offset: number): void;
|
|
28
|
+
renderControls: () => import("lit-html").TemplateResult<1>;
|
|
29
|
+
render: () => Iterable<string | import("lit-html/directive").DirectiveResult<typeof import("lit-html/directives/cache").CacheDirective>>;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=calendar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar.d.ts","sourceRoot":"","sources":["../../src/ui/calendar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,cAAc,EAAsB,MAAM,iBAAiB,CAAC;AAK3F,OAAO,EAAqC,IAAI,EAA0C,MAAM,iBAAiB,CAAC;AAClH,OAAO,EAAE,OAAO,EAAe,MAAM,YAAY,CAAC;AAQlD,qBACa,QAAS,SAAQ,cAAe,YAAW,MAAM;;IAE7D,MAAM,CAAC,MAAM,4BAAW;IAGxB,IAAI,EAAE,cAAc,CAAC;IAGrB,OAAO,EAAE,OAAO,CAAC;IAGjB,IAAI,OAA0B;IAG9B,IAAI,SAA8B;IAGlC,KAAK,SAA+B;IAGpC,aAAa,EAAE,YAAY,CAAC;IAG5B,YAAY,EAAE,YAAY,CAAC;IAG3B,IAAI,aAAa,WADM,IAAI,KAAK,MAAM,CAMrC;IAED,IAAI,aAAa,WAGhB;IAMD,UAAU,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAMtC,iBAAiB;IAKjB,oBAAoB;IASpB,UAAU;IASV,IAAI,IAAI,SAaP;IAEK,MAAM;IASZ,IAAI,CAAC,IAAI,GAAE,IAAW;IAqEtB,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC;IAgBnC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,aAAa,UAAO;IAsB3C,oBAAoB;IAIpB,OAAO,CAAC,MAAM,EAAE,MAAM;IAQtB,QAAQ,CAAC,MAAM,EAAE,MAAM;IAavB,cAAc,6CAgFb;IAED,MAAM,mIAMC;CAEP"}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
13
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
14
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
15
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
16
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
17
|
+
};
|
|
18
|
+
var _Calendar_instances, _Calendar_dateFormatter, _Calendar_dispatchChangeEvent, _Calendar_calculateColumnWidth, _Calendar_calculateRowHeight, _Calendar_grid, _Calendar_gridInitialized, _Calendar_month, _Calendar_renderer, _Calendar_getSourceData, _Calendar_initInnerTable, _Calendar_onSelect, _Calendar_onRender, _Calendar_onSelectChange;
|
|
19
|
+
import { OmegaComponent, dates, dom, events } from '@omegagrid/core';
|
|
20
|
+
import { html } from 'lit';
|
|
21
|
+
import { customElement, property, query } from 'lit/decorators.js';
|
|
22
|
+
import { join } from 'lit/directives/join.js';
|
|
23
|
+
import { style } from './calendar.style';
|
|
24
|
+
import { CellRange } from '@omegagrid/grid';
|
|
25
|
+
import { initOptions } from '../options';
|
|
26
|
+
import { getNumberOfWeeks, getWeekDays, getDate, getYears, getMonthNames, getWeekOffset, getCellCoordsByDate } from '../utils';
|
|
27
|
+
import { format, isEqual, startOfDay } from 'date-fns';
|
|
28
|
+
import { guard } from 'lit/directives/guard.js';
|
|
29
|
+
import { cache } from 'lit/directives/cache.js';
|
|
30
|
+
import { msg } from '@omegagrid/localize';
|
|
31
|
+
import constants from '../constants';
|
|
32
|
+
let Calendar = class Calendar extends OmegaComponent {
|
|
33
|
+
constructor() {
|
|
34
|
+
super(...arguments);
|
|
35
|
+
_Calendar_instances.add(this);
|
|
36
|
+
this.date = startOfDay(new Date());
|
|
37
|
+
this.year = (new Date()).getFullYear();
|
|
38
|
+
this.month = (new Date()).getMonth() + 1;
|
|
39
|
+
_Calendar_dateFormatter.set(this, void 0);
|
|
40
|
+
_Calendar_dispatchChangeEvent.set(this, () => this.dispatchEvent(new events.ChangeEvent({ value: this.date })));
|
|
41
|
+
_Calendar_calculateColumnWidth.set(this, () => this.body.clientWidth / 7);
|
|
42
|
+
_Calendar_calculateRowHeight.set(this, () => (this.body.clientHeight - constants.HEADER_HEIGHT) / 6);
|
|
43
|
+
_Calendar_grid.set(this, void 0);
|
|
44
|
+
_Calendar_gridInitialized.set(this, false);
|
|
45
|
+
_Calendar_month.set(this, void 0);
|
|
46
|
+
_Calendar_renderer.set(this, (div, cell) => {
|
|
47
|
+
const date = getDate(cell.r, cell.c, this.options);
|
|
48
|
+
div.innerHTML = format(date, 'd');
|
|
49
|
+
div.style.lineHeight = dom.px(cell.row.height);
|
|
50
|
+
div.style.textAlign = 'center';
|
|
51
|
+
const month = date.getMonth();
|
|
52
|
+
if (__classPrivateFieldGet(this, _Calendar_month, "f") == null) {
|
|
53
|
+
__classPrivateFieldSet(this, _Calendar_month, (month + (date.getDate() < 10 ? 0 : 1)) % 12, "f");
|
|
54
|
+
this.month = __classPrivateFieldGet(this, _Calendar_month, "f") + 1;
|
|
55
|
+
date.setDate(date.getDate() + 10);
|
|
56
|
+
this.year = date.getFullYear();
|
|
57
|
+
}
|
|
58
|
+
if (__classPrivateFieldGet(this, _Calendar_month, "f") == month) {
|
|
59
|
+
div.style.backgroundColor = 'initial';
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
div.style.backgroundColor = 'var(--og-background-color-3)';
|
|
63
|
+
}
|
|
64
|
+
return div;
|
|
65
|
+
});
|
|
66
|
+
_Calendar_onSelect.set(this, (e) => {
|
|
67
|
+
if (e.selection.activeCell) {
|
|
68
|
+
this.updateDate(getDate(e.selection.range.r1, e.selection.range.c1, this.options));
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
_Calendar_onRender.set(this, () => __classPrivateFieldSet(this, _Calendar_month, null, "f"));
|
|
72
|
+
_Calendar_onSelectChange.set(this, async () => {
|
|
73
|
+
this.month = this.monthDropdown.value;
|
|
74
|
+
this.year = this.yearDropdown.value;
|
|
75
|
+
await this.updateComplete;
|
|
76
|
+
this.gotoCurrentSelection();
|
|
77
|
+
});
|
|
78
|
+
this.renderControls = () => html `
|
|
79
|
+
<div class="header">
|
|
80
|
+
${this.date ? html `
|
|
81
|
+
<og-button
|
|
82
|
+
class="date"
|
|
83
|
+
color="transparent"
|
|
84
|
+
.text="${this.formattedDate}"
|
|
85
|
+
@click="${() => this.goto(this.date)}">
|
|
86
|
+
</og-button>
|
|
87
|
+
` : ''}
|
|
88
|
+
|
|
89
|
+
${this.options.todayButton ? html `
|
|
90
|
+
<og-button
|
|
91
|
+
style="flex: 1; text-align: center"
|
|
92
|
+
class="today"
|
|
93
|
+
color="transparent"
|
|
94
|
+
.text="${msg('today')}"
|
|
95
|
+
@click="${() => this.updateDate(new Date())}">
|
|
96
|
+
</og-button>
|
|
97
|
+
` : html `
|
|
98
|
+
<div style="flex: 1"></div>
|
|
99
|
+
`}
|
|
100
|
+
|
|
101
|
+
${guard([this.month], () => html `
|
|
102
|
+
<og-button
|
|
103
|
+
class="left"
|
|
104
|
+
icon="caret-left"
|
|
105
|
+
color="accent"
|
|
106
|
+
@click="${() => this.addMonth(-1)}">
|
|
107
|
+
</og-button>
|
|
108
|
+
|
|
109
|
+
<og-dropdown-list
|
|
110
|
+
noCaret
|
|
111
|
+
class="month"
|
|
112
|
+
color="accent"
|
|
113
|
+
width="70"
|
|
114
|
+
style="width: 60px; text-align: center"
|
|
115
|
+
@change="${__classPrivateFieldGet(this, _Calendar_onSelectChange, "f")}"
|
|
116
|
+
.value="${this.month?.toString()}"
|
|
117
|
+
.items="${getMonthNames(this.options).map((name, i) => ({ key: (i + 1).toString(), value: name }))}">
|
|
118
|
+
</og-dropdown-list>
|
|
119
|
+
|
|
120
|
+
<og-button
|
|
121
|
+
class="right"
|
|
122
|
+
icon="caret-right"
|
|
123
|
+
color="accent"
|
|
124
|
+
@click="${() => this.addMonth(1)}">
|
|
125
|
+
</og-button>
|
|
126
|
+
`)}
|
|
127
|
+
|
|
128
|
+
${guard([this.year], () => html `
|
|
129
|
+
<og-button
|
|
130
|
+
class="left"
|
|
131
|
+
icon="caret-left"
|
|
132
|
+
color="accent"
|
|
133
|
+
style="margin-left: 10px"
|
|
134
|
+
@click="${() => this.addYear(-1)}">
|
|
135
|
+
</og-button>
|
|
136
|
+
|
|
137
|
+
<og-dropdown-list
|
|
138
|
+
noCaret
|
|
139
|
+
width="50"
|
|
140
|
+
class="year"
|
|
141
|
+
color="accent"
|
|
142
|
+
style="min-width: 35px; text-align: center"
|
|
143
|
+
alignment="left"
|
|
144
|
+
@change="${__classPrivateFieldGet(this, _Calendar_onSelectChange, "f")}"
|
|
145
|
+
.value="${this.year.toString()}"
|
|
146
|
+
.items="${getYears(this.options).map(y => ({ key: y.toString(), value: y.toString() }))}">
|
|
147
|
+
</og-dropdown-list>
|
|
148
|
+
|
|
149
|
+
<og-button
|
|
150
|
+
class="right"
|
|
151
|
+
icon="caret-right"
|
|
152
|
+
color="accent"
|
|
153
|
+
style="margin-right: 5px"
|
|
154
|
+
@click="${() => this.addYear(1)}">
|
|
155
|
+
</og-button>
|
|
156
|
+
`)}
|
|
157
|
+
</div>
|
|
158
|
+
`;
|
|
159
|
+
this.render = () => join(this.options.controlsPosition != 'top' ? [
|
|
160
|
+
cache(html `<div class="body"></div>`),
|
|
161
|
+
this.renderControls()
|
|
162
|
+
] : [
|
|
163
|
+
this.renderControls(),
|
|
164
|
+
cache(html `<div class="body"></div>`)
|
|
165
|
+
], '');
|
|
166
|
+
}
|
|
167
|
+
get dateFormatter() {
|
|
168
|
+
if (!__classPrivateFieldGet(this, _Calendar_dateFormatter, "f")) {
|
|
169
|
+
__classPrivateFieldSet(this, _Calendar_dateFormatter, dates.getDateFormatter(this.options.locale, this.options.dateFormat), "f");
|
|
170
|
+
}
|
|
171
|
+
return __classPrivateFieldGet(this, _Calendar_dateFormatter, "f");
|
|
172
|
+
}
|
|
173
|
+
get formattedDate() {
|
|
174
|
+
if (!this.date)
|
|
175
|
+
return '';
|
|
176
|
+
return this.dateFormatter(this.date);
|
|
177
|
+
}
|
|
178
|
+
willUpdate(props) {
|
|
179
|
+
if (props.has('options') || !this.options) {
|
|
180
|
+
this.options = initOptions(this.options);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
connectedCallback() {
|
|
184
|
+
super.connectedCallback();
|
|
185
|
+
this.updateBody();
|
|
186
|
+
}
|
|
187
|
+
disconnectedCallback() {
|
|
188
|
+
if (this.body)
|
|
189
|
+
dom.empty(this.body);
|
|
190
|
+
__classPrivateFieldSet(this, _Calendar_grid, null, "f");
|
|
191
|
+
}
|
|
192
|
+
updateBody() {
|
|
193
|
+
if (!this.body)
|
|
194
|
+
return;
|
|
195
|
+
if (this.body.firstElementChild != this.grid) {
|
|
196
|
+
dom.empty(this.body);
|
|
197
|
+
this.grid.setSourceData(__classPrivateFieldGet(this, _Calendar_instances, "m", _Calendar_getSourceData).call(this));
|
|
198
|
+
this.body.appendChild(this.grid);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
get grid() {
|
|
202
|
+
if (__classPrivateFieldGet(this, _Calendar_grid, "f"))
|
|
203
|
+
return __classPrivateFieldGet(this, _Calendar_grid, "f");
|
|
204
|
+
__classPrivateFieldSet(this, _Calendar_grid, dom.createElement('og-grid'), "f");
|
|
205
|
+
dom.setInset(__classPrivateFieldGet(this, _Calendar_grid, "f"), 0);
|
|
206
|
+
__classPrivateFieldGet(this, _Calendar_grid, "f").addEventListener('grid.select', __classPrivateFieldGet(this, _Calendar_onSelect, "f"));
|
|
207
|
+
__classPrivateFieldGet(this, _Calendar_grid, "f").addEventListener('grid.render', __classPrivateFieldGet(this, _Calendar_onRender, "f"));
|
|
208
|
+
__classPrivateFieldGet(this, _Calendar_grid, "f").addEventListener('grid.init', () => {
|
|
209
|
+
const coords = getCellCoordsByDate(this.date, this.options);
|
|
210
|
+
this.grid?.selecting.select(new CellRange(coords.column, coords.row));
|
|
211
|
+
this.goto();
|
|
212
|
+
__classPrivateFieldSet(this, _Calendar_gridInitialized, true, "f");
|
|
213
|
+
});
|
|
214
|
+
return __classPrivateFieldGet(this, _Calendar_grid, "f");
|
|
215
|
+
}
|
|
216
|
+
async layout() {
|
|
217
|
+
await this.updateComplete;
|
|
218
|
+
const columnWidth = __classPrivateFieldGet(this, _Calendar_calculateColumnWidth, "f").call(this);
|
|
219
|
+
const rowHeight = __classPrivateFieldGet(this, _Calendar_calculateRowHeight, "f").call(this);
|
|
220
|
+
this.grid.model.columns.forEach((row) => row.width = columnWidth);
|
|
221
|
+
this.grid.model.rows.forEach((row) => row.height = rowHeight);
|
|
222
|
+
this.grid.layout();
|
|
223
|
+
}
|
|
224
|
+
goto(date = null) {
|
|
225
|
+
__classPrivateFieldSet(this, _Calendar_month, null, "f");
|
|
226
|
+
date = date ?? this.date ?? new Date();
|
|
227
|
+
this.year = date.getFullYear();
|
|
228
|
+
this.month = date.getMonth() + 1;
|
|
229
|
+
__classPrivateFieldGet(this, _Calendar_grid, "f").rendering.scrollTo(getWeekOffset(date, this.options), 0);
|
|
230
|
+
}
|
|
231
|
+
updated(props) {
|
|
232
|
+
this.updateBody();
|
|
233
|
+
if (props.has('options')) {
|
|
234
|
+
this.grid?.setSourceData(__classPrivateFieldGet(this, _Calendar_instances, "m", _Calendar_getSourceData).call(this));
|
|
235
|
+
}
|
|
236
|
+
if (props.has('date') && __classPrivateFieldGet(this, _Calendar_gridInitialized, "f")) {
|
|
237
|
+
const coords = getCellCoordsByDate(this.date, this.options);
|
|
238
|
+
this.grid?.selecting.select(new CellRange(coords.column, coords.row));
|
|
239
|
+
this.goto();
|
|
240
|
+
}
|
|
241
|
+
this.grid.updateComplete.then(() => __classPrivateFieldGet(this, _Calendar_instances, "m", _Calendar_initInnerTable).call(this, this.grid.table));
|
|
242
|
+
}
|
|
243
|
+
updateDate(date, dispatchEvent = true) {
|
|
244
|
+
date = startOfDay(date);
|
|
245
|
+
if (isEqual(date, this.date))
|
|
246
|
+
return;
|
|
247
|
+
this.date = date;
|
|
248
|
+
if (dispatchEvent)
|
|
249
|
+
__classPrivateFieldGet(this, _Calendar_dispatchChangeEvent, "f").call(this);
|
|
250
|
+
}
|
|
251
|
+
gotoCurrentSelection() {
|
|
252
|
+
this.goto(new Date(this.year, this.month - 1, 1, 0, 0, 0));
|
|
253
|
+
}
|
|
254
|
+
addYear(offset) {
|
|
255
|
+
this.year = Math.max(this.options.minDate.getFullYear(), Math.min(this.options.maxDate.getFullYear(), this.year + offset));
|
|
256
|
+
this.gotoCurrentSelection();
|
|
257
|
+
}
|
|
258
|
+
addMonth(offset) {
|
|
259
|
+
if (this.month + offset > 12) {
|
|
260
|
+
this.month = 1;
|
|
261
|
+
this.addYear(1);
|
|
262
|
+
}
|
|
263
|
+
else if (this.month + offset < 1) {
|
|
264
|
+
this.month = 12;
|
|
265
|
+
this.addYear(-1);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
this.month += offset;
|
|
269
|
+
this.gotoCurrentSelection();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
_Calendar_dateFormatter = new WeakMap();
|
|
274
|
+
_Calendar_dispatchChangeEvent = new WeakMap();
|
|
275
|
+
_Calendar_calculateColumnWidth = new WeakMap();
|
|
276
|
+
_Calendar_calculateRowHeight = new WeakMap();
|
|
277
|
+
_Calendar_grid = new WeakMap();
|
|
278
|
+
_Calendar_gridInitialized = new WeakMap();
|
|
279
|
+
_Calendar_month = new WeakMap();
|
|
280
|
+
_Calendar_renderer = new WeakMap();
|
|
281
|
+
_Calendar_onSelect = new WeakMap();
|
|
282
|
+
_Calendar_onRender = new WeakMap();
|
|
283
|
+
_Calendar_onSelectChange = new WeakMap();
|
|
284
|
+
_Calendar_instances = new WeakSet();
|
|
285
|
+
_Calendar_getSourceData = function _Calendar_getSourceData() {
|
|
286
|
+
return {
|
|
287
|
+
columns: getWeekDays(this.options).map(day => ({
|
|
288
|
+
renderer: __classPrivateFieldGet(this, _Calendar_renderer, "f"),
|
|
289
|
+
header: [{ label: day, height: constants.HEADER_HEIGHT }]
|
|
290
|
+
})),
|
|
291
|
+
options: {
|
|
292
|
+
rows: getNumberOfWeeks(this.options),
|
|
293
|
+
rowHeight: __classPrivateFieldGet(this, _Calendar_calculateRowHeight, "f").call(this),
|
|
294
|
+
columnWidth: __classPrivateFieldGet(this, _Calendar_calculateColumnWidth, "f").call(this),
|
|
295
|
+
colLetters: false,
|
|
296
|
+
rowNumbers: false,
|
|
297
|
+
rowResize: false,
|
|
298
|
+
columnResize: false,
|
|
299
|
+
autofill: false,
|
|
300
|
+
cellCache: false,
|
|
301
|
+
singleCellModel: true,
|
|
302
|
+
selecting: {
|
|
303
|
+
enabled: true,
|
|
304
|
+
multiSelect: false,
|
|
305
|
+
},
|
|
306
|
+
scrolling: {
|
|
307
|
+
verticalOverscroll: false,
|
|
308
|
+
horizontalOverscroll: false,
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
};
|
|
312
|
+
};
|
|
313
|
+
_Calendar_initInnerTable = function _Calendar_initInnerTable(table) {
|
|
314
|
+
if (table.dataset.init)
|
|
315
|
+
return;
|
|
316
|
+
table.dataset.init = '1';
|
|
317
|
+
dom.appendStyle(table.shadowRoot, `td:hover>div {
|
|
318
|
+
border: 2px solid var(--og-accent-color);
|
|
319
|
+
cursor: pointer;
|
|
320
|
+
}`);
|
|
321
|
+
};
|
|
322
|
+
Calendar.styles = [style];
|
|
323
|
+
__decorate([
|
|
324
|
+
query('.body')
|
|
325
|
+
], Calendar.prototype, "body", void 0);
|
|
326
|
+
__decorate([
|
|
327
|
+
property({ type: Object })
|
|
328
|
+
], Calendar.prototype, "options", void 0);
|
|
329
|
+
__decorate([
|
|
330
|
+
property({ type: Object })
|
|
331
|
+
], Calendar.prototype, "date", void 0);
|
|
332
|
+
__decorate([
|
|
333
|
+
property({ type: Number })
|
|
334
|
+
], Calendar.prototype, "year", void 0);
|
|
335
|
+
__decorate([
|
|
336
|
+
property({ type: Number })
|
|
337
|
+
], Calendar.prototype, "month", void 0);
|
|
338
|
+
__decorate([
|
|
339
|
+
query('og-dropdown-list.month')
|
|
340
|
+
], Calendar.prototype, "monthDropdown", void 0);
|
|
341
|
+
__decorate([
|
|
342
|
+
query('og-dropdown-list.year')
|
|
343
|
+
], Calendar.prototype, "yearDropdown", void 0);
|
|
344
|
+
Calendar = __decorate([
|
|
345
|
+
customElement('og-calendar')
|
|
346
|
+
], Calendar);
|
|
347
|
+
export { Calendar };
|
|
348
|
+
//# sourceMappingURL=calendar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar.js","sourceRoot":"","sources":["../../src/ui/calendar.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,OAAO,EAAwB,cAAc,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AAC9C,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EAAa,SAAS,EAA6D,MAAM,iBAAiB,CAAC;AAClH,OAAO,EAAW,WAAW,EAAE,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/H,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,yBAA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AG5B;IADC,KAAK,CAAC,uBAAuB,CAAC;8CACJ;AAvBf,QAAQ;IADpB,aAAa,CAAC,aAAa,CAAC;GAChB,QAAQ,CA6TpB","sourcesContent":["import { DropdownList, Layout, OmegaComponent, dates, dom, events } from '@omegagrid/core';\nimport { html } from 'lit';\nimport { customElement, property, query } from 'lit/decorators.js';\nimport { join } from 'lit/directives/join.js';\nimport { style } from './calendar.style';\nimport { CellModel, CellRange, ColumnModel, Grid, GridEvent, GridSource, RowModel, Table } from '@omegagrid/grid';\nimport { Options, initOptions } from '../options';\nimport { getNumberOfWeeks, getWeekDays, getDate, getYears, getMonthNames, getWeekOffset, getCellCoordsByDate } from '../utils';\nimport { format, isEqual, startOfDay } from 'date-fns';\nimport { guard } from 'lit/directives/guard.js';\nimport { cache } from 'lit/directives/cache.js';\nimport { msg } from '@omegagrid/localize';\nimport constants from '../constants';\n\n@customElement('og-calendar')\nexport class Calendar extends OmegaComponent implements Layout {\n\n\tstatic styles = [style];\n\n\t@query('.body')\n\tbody: HTMLDivElement;\n\n\t@property({type: Object})\n\toptions: Options;\n\n\t@property({type: Object})\n\tdate = startOfDay(new Date());\n\n\t@property({type: Number})\n\tyear = (new Date()).getFullYear();\n\n\t@property({type: Number})\n\tmonth = (new Date()).getMonth() + 1;\n\n\t@query('og-dropdown-list.month')\n\tmonthDropdown: DropdownList;\n\n\t@query('og-dropdown-list.year')\n\tyearDropdown: DropdownList;\n\n\t#dateFormatter: (date: Date) => string;\n\tget dateFormatter() {\n\t\tif (!this.#dateFormatter) {\n\t\t\tthis.#dateFormatter = dates.getDateFormatter(this.options.locale, this.options.dateFormat);\n\t\t}\n\t\treturn this.#dateFormatter;\n\t}\n\n\tget formattedDate() {\n\t\tif (!this.date) return '';\n\t\treturn this.dateFormatter(this.date);\n\t}\n\n\t#dispatchChangeEvent = () => this.dispatchEvent(new events.ChangeEvent({value: this.date}));\n\t#calculateColumnWidth = () => this.body.clientWidth / 7;\n\t#calculateRowHeight = () => (this.body.clientHeight - constants.HEADER_HEIGHT) / 6;\n\n\twillUpdate(props: Map<string, unknown>) {\n\t\tif (props.has('options') || !this.options) {\t\n\t\t\tthis.options = initOptions(this.options);\n\t\t}\n\t}\n\n\tconnectedCallback() {\n\t\tsuper.connectedCallback();\n\t\tthis.updateBody();\n\t}\n\n\tdisconnectedCallback() {\n\t\tif (this.body) dom.empty(this.body);\n\t\tthis.#grid = null;\n\t}\n\n\t#grid: Grid;\n\t#gridInitialized = false;\n\t#month: number;\n\n\tupdateBody() {\n\t\tif (!this.body) return;\n\t\tif (this.body.firstElementChild != this.grid) {\n\t\t\tdom.empty(this.body);\n\t\t\tthis.grid.setSourceData(this.#getSourceData());\n\t\t\tthis.body.appendChild(this.grid);\n\t\t}\n\t}\n\n\tget grid() { \n\t\tif (this.#grid) return this.#grid;\n\t\tthis.#grid = dom.createElement<Grid>('og-grid');\n\t\tdom.setInset(this.#grid, 0);\n\t\tthis.#grid.addEventListener('grid.select', this.#onSelect);\n\t\tthis.#grid.addEventListener('grid.render', this.#onRender);\n\t\tthis.#grid.addEventListener('grid.init', () => {\n\t\t\tconst coords = getCellCoordsByDate(this.date, this.options);\n\t\t\tthis.grid?.selecting.select(new CellRange(coords.column, coords.row));\n\t\t\tthis.goto();\n\t\t\tthis.#gridInitialized = true;\n\t\t});\n\t\treturn this.#grid;\n\t}\n\n\tasync layout() {\n\t\tawait this.updateComplete;\n\t\tconst columnWidth = this.#calculateColumnWidth();\n\t\tconst rowHeight = this.#calculateRowHeight();\n\t\tthis.grid.model.columns.forEach((row: ColumnModel) => row.width = columnWidth);\n\t\tthis.grid.model.rows.forEach((row: RowModel) => row.height = rowHeight);\n\t\tthis.grid.layout();\n\t}\n\n\tgoto(date: Date = null) {\n\t\tthis.#month = null;\n\t\tdate = date ?? this.date ?? new Date();\n\t\tthis.year = date.getFullYear();\n\t\tthis.month = date.getMonth() + 1;\n\t\tthis.#grid.rendering.scrollTo(getWeekOffset(date, this.options), 0);\n\t}\n\n\t#renderer = (div: HTMLDivElement, cell: CellModel) => {\n\t\tconst date = getDate(cell.r, cell.c, this.options);\n\t\tdiv.innerHTML = format(date, 'd');\n\t\tdiv.style.lineHeight = dom.px(cell.row.height);\n\t\tdiv.style.textAlign = 'center';\n\t\tconst month = date.getMonth();\n\n\t\tif (this.#month == null) {\n\t\t\tthis.#month = (month + (date.getDate() < 10 ? 0 : 1)) % 12;\n\t\t\tthis.month = this.#month + 1;\n\t\t\tdate.setDate(date.getDate() + 10);\n\t\t\tthis.year = date.getFullYear();\n\t\t}\n\n\t\tif (this.#month == month) {\n\t\t\tdiv.style.backgroundColor = 'initial';\n\t\t} else {\n\t\t\tdiv.style.backgroundColor = 'var(--og-background-color-3)';\n\t\t}\n\n\t\treturn div;\n\t}\n\n\t#getSourceData(): GridSource {\n\t\treturn {\n\t\t\tcolumns: getWeekDays(this.options).map(day => ({\n\t\t\t\trenderer: this.#renderer, \n\t\t\t\theader: [{label: day, height: constants.HEADER_HEIGHT}]\n\t\t\t})),\n\t\t\toptions: {\n\t\t\t\trows: getNumberOfWeeks(this.options),\n\t\t\t\trowHeight: this.#calculateRowHeight(),\n\t\t\t\tcolumnWidth: this.#calculateColumnWidth(),\n\t\t\t\tcolLetters: false,\n\t\t\t\trowNumbers: false,\n\t\t\t\trowResize: false,\n\t\t\t\tcolumnResize: false,\n\t\t\t\tautofill: false,\n\t\t\t\tcellCache: false,\n\t\t\t\tsingleCellModel: true,\n\t\t\t\tselecting: {\n\t\t\t\t\tenabled: true,\n\t\t\t\t\tmultiSelect: false,\n\t\t\t\t},\n\t\t\t\tscrolling: {\n\t\t\t\t\tverticalOverscroll: false,\n\t\t\t\t\thorizontalOverscroll: false,\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t}\n\n\t#initInnerTable(table: Table) {\n\t\tif (table.dataset.init) return;\n\t\ttable.dataset.init = '1';\n\t\tdom.appendStyle(table.shadowRoot, `td:hover>div { \n\t\t\tborder: 2px solid var(--og-accent-color);\n\t\t\tcursor: pointer;\n\t\t}`);\n\t}\n\n\tupdated(props: Map<string, unknown>) {\n\t\tthis.updateBody();\n\n\t\tif (props.has('options')) {\t\n\t\t\tthis.grid?.setSourceData(this.#getSourceData());\n\t\t}\n\n\t\tif (props.has('date') && this.#gridInitialized) {\n\t\t\tconst coords = getCellCoordsByDate(this.date, this.options);\n\t\t\tthis.grid?.selecting.select(new CellRange(coords.column, coords.row));\n\t\t\tthis.goto();\n\t\t}\n\n\t\tthis.grid.updateComplete.then(() => this.#initInnerTable(this.grid.table));\n\t}\n\n\tupdateDate(date: Date, dispatchEvent = true) {\n\t\tdate = startOfDay(date);\n\t\tif (isEqual(date, this.date)) return;\n\t\tthis.date = date;\n\t\tif (dispatchEvent) this.#dispatchChangeEvent();\n\t}\n\n\t#onSelect = (e: GridEvent) => {\n\t\tif (e.selection.activeCell) {\n\t\t\tthis.updateDate(getDate(e.selection.range.r1, e.selection.range.c1, this.options));\n\t\t}\n\t}\n\n\t#onRender = (): void => this.#month = null;\n\n\t#onSelectChange = async () => {\n\t\tthis.month = this.monthDropdown.value as number;\n\t\tthis.year = this.yearDropdown.value as number;\n\t\tawait this.updateComplete;\n\t\tthis.gotoCurrentSelection();\n\t}\n\n\tgotoCurrentSelection() {\n\t\tthis.goto(new Date(this.year, this.month - 1, 1, 0, 0, 0));\n\t}\n\n\taddYear(offset: number) {\n\t\tthis.year = Math.max(\n\t\t\tthis.options.minDate.getFullYear(), \n\t\t\tMath.min(this.options.maxDate.getFullYear(), this.year + offset)\n\t\t);\n\t\tthis.gotoCurrentSelection();\n\t}\n\n\taddMonth(offset: number) {\n\t\tif (this.month + offset > 12) {\n\t\t\tthis.month = 1;\n\t\t\tthis.addYear(1);\n\t\t} else if (this.month + offset < 1) {\n\t\t\tthis.month = 12;\n\t\t\tthis.addYear(-1);\n\t\t} else {\n\t\t\tthis.month += offset;\n\t\t\tthis.gotoCurrentSelection();\n\t\t}\n\t}\n\n\trenderControls = () => html`\n\t\t<div class=\"header\">\n\t\t\t${this.date ? html`\n\t\t\t\t<og-button \n\t\t\t\t\tclass=\"date\" \n\t\t\t\t\tcolor=\"transparent\"\n\t\t\t\t\t.text=\"${this.formattedDate}\"\n\t\t\t\t\t@click=\"${() => this.goto(this.date)}\">\n\t\t\t\t</og-button>\t\n\t\t\t` : ''}\n\t\t\t\n\t\t\t${this.options.todayButton ? html`\n\t\t\t\t<og-button \n\t\t\t\t\tstyle=\"flex: 1; text-align: center\"\n\t\t\t\t\tclass=\"today\" \n\t\t\t\t\tcolor=\"transparent\"\n\t\t\t\t\t.text=\"${msg('today')}\"\n\t\t\t\t\t@click=\"${() => this.updateDate(new Date())}\">\n\t\t\t\t</og-button>\t\n\t\t\t` : html`\n\t\t\t\t<div style=\"flex: 1\"></div>\n\t\t\t`}\n\n\t\t\t${guard([this.month], () => html`\n\t\t\t\t<og-button \n\t\t\t\t\tclass=\"left\" \n\t\t\t\t\ticon=\"caret-left\"\n\t\t\t\t\tcolor=\"accent\"\n\t\t\t\t\t@click=\"${() => this.addMonth(-1)}\">\n\t\t\t\t</og-button>\n\t\t\t\t\n\t\t\t\t<og-dropdown-list\n\t\t\t\t\tnoCaret\n\t\t\t\t\tclass=\"month\"\n\t\t\t\t\tcolor=\"accent\"\n\t\t\t\t\twidth=\"70\"\n\t\t\t\t\tstyle=\"width: 60px; text-align: center\"\n\t\t\t\t\t@change=\"${this.#onSelectChange}\"\n\t\t\t\t\t.value=\"${this.month?.toString()}\"\n\t\t\t\t\t.items=\"${getMonthNames(this.options).map((name, i) => ({key: (i + 1).toString(), value: name}))}\">\n\t\t\t\t</og-dropdown-list>\n\t\t\t\t\n\t\t\t\t<og-button \n\t\t\t\t\tclass=\"right\" \n\t\t\t\t\ticon=\"caret-right\" \n\t\t\t\t\tcolor=\"accent\"\n\t\t\t\t\t@click=\"${() => this.addMonth(1)}\">\n\t\t\t\t</og-button>\n\t\t\t`)}\n\n\t\t\t${guard([this.year], () => html`\n\t\t\t\t<og-button \n\t\t\t\t\tclass=\"left\" \n\t\t\t\t\ticon=\"caret-left\" \n\t\t\t\t\tcolor=\"accent\" \n\t\t\t\t\tstyle=\"margin-left: 10px\"\n\t\t\t\t\t@click=\"${() => this.addYear(-1)}\">\n\t\t\t\t</og-button>\n\t\t\t\t\n\t\t\t\t<og-dropdown-list\n\t\t\t\t\tnoCaret\n\t\t\t\t\twidth=\"50\"\n\t\t\t\t\tclass=\"year\"\n\t\t\t\t\tcolor=\"accent\"\n\t\t\t\t\tstyle=\"min-width: 35px; text-align: center\"\n\t\t\t\t\talignment=\"left\"\n\t\t\t\t\t@change=\"${this.#onSelectChange}\"\n\t\t\t\t\t.value=\"${this.year.toString()}\"\n\t\t\t\t\t.items=\"${getYears(this.options).map(y => ({key: y.toString(), value: y.toString()}))}\">\n\t\t\t\t</og-dropdown-list>\n\n\t\t\t\t<og-button \n\t\t\t\t\tclass=\"right\" \n\t\t\t\t\ticon=\"caret-right\" \n\t\t\t\t\tcolor=\"accent\" \n\t\t\t\t\tstyle=\"margin-right: 5px\"\n\t\t\t\t\t@click=\"${() => this.addYear(1)}\">\n\t\t\t\t</og-button>\n\t\t\t`)}\n\t\t</div>\n\t`\n\n\trender = () => join(this.options.controlsPosition != 'top' ? [\n\t\tcache(html`<div class=\"body\"></div>`),\n\t\tthis.renderControls()\n\t] : [\n\t\tthis.renderControls(),\n\t\tcache(html`<div class=\"body\"></div>`)\n\t], '');\n\n}"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar.style.d.ts","sourceRoot":"","sources":["../../src/ui/calendar.style.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,KAAK,yBA4CjB,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { css } from 'lit';
|
|
2
|
+
import constants from '../constants';
|
|
3
|
+
export const style = css `
|
|
4
|
+
* {
|
|
5
|
+
box-sizing: border-box;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
:host {
|
|
9
|
+
display: flex;
|
|
10
|
+
flex-direction: column;
|
|
11
|
+
font-family: var(--og-font-family);
|
|
12
|
+
font-size: var(--og-font-size);
|
|
13
|
+
min-height: 200px;
|
|
14
|
+
min-width: 280px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.header {
|
|
18
|
+
flex: 0 0 ${constants.HEADER_HEIGHT}px;
|
|
19
|
+
background: var(--og-accent-color);
|
|
20
|
+
color: #ffffff;
|
|
21
|
+
display: flex;
|
|
22
|
+
flex-direction: row;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.body {
|
|
26
|
+
flex: 1;
|
|
27
|
+
overflow: hidden;
|
|
28
|
+
position: relative;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
og-grid {
|
|
32
|
+
width: 100%;
|
|
33
|
+
height: 100%;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
og-button {
|
|
37
|
+
padding-left: 5px;
|
|
38
|
+
padding-right: 5px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
og-button.left, og-button.right {
|
|
42
|
+
width: 10px;
|
|
43
|
+
padding-left: 2px;
|
|
44
|
+
padding-right: 2px;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
`;
|
|
48
|
+
//# sourceMappingURL=calendar.style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar.style.js","sourceRoot":"","sources":["../../src/ui/calendar.style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,SAAS,MAAM,cAAc,CAAC;AAErC,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;cAeV,SAAS,CAAC,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BpC,CAAC","sourcesContent":["import { css } from 'lit';\nimport constants from '../constants';\n\nexport const style = css`\n\t* {\n\t\tbox-sizing: border-box;\n\t}\n\n\t:host {\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t\tfont-family: var(--og-font-family);\n\t\tfont-size: var(--og-font-size);\n\t\tmin-height: 200px;\n\t\tmin-width: 280px;\n\t}\n\n\t.header {\n\t\tflex: 0 0 ${constants.HEADER_HEIGHT}px;\n\t\tbackground: var(--og-accent-color);\n\t\tcolor: #ffffff;\n\t\tdisplay: flex;\n\t\tflex-direction: row;\n\t}\n\n\t.body {\n\t\tflex: 1;\n\t\toverflow: hidden;\n\t\tposition: relative;\n\t}\n\n\tog-grid {\n\t\twidth: 100%;\n\t\theight: 100%;\n\t}\n\n\tog-button {\n\t\tpadding-left: 5px;\n\t\tpadding-right: 5px;\n\t}\n\n\tog-button.left, og-button.right {\n\t\twidth: 10px;\n\t\tpadding-left: 2px;\n\t\tpadding-right: 2px;\n\t}\n\t\n`;"]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Dropdown, Input } from "@omegagrid/core";
|
|
2
|
+
import { Options } from "../options";
|
|
3
|
+
import { Calendar } from "./calendar";
|
|
4
|
+
export declare class CalendarDropdown extends Dropdown {
|
|
5
|
+
#private;
|
|
6
|
+
static styles: import("lit").CSSResult[];
|
|
7
|
+
calendarOptions: Options;
|
|
8
|
+
buttonInput: boolean;
|
|
9
|
+
get value(): Date;
|
|
10
|
+
set value(value: Date);
|
|
11
|
+
cross: boolean;
|
|
12
|
+
input: Input;
|
|
13
|
+
get hasCrossButton(): boolean;
|
|
14
|
+
get calendar(): Calendar;
|
|
15
|
+
open(initialValue?: string): Promise<void>;
|
|
16
|
+
clearValue(dispatchEvent?: boolean): void;
|
|
17
|
+
_onInputFocus: () => void;
|
|
18
|
+
parseDate(value: string): Date;
|
|
19
|
+
_onInputBlur: () => void;
|
|
20
|
+
_onInput: () => void;
|
|
21
|
+
_onInputKeydown: (e: KeyboardEvent) => void;
|
|
22
|
+
layout(): void;
|
|
23
|
+
render: () => import("lit-html").TemplateResult<1>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=dropdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropdown.d.ts","sourceRoot":"","sources":["../../src/ui/dropdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAsB,MAAM,iBAAiB,CAAC;AAEtE,OAAO,EAAe,OAAO,EAAE,MAAM,YAAY,CAAC;AAGlD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,qBACa,gBAAiB,SAAQ,QAAQ;;IAE7C,MAAM,CAAC,MAAM,4BAA+B;IAG5C,eAAe,EAAE,OAAO,CAErB;IAGH,WAAW,UAAS;IAGpB,IACI,KAAK,IACQ,IAAI,CADa;IAClC,IAAI,KAAK,CAAC,KAAK,EAAE,IAAI,EAMpB;IAGD,KAAK,UAAS;IAGd,KAAK,EAAE,KAAK,CAAC;IAIb,IAAI,cAAc,YAEjB;IAED,IAAI,QAAQ,aAaX;IAEK,IAAI,CAAC,YAAY,GAAE,MAAa;IAQtC,UAAU,CAAC,aAAa,UAAO;IAM/B,aAAa,aAEZ;IAED,SAAS,CAAC,KAAK,EAAE,MAAM;IAIvB,YAAY,aAOX;IAED,QAAQ,aAGP;IAED,eAAe,GAAI,GAAG,aAAa,UAKlC;IAED,MAAM;IAKN,MAAM,6CAgCJ;CACF"}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
13
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
14
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
15
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
16
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
17
|
+
};
|
|
18
|
+
var _CalendarDropdown_value, _CalendarDropdown_calendar;
|
|
19
|
+
import { Dropdown, dates, dom, events } from "@omegagrid/core";
|
|
20
|
+
import { customElement, property, query } from "lit/decorators.js";
|
|
21
|
+
import { initOptions } from "../options";
|
|
22
|
+
import { html } from "lit";
|
|
23
|
+
import { style } from "./dropdown.style";
|
|
24
|
+
import { unsafeHTML } from "lit/directives/unsafe-html.js";
|
|
25
|
+
let CalendarDropdown = class CalendarDropdown extends Dropdown {
|
|
26
|
+
constructor() {
|
|
27
|
+
super(...arguments);
|
|
28
|
+
this.calendarOptions = initOptions({
|
|
29
|
+
controlsPosition: 'bottom'
|
|
30
|
+
});
|
|
31
|
+
this.buttonInput = false;
|
|
32
|
+
_CalendarDropdown_value.set(this, void 0);
|
|
33
|
+
this.cross = false;
|
|
34
|
+
_CalendarDropdown_calendar.set(this, void 0);
|
|
35
|
+
this._onInputFocus = () => {
|
|
36
|
+
this.open();
|
|
37
|
+
};
|
|
38
|
+
this._onInputBlur = () => {
|
|
39
|
+
const newDate = this.parseDate(this.input.value);
|
|
40
|
+
if (newDate == null)
|
|
41
|
+
this.input.value = '';
|
|
42
|
+
if (newDate?.getTime() !== __classPrivateFieldGet(this, _CalendarDropdown_value, "f")?.getTime()) {
|
|
43
|
+
__classPrivateFieldSet(this, _CalendarDropdown_value, newDate, "f");
|
|
44
|
+
this.dispatchEvent(new events.ChangeEvent({ value: this.value }));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
this._onInput = () => {
|
|
48
|
+
const newDate = this.parseDate(this.input.value);
|
|
49
|
+
if (newDate)
|
|
50
|
+
__classPrivateFieldGet(this, _CalendarDropdown_calendar, "f").date = newDate;
|
|
51
|
+
};
|
|
52
|
+
this._onInputKeydown = (e) => {
|
|
53
|
+
if (e.key === 'Enter') {
|
|
54
|
+
this.input.blur();
|
|
55
|
+
this.close();
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
this.render = () => html `
|
|
59
|
+
${this.buttonInput ? html `
|
|
60
|
+
<og-input
|
|
61
|
+
@keydown="${this._onInputKeydown}"
|
|
62
|
+
@focus="${this._onInputFocus}"
|
|
63
|
+
@input="${this._onInput}"
|
|
64
|
+
@blur="${this._onInputBlur}"
|
|
65
|
+
.value="${this.calendar?.formattedDate || ''}">
|
|
66
|
+
</og-input>
|
|
67
|
+
` : html `
|
|
68
|
+
<og-button
|
|
69
|
+
.caret="${this.noCaret ? 'none' : 'down'}"
|
|
70
|
+
color="${this.color}"
|
|
71
|
+
class="main"
|
|
72
|
+
style="flex: 1; text-align: center;"
|
|
73
|
+
@mousedown="${this._onMousedown}">
|
|
74
|
+
<div class="content" slot="content">
|
|
75
|
+
${this.calendar?.formattedDate || unsafeHTML(' ')}
|
|
76
|
+
</div>
|
|
77
|
+
</og-button>
|
|
78
|
+
`}
|
|
79
|
+
|
|
80
|
+
${this.hasCrossButton ? html `
|
|
81
|
+
<og-button
|
|
82
|
+
class="cross"
|
|
83
|
+
@mousedown="${() => this.clearValue(true)}"
|
|
84
|
+
icon="xmark"
|
|
85
|
+
color="red">
|
|
86
|
+
</og-button>
|
|
87
|
+
` : ``}
|
|
88
|
+
|
|
89
|
+
${this.renderDropdown()}
|
|
90
|
+
`;
|
|
91
|
+
}
|
|
92
|
+
get value() { return __classPrivateFieldGet(this, _CalendarDropdown_value, "f"); }
|
|
93
|
+
set value(value) {
|
|
94
|
+
__classPrivateFieldSet(this, _CalendarDropdown_value, value, "f");
|
|
95
|
+
if (__classPrivateFieldGet(this, _CalendarDropdown_calendar, "f")) {
|
|
96
|
+
__classPrivateFieldGet(this, _CalendarDropdown_calendar, "f").date = value;
|
|
97
|
+
this.requestUpdate();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
get hasCrossButton() {
|
|
101
|
+
return this.cross && __classPrivateFieldGet(this, _CalendarDropdown_value, "f") != null;
|
|
102
|
+
}
|
|
103
|
+
get calendar() {
|
|
104
|
+
if (__classPrivateFieldGet(this, _CalendarDropdown_calendar, "f"))
|
|
105
|
+
return __classPrivateFieldGet(this, _CalendarDropdown_calendar, "f");
|
|
106
|
+
__classPrivateFieldSet(this, _CalendarDropdown_calendar, dom.createElement('og-calendar'), "f");
|
|
107
|
+
__classPrivateFieldGet(this, _CalendarDropdown_calendar, "f").date = __classPrivateFieldGet(this, _CalendarDropdown_value, "f");
|
|
108
|
+
__classPrivateFieldGet(this, _CalendarDropdown_calendar, "f").options = this.calendarOptions;
|
|
109
|
+
__classPrivateFieldGet(this, _CalendarDropdown_calendar, "f").slot = 'inner-content';
|
|
110
|
+
__classPrivateFieldGet(this, _CalendarDropdown_calendar, "f").addEventListener('change', (e) => {
|
|
111
|
+
__classPrivateFieldSet(this, _CalendarDropdown_value, e.value, "f");
|
|
112
|
+
this.close();
|
|
113
|
+
this.dispatchEvent(new events.ChangeEvent({ value: e.value }));
|
|
114
|
+
this.requestUpdate();
|
|
115
|
+
});
|
|
116
|
+
return __classPrivateFieldGet(this, _CalendarDropdown_calendar, "f");
|
|
117
|
+
}
|
|
118
|
+
async open(initialValue = null) {
|
|
119
|
+
if (initialValue != null)
|
|
120
|
+
this.input.value = initialValue;
|
|
121
|
+
await super.open();
|
|
122
|
+
if (this.calendar.parentElement != this.dropdown)
|
|
123
|
+
this.dropdown.appendChild(this.calendar);
|
|
124
|
+
this.layout();
|
|
125
|
+
}
|
|
126
|
+
clearValue(dispatchEvent = true) {
|
|
127
|
+
this.value = null;
|
|
128
|
+
this.close();
|
|
129
|
+
if (dispatchEvent)
|
|
130
|
+
this.dispatchEvent(new events.ChangeEvent({ value: null }));
|
|
131
|
+
}
|
|
132
|
+
parseDate(value) {
|
|
133
|
+
return dates.parse(value, this.calendarOptions.locale);
|
|
134
|
+
}
|
|
135
|
+
layout() {
|
|
136
|
+
super.layout();
|
|
137
|
+
this.calendar?.layout();
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
_CalendarDropdown_value = new WeakMap();
|
|
141
|
+
_CalendarDropdown_calendar = new WeakMap();
|
|
142
|
+
CalendarDropdown.styles = [...Dropdown.styles, style];
|
|
143
|
+
__decorate([
|
|
144
|
+
property({ type: Object })
|
|
145
|
+
], CalendarDropdown.prototype, "calendarOptions", void 0);
|
|
146
|
+
__decorate([
|
|
147
|
+
property({ type: Boolean })
|
|
148
|
+
], CalendarDropdown.prototype, "buttonInput", void 0);
|
|
149
|
+
__decorate([
|
|
150
|
+
property({ type: Object, noAccessor: true })
|
|
151
|
+
], CalendarDropdown.prototype, "value", null);
|
|
152
|
+
__decorate([
|
|
153
|
+
property({ type: Boolean, reflect: true })
|
|
154
|
+
], CalendarDropdown.prototype, "cross", void 0);
|
|
155
|
+
__decorate([
|
|
156
|
+
query('og-input')
|
|
157
|
+
], CalendarDropdown.prototype, "input", void 0);
|
|
158
|
+
CalendarDropdown = __decorate([
|
|
159
|
+
customElement('og-calendar-dropdown')
|
|
160
|
+
], CalendarDropdown);
|
|
161
|
+
export { CalendarDropdown };
|
|
162
|
+
//# sourceMappingURL=dropdown.js.map
|
|
@@ -0,0 +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a,CAAC,sBAAsB,CAAC;GACzB,gBAAgB,CAmI5B","sourcesContent":["import { Dropdown, Input, dates, dom, events } from \"@omegagrid/core\";\nimport { customElement, property, query } from \"lit/decorators.js\";\nimport { initOptions, Options } from \"../options\";\nimport { html } from \"lit\";\nimport { style } from \"./dropdown.style\";\nimport { Calendar } from \"./calendar\";\nimport { unsafeHTML } from \"lit/directives/unsafe-html.js\";\n\n@customElement('og-calendar-dropdown')\nexport class CalendarDropdown extends Dropdown {\n\n\tstatic styles = [...Dropdown.styles, style];\n\n\t@property({type: Object})\n\tcalendarOptions: Options = initOptions({\n\t\tcontrolsPosition: 'bottom'\n\t});\n\n\t@property({type: Boolean})\n\tbuttonInput = false;\n\n\t#value: Date;\n\t@property({type: Object, noAccessor: true})\n\tget value() { return this.#value }\n\tset value(value: Date) {\n\t\tthis.#value = value;\n\t\tif (this.#calendar) {\n\t\t\tthis.#calendar.date = value;\n\t\t\tthis.requestUpdate();\n\t\t}\n\t}\n\n\t@property({type: Boolean, reflect: true})\n\tcross = false;\n\n\t@query('og-input')\n\tinput: Input;\n\n\t#calendar: Calendar;\t\n\n\tget hasCrossButton() {\n\t\treturn this.cross && this.#value != null;\n\t}\n\n\tget calendar() {\n\t\tif (this.#calendar) return this.#calendar;\n\t\tthis.#calendar = dom.createElement<Calendar>('og-calendar');\n\t\tthis.#calendar.date = this.#value;\n\t\tthis.#calendar.options = this.calendarOptions;\n\t\tthis.#calendar.slot = 'inner-content';\n\t\tthis.#calendar.addEventListener('change', (e: events.ChangeEvent<Date>) => {\n\t\t\tthis.#value = e.value;\n\t\t\tthis.close();\n\t\t\tthis.dispatchEvent(new events.ChangeEvent({value: e.value}));\n\t\t\tthis.requestUpdate();\n\t\t});\n\t\treturn this.#calendar;\n\t}\n\n\tasync open(initialValue: string = null) {\n\t\tif (initialValue != null) this.input.value = initialValue;\n\n\t\tawait super.open();\n\t\tif (this.calendar.parentElement != this.dropdown) this.dropdown.appendChild(this.calendar);\n\t\tthis.layout();\n\t}\n\n\tclearValue(dispatchEvent = true) {\n\t\tthis.value = null;\n\t\tthis.close();\n\t\tif (dispatchEvent) this.dispatchEvent(new events.ChangeEvent({value: null}));\n\t}\n\n\t_onInputFocus = () => {\n\t\tthis.open();\n\t}\n\n\tparseDate(value: string) {\n\t\treturn dates.parse(value, this.calendarOptions.locale);\n\t}\n\n\t_onInputBlur = () => {\n\t\tconst newDate = this.parseDate(this.input.value);\n\t\tif (newDate == null) this.input.value = '';\n\t\tif (newDate?.getTime() !== this.#value?.getTime()) {\n\t\t\tthis.#value = newDate;\n\t\t\tthis.dispatchEvent(new events.ChangeEvent({value: this.value}));\n\t\t}\n\t}\n\t\n\t_onInput = () => {\n\t\tconst newDate = this.parseDate(this.input.value);\n\t\tif (newDate) this.#calendar.date = newDate;\n\t}\n\n\t_onInputKeydown = (e: KeyboardEvent) => {\n\t\tif (e.key === 'Enter') {\n\t\t\tthis.input.blur();\n\t\t\tthis.close();\n\t\t}\n\t}\n\n\tlayout() {\n\t\tsuper.layout();\n\t\tthis.calendar?.layout();\n\t}\n\n\trender = () => html`\n\t\t${this.buttonInput ? html`\n\t\t\t<og-input\n\t\t\t\t@keydown=\"${this._onInputKeydown}\"\n\t\t\t\t@focus=\"${this._onInputFocus}\"\n\t\t\t\t@input=\"${this._onInput}\"\n\t\t\t\t@blur=\"${this._onInputBlur}\"\n\t\t\t\t.value=\"${this.calendar?.formattedDate || ''}\">\n\t\t\t</og-input>\n\t\t` : html`\n\t\t\t<og-button\n\t\t\t\t.caret=\"${this.noCaret ? 'none' : 'down'}\"\n\t\t\t\tcolor=\"${this.color}\"\n\t\t\t\tclass=\"main\"\n\t\t\t\tstyle=\"flex: 1; text-align: center;\" \n\t\t\t\t@mousedown=\"${this._onMousedown}\">\n\t\t\t\t<div class=\"content\" slot=\"content\">\n\t\t\t\t\t${this.calendar?.formattedDate || unsafeHTML(' ')}\n\t\t\t\t</div>\n\t\t\t</og-button>\n\t\t`}\n\n\t\t${this.hasCrossButton ? html`\n\t\t\t<og-button\n\t\t\t\tclass=\"cross\"\n\t\t\t\t@mousedown=\"${() => this.clearValue(true)}\"\n\t\t\t\ticon=\"xmark\"\n\t\t\t\tcolor=\"red\">\n\t\t\t</og-button>\n\t\t` : ``}\n\n\t\t${this.renderDropdown()}\n\t`;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropdown.style.d.ts","sourceRoot":"","sources":["../../src/ui/dropdown.style.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,KAAK,yBAuCjB,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { css } from "lit";
|
|
2
|
+
export const style = css `
|
|
3
|
+
og-input {
|
|
4
|
+
flex: 1;
|
|
5
|
+
border: none;
|
|
6
|
+
outline: none;
|
|
7
|
+
background-color: var(--og-background-color);
|
|
8
|
+
color: var(--og-text-color);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
:host([cross]) og-button.main, og-input {
|
|
12
|
+
border-top-right-radius: 0;
|
|
13
|
+
border-bottom-right-radius: 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
og-button.cross {
|
|
17
|
+
border-width: 0;
|
|
18
|
+
border-left-width: 1px;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
og-input+og-button {
|
|
22
|
+
flex: 0;
|
|
23
|
+
max-width: 14px;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.cross {
|
|
27
|
+
flex: 0;
|
|
28
|
+
max-width: 14px;
|
|
29
|
+
min-width: 14px;
|
|
30
|
+
border: 1px solid var(--og-accent-color);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.caption, .placeholder {
|
|
34
|
+
color: var(--og-text-color-2);
|
|
35
|
+
opacity: 0.7;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.content {
|
|
39
|
+
display: flex;
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
//# sourceMappingURL=dropdown.style.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dropdown.style.js","sourceRoot":"","sources":["../../src/ui/dropdown.style.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE1B,MAAM,CAAC,MAAM,KAAK,GAAG,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuCvB,CAAC","sourcesContent":["import { css } from \"lit\";\n\nexport const style = css`\n\tog-input {\n\t\tflex: 1;\n\t\tborder: none;\n\t\toutline: none;\n\t\tbackground-color: var(--og-background-color);\n\t\tcolor: var(--og-text-color);\n\t}\n\n\t:host([cross]) og-button.main, og-input {\n\t\tborder-top-right-radius: 0;\n\t\tborder-bottom-right-radius: 0;\n\t}\n\n\tog-button.cross {\n\t\tborder-width: 0;\n\t\tborder-left-width: 1px;\n\t}\n\n\tog-input+og-button {\n\t\tflex: 0;\n\t\tmax-width: 14px;\n\t}\n\n\t.cross {\n\t\tflex: 0;\n\t\tmax-width: 14px;\n\t\tmin-width: 14px;\n\t\tborder: 1px solid var(--og-accent-color);\n\t}\n\n\t.caption, .placeholder {\n\t\tcolor: var(--og-text-color-2);\n\t\topacity: 0.7;\n\t}\n\n\t.content {\n\t\tdisplay: flex;\n\t}\n`;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC"}
|
package/dist/ui/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ui/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC","sourcesContent":["export * from './calendar';\nexport * from './dropdown';\n"]}
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Options } from "./options";
|
|
2
|
+
export declare function getNumberOfWeeks(options: Options): number;
|
|
3
|
+
export declare function getWeekDays(options: Options): string[];
|
|
4
|
+
export declare function getDate(row: number, column: number, options: Options): Date;
|
|
5
|
+
export declare function getYears(options: Options): number[];
|
|
6
|
+
export declare function getMonthNames(options: Options): string[];
|
|
7
|
+
export declare function getWeekOffset(date: Date, options: Options): number;
|
|
8
|
+
export declare function getCellCoordsByDate(date: Date, options: Options): {
|
|
9
|
+
row: number;
|
|
10
|
+
column: number;
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,UAEhD;AAED,wBAAgB,WAAW,CAAC,OAAO,EAAE,OAAO,YAK3C;AAED,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,QAEpE;AAED,wBAAgB,QAAQ,CAAC,OAAO,EAAE,OAAO,YAMxC;AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,OAAO,YAI7C;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,UAEzD;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO;;;EAK/D"}
|
package/dist/utils.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { eachDayOfInterval, format, startOfWeek, endOfWeek, differenceInDays, add, startOfMonth } from "date-fns";
|
|
2
|
+
import { dates } from "@omegagrid/core";
|
|
3
|
+
export function getNumberOfWeeks(options) {
|
|
4
|
+
return Math.ceil(differenceInDays(options.maxDate, options.minDate) / 7);
|
|
5
|
+
}
|
|
6
|
+
export function getWeekDays(options) {
|
|
7
|
+
return eachDayOfInterval({
|
|
8
|
+
start: startOfWeek(new Date(), { weekStartsOn: options.weekStart }),
|
|
9
|
+
end: endOfWeek(new Date(), { weekStartsOn: options.weekStart }),
|
|
10
|
+
}).map(date => format(date, 'cccccc', { locale: dates.getDateLocale(options.locale) }));
|
|
11
|
+
}
|
|
12
|
+
export function getDate(row, column, options) {
|
|
13
|
+
return add(options.minDate, { days: row * 7 + column });
|
|
14
|
+
}
|
|
15
|
+
export function getYears(options) {
|
|
16
|
+
const years = [];
|
|
17
|
+
for (let i = options.minDate.getFullYear(); i <= options.maxDate.getFullYear(); i++) {
|
|
18
|
+
years.push(i);
|
|
19
|
+
}
|
|
20
|
+
return years;
|
|
21
|
+
}
|
|
22
|
+
export function getMonthNames(options) {
|
|
23
|
+
return [...(new Array(12)).keys()].map(i => format(new Date(2000, i, 1), 'LLLL', {
|
|
24
|
+
locale: dates.getDateLocale(options.locale)
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
export function getWeekOffset(date, options) {
|
|
28
|
+
return Math.floor(differenceInDays(startOfMonth(date), options.minDate) / 7);
|
|
29
|
+
}
|
|
30
|
+
export function getCellCoordsByDate(date, options) {
|
|
31
|
+
return {
|
|
32
|
+
row: Math.floor(differenceInDays(date, options.minDate) / 7),
|
|
33
|
+
column: differenceInDays(date, options.minDate) % 7
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,EAAE,gBAAgB,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAElH,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAExC,MAAM,UAAU,gB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AAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE;QAChF,MAAM,EAAE,KAAK,CAAC,aAAa,CAAC,OAAO,CAAC,MAAM,CAAC;KAC3C,CAAC,CAAC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,IAAU,EAAE,OAAgB;IACzD,OAAO,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAU,EAAE,OAAgB;IAC/D,OAAO;QACN,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QAC5D,MAAM,EAAE,gBAAgB,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC;KACnD,CAAC;AACH,CAAC","sourcesContent":["import { eachDayOfInterval, format, startOfWeek, endOfWeek, differenceInDays, add, startOfMonth } from \"date-fns\";\nimport { Options } from \"./options\";\nimport { dates } from \"@omegagrid/core\";\n\nexport function getNumberOfWeeks(options: Options) {\n\treturn Math.ceil(differenceInDays(options.maxDate, options.minDate) / 7);\n}\n\nexport function getWeekDays(options: Options) {\n\treturn eachDayOfInterval({\n\t\tstart: startOfWeek(new Date(), {weekStartsOn: options.weekStart}), \n\t\tend: endOfWeek(new Date(), {weekStartsOn: options.weekStart}), \n\t}).map(date => format(date, 'cccccc', {locale: dates.getDateLocale(options.locale)}));\n}\n\nexport function getDate(row: number, column: number, options: Options) {\n\treturn add(options.minDate, {days: row * 7 + column});\n}\n\nexport function getYears(options: Options) {\n\tconst years = [];\n\tfor (let i = options.minDate.getFullYear(); i <= options.maxDate.getFullYear(); i++) {\n\t\tyears.push(i);\n\t}\n\treturn years;\n}\n\nexport function getMonthNames(options: Options) {\n\treturn [...(new Array(12)).keys()].map(i => format(new Date(2000, i, 1), 'LLLL', {\n\t\tlocale: dates.getDateLocale(options.locale)\n\t}));\n}\n\nexport function getWeekOffset(date: Date, options: Options) {\n\treturn Math.floor(differenceInDays(startOfMonth(date), options.minDate) / 7);\n}\n\nexport function getCellCoordsByDate(date: Date, options: Options) {\n\treturn {\n\t\trow: Math.floor(differenceInDays(date, options.minDate) / 7), \n\t\tcolumn: differenceInDays(date, options.minDate) % 7\n\t};\n}"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omegagrid/calendar",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.5",
|
|
4
4
|
"license": "UNLICENSED",
|
|
5
5
|
"description": "Calendar component",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
30
|
"@fortawesome/fontawesome-svg-core": "^7.0.1",
|
|
31
|
-
"@omegagrid/core": "^0.10.
|
|
32
|
-
"@omegagrid/grid": "^0.10.
|
|
33
|
-
"@omegagrid/grid-core": "^0.10.
|
|
34
|
-
"@omegagrid/localize": "^0.10.
|
|
31
|
+
"@omegagrid/core": "^0.10.5",
|
|
32
|
+
"@omegagrid/grid": "^0.10.5",
|
|
33
|
+
"@omegagrid/grid-core": "^0.10.5",
|
|
34
|
+
"@omegagrid/localize": "^0.10.5",
|
|
35
35
|
"date-fns": "^3.2.0",
|
|
36
36
|
"lit": "^3.1.1",
|
|
37
37
|
"ts-debounce": "^4.0.0"
|