@drayman/elements 1.57.0 → 1.58.0
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/README.md +1 -0
- package/dist/types/year-calendar/index.d.ts +17 -0
- package/dist/types/year-calendar/options.d.ts +24 -0
- package/dist/year-calendar/index.js +128 -0
- package/package.json +7 -2
- package/types/index.d.ts +39 -0
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@ Default drayman elements library.
|
|
|
33
33
|
- [drayman-nebula](interfaces/__global.draymannebulaprops.html)
|
|
34
34
|
- [drayman-code-editor](interfaces/__global.draymancodeeditorprops.html)
|
|
35
35
|
- [drayman-calendar](interfaces/__global.draymancalendarprops.html)
|
|
36
|
+
- [drayman-year-calendar](interfaces/__global.draymanyearcalendarprops.html)
|
|
36
37
|
|
|
37
38
|
## Installing
|
|
38
39
|
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface DraymanYearCalendar {
|
|
2
|
+
/**
|
|
3
|
+
* Executed when user clicks on a day.
|
|
4
|
+
*/
|
|
5
|
+
onDayClick?: ElementEvent<{
|
|
6
|
+
date: string;
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* Array of selected dates in YYYY-MM-DD format.
|
|
10
|
+
*/
|
|
11
|
+
selectedDates?: string[];
|
|
12
|
+
/**
|
|
13
|
+
* The year to display.
|
|
14
|
+
* If not provided, the current year will be used.
|
|
15
|
+
*/
|
|
16
|
+
year?: number;
|
|
17
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export interface DraymanYearCalendar {
|
|
2
|
+
/**
|
|
3
|
+
* Array of events to be displayed in the calendar.
|
|
4
|
+
*/
|
|
5
|
+
events?: {
|
|
6
|
+
title: string;
|
|
7
|
+
id: any;
|
|
8
|
+
color: string;
|
|
9
|
+
start: string;
|
|
10
|
+
end?: string;
|
|
11
|
+
}[];
|
|
12
|
+
/**
|
|
13
|
+
* Executed when user clicks on an event.
|
|
14
|
+
*/
|
|
15
|
+
onEventClick?: ElementEvent<{
|
|
16
|
+
id: any;
|
|
17
|
+
}>;
|
|
18
|
+
/**
|
|
19
|
+
* Executed when user clicks on a day.
|
|
20
|
+
*/
|
|
21
|
+
onDayClick?: ElementEvent<{
|
|
22
|
+
date: string;
|
|
23
|
+
}>;
|
|
24
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
class CalendarGrid extends HTMLElement {
|
|
2
|
+
constructor() {
|
|
3
|
+
super();
|
|
4
|
+
this.attachShadow({ mode: 'open' });
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
connectedCallback() {
|
|
8
|
+
this.render();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
render() {
|
|
12
|
+
const blocksPerRow = 4;
|
|
13
|
+
const blocksPerCol = 3;
|
|
14
|
+
const blockWidth = 7;
|
|
15
|
+
const blockHeight = 8;
|
|
16
|
+
const gap = 1;
|
|
17
|
+
const cellWidth = 40;
|
|
18
|
+
const cellHeight = 20;
|
|
19
|
+
const megaColumns = blocksPerRow * blockWidth + (blocksPerRow - 1) * gap;
|
|
20
|
+
const megaRows = blocksPerCol * blockHeight + (blocksPerCol - 1) * gap;
|
|
21
|
+
|
|
22
|
+
this.shadowRoot.innerHTML = '';
|
|
23
|
+
|
|
24
|
+
const style = document.createElement('style');
|
|
25
|
+
style.textContent = `
|
|
26
|
+
.calendar {
|
|
27
|
+
display: grid;
|
|
28
|
+
grid-template-columns: repeat(${megaColumns}, ${cellWidth}px);
|
|
29
|
+
grid-template-rows: repeat(${megaRows}, ${cellHeight}px);
|
|
30
|
+
gap: ${gap}px;
|
|
31
|
+
}
|
|
32
|
+
.cell {
|
|
33
|
+
display: flex;
|
|
34
|
+
align-items: center;
|
|
35
|
+
justify-content: center;
|
|
36
|
+
}
|
|
37
|
+
.cell.clickable {
|
|
38
|
+
cursor: pointer;
|
|
39
|
+
}
|
|
40
|
+
.cell.header {
|
|
41
|
+
font-weight: bold;
|
|
42
|
+
justify-content: center;
|
|
43
|
+
text-align: center;
|
|
44
|
+
white-space: nowrap;
|
|
45
|
+
overflow: hidden;
|
|
46
|
+
text-overflow: ellipsis;
|
|
47
|
+
}
|
|
48
|
+
.cell.weekday {
|
|
49
|
+
font-weight: bold;
|
|
50
|
+
background-color: #f0f0f0;
|
|
51
|
+
border-bottom: 1px solid #000;
|
|
52
|
+
}
|
|
53
|
+
.cell.selected {
|
|
54
|
+
background-color: red;
|
|
55
|
+
}
|
|
56
|
+
`;
|
|
57
|
+
this.shadowRoot.appendChild(style);
|
|
58
|
+
|
|
59
|
+
const container = document.createElement('div');
|
|
60
|
+
container.classList.add('calendar');
|
|
61
|
+
this.shadowRoot.appendChild(container);
|
|
62
|
+
|
|
63
|
+
const daysOfWeek = ['Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'];
|
|
64
|
+
|
|
65
|
+
for (let m = 1; m <= 12; m++) {
|
|
66
|
+
const monthIdx = m - 1;
|
|
67
|
+
const baseCol = (monthIdx % blocksPerRow) * (blockWidth + gap);
|
|
68
|
+
const baseRow = Math.floor(monthIdx / blocksPerRow) * (blockHeight + gap);
|
|
69
|
+
|
|
70
|
+
const firstDate = new Date(this.year, m - 1, 1);
|
|
71
|
+
const monthName = firstDate.toLocaleString('default', { month: 'long' });
|
|
72
|
+
const headerCell = this._createCell(container, baseRow, baseCol, '', monthName, ['cell', 'header']);
|
|
73
|
+
headerCell.style.gridColumnStart = baseCol + 1;
|
|
74
|
+
headerCell.style.gridColumnEnd = baseCol + 1 + blockWidth;
|
|
75
|
+
|
|
76
|
+
daysOfWeek.forEach((day, di) => {
|
|
77
|
+
this._createCell(container, baseRow + 1, baseCol + di, '', day, ['cell', 'weekday']);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
for (let i = 0; i < 42; i++) {
|
|
81
|
+
const dayNum = i - ((firstDate.getDay() + 6) % 7) + 1;
|
|
82
|
+
const r = baseRow + 2 + Math.floor(i / 7);
|
|
83
|
+
const c = baseCol + (i % 7);
|
|
84
|
+
let dateStr = '';
|
|
85
|
+
let txt = '';
|
|
86
|
+
if (dayNum > 0 && dayNum <= new Date(this.year, m, 0).getDate()) {
|
|
87
|
+
const yyyy = this.year;
|
|
88
|
+
const mm = String(m).padStart(2, '0');
|
|
89
|
+
const dd = String(dayNum).padStart(2, '0');
|
|
90
|
+
dateStr = `${yyyy}-${mm}-${dd}`;
|
|
91
|
+
txt = String(dayNum);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const classes = ['cell'];
|
|
95
|
+
if (dateStr) classes.push('clickable');
|
|
96
|
+
if (this.selectedDates.includes(dateStr)) classes.push('selected');
|
|
97
|
+
|
|
98
|
+
const cell = this._createCell(container, r, c, dateStr, txt, classes);
|
|
99
|
+
if (dateStr) {
|
|
100
|
+
cell.addEventListener('click', () => {
|
|
101
|
+
const idx = this.selectedDates.indexOf(dateStr);
|
|
102
|
+
if (idx > -1) {
|
|
103
|
+
this.selectedDates.splice(idx, 1);
|
|
104
|
+
cell.classList.remove('selected');
|
|
105
|
+
} else {
|
|
106
|
+
this.selectedDates.push(dateStr);
|
|
107
|
+
cell.classList.add('selected');
|
|
108
|
+
}
|
|
109
|
+
this.onDayClick?.({ date: dateStr });
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
_createCell(container, row, col, date, content, classes) {
|
|
117
|
+
const cell = document.createElement('div');
|
|
118
|
+
cell.textContent = content;
|
|
119
|
+
cell.dataset.date = date;
|
|
120
|
+
cell.classList.add(...classes);
|
|
121
|
+
cell.style.gridRowStart = row + 1;
|
|
122
|
+
cell.style.gridColumnStart = col + 1;
|
|
123
|
+
container.appendChild(cell);
|
|
124
|
+
return cell;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
customElements.define('drayman-year-calendar', CalendarGrid);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drayman/elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.58.0",
|
|
4
4
|
"description": "A collection of web components for Drayman.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"keywords": [
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"build:types": "tsc -p ./tsconfig.types.json",
|
|
13
13
|
"typedoc": "npm run build:types && typedoc --tsconfig ./tsconfig.types.json",
|
|
14
14
|
"lint": "ng lint",
|
|
15
|
-
"build": "npm run build:calendar && npm run build:code-editor && npm run build:button && npm run build:text-field && npm run build:claviz-charts && npm run build:file-uploader && npm run build:number-field && npm run build:select && npm run build:table && npm run build:checkbox && npm run build:slider && npm run build:textarea-field && npm run build:radio-group && npm run build:datepicker && npm run build:timepicker && npm run build:pdf-viewer && npm run build:ngx-charts && npm run build:menu && npm run build:ngx-graph && npm run build:youtube-player && npm run build:nebula && npm run build:grid && npm run build:gauge && npm run typedoc",
|
|
15
|
+
"build": "npm run build:calendar && npm run build:code-editor && npm run build:button && npm run build:text-field && npm run build:claviz-charts && npm run build:file-uploader && npm run build:number-field && npm run build:select && npm run build:table && npm run build:checkbox && npm run build:slider && npm run build:textarea-field && npm run build:radio-group && npm run build:datepicker && npm run build:timepicker && npm run build:pdf-viewer && npm run build:ngx-charts && npm run build:menu && npm run build:ngx-graph && npm run build:youtube-player && npm run build:nebula && npm run build:grid && npm run build:gauge && npm run build:year-calendar && npm run typedoc",
|
|
16
16
|
"build:code-editor": "ng build code-editor --extra-webpack-config webpack.partial.js --configuration production --single-bundle --output-hashing=none",
|
|
17
17
|
"build:calendar": "ng build calendar --configuration production --single-bundle --output-hashing=none",
|
|
18
18
|
"build:button": "ng build button --configuration production --single-bundle --output-hashing=none",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"build:ngx-charts": "ng build ngx-charts --configuration production --single-bundle --output-hashing=none",
|
|
37
37
|
"build:ngx-graph": "ng build ngx-graph --configuration production --single-bundle --output-hashing=none",
|
|
38
38
|
"build:menu": "ng build menu --configuration production --single-bundle --output-hashing=none",
|
|
39
|
+
"build:year-calendar": "cpx \"projects/year-calendar/index.js\" dist/year-calendar",
|
|
39
40
|
"create-element": "./element-generator/create.sh",
|
|
40
41
|
"e2e": "ng e2e"
|
|
41
42
|
},
|
|
@@ -53,6 +54,9 @@
|
|
|
53
54
|
"drayman-calendar": {
|
|
54
55
|
"script": "./dist/calendar/main.js"
|
|
55
56
|
},
|
|
57
|
+
"drayman-year-calendar": {
|
|
58
|
+
"script": "./dist/year-calendar/index.js"
|
|
59
|
+
},
|
|
56
60
|
"drayman-code-editor": {
|
|
57
61
|
"script": "./dist/code-editor/main.js"
|
|
58
62
|
},
|
|
@@ -151,6 +155,7 @@
|
|
|
151
155
|
"claviz-charts": "0.5.0",
|
|
152
156
|
"codelyzer": "^6.0.0",
|
|
153
157
|
"codemirror": "5.65.2",
|
|
158
|
+
"cpx": "^1.5.0",
|
|
154
159
|
"d3-require": "1.2.4",
|
|
155
160
|
"date-fns": "2.29.2",
|
|
156
161
|
"dayjs": "1.9.6",
|
package/types/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { DraymanClavizCharts } from '../dist/types/claviz-charts/src/app/models/
|
|
|
3
3
|
import { DraymanDatepicker } from '../dist/types/datepicker/src/app/models/datepicker-options';
|
|
4
4
|
import { DraymanGauge } from '../dist/types/gauge/src/app/models/gauge-options';
|
|
5
5
|
import { DraymanFileUploader } from '../dist/types/file-uploader/src/app/models/file-uploader-options';
|
|
6
|
+
import { DraymanYearCalendar } from '../dist/types/year-calendar/options';
|
|
6
7
|
import { DraymanMenu } from '../dist/types/menu/src/app/models/menu-options';
|
|
7
8
|
import { DraymanNgxCharts } from '../dist/types/ngx-charts/src/app/models/ngx-charts-options';
|
|
8
9
|
import { DraymanNgxGraph } from '../dist/types/ngx-graph/src/app/models/ngx-graph-options';
|
|
@@ -313,6 +314,44 @@ declare global {
|
|
|
313
314
|
* ```
|
|
314
315
|
*/
|
|
315
316
|
interface DraymanSliderProps extends DraymanSlider, DraymanElementsProps { }
|
|
317
|
+
/**
|
|
318
|
+
* # <drayman-year-calendar \/>
|
|
319
|
+
*
|
|
320
|
+
* Year calendar.
|
|
321
|
+
*
|
|
322
|
+
* ## Example of usage
|
|
323
|
+
*
|
|
324
|
+
* ### Year calendar with selected dates.
|
|
325
|
+
* 
|
|
326
|
+
*
|
|
327
|
+
* ```typescript
|
|
328
|
+
* export const component: DraymanComponent = async ({ forceUpdate }) => {
|
|
329
|
+
*
|
|
330
|
+
* let selectedDates = ['2025-01-01'];
|
|
331
|
+
*
|
|
332
|
+
* return () => {
|
|
333
|
+
* return (
|
|
334
|
+
* <div>
|
|
335
|
+
* <p>Selected dates count: {selectedDates.length}</p>
|
|
336
|
+
* <drayman-year-calendar
|
|
337
|
+
* selectedDates={selectedDates}
|
|
338
|
+
* year={2025}
|
|
339
|
+
* onDayClick={async ({ date }) => {
|
|
340
|
+
* if (selectedDates.includes(date)) {
|
|
341
|
+
* selectedDates = selectedDates.filter((d) => d !== date);
|
|
342
|
+
* } else {
|
|
343
|
+
* selectedDates.push(date);
|
|
344
|
+
* }
|
|
345
|
+
* await forceUpdate();
|
|
346
|
+
* }}
|
|
347
|
+
* />
|
|
348
|
+
* </div>
|
|
349
|
+
* );
|
|
350
|
+
* }
|
|
351
|
+
* }
|
|
352
|
+
* ```
|
|
353
|
+
*/
|
|
354
|
+
interface DraymanYearCalendarProps extends DraymanYearCalendar, DraymanElementsProps { }
|
|
316
355
|
/**
|
|
317
356
|
* # <drayman-claviz-charts \/>
|
|
318
357
|
*
|