@parksw/sw-ui-components 0.0.1 → 0.0.3
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/decorate-BnP3GfGh.js +7 -0
- package/dist/index.js +6 -3
- package/dist/my-button-BXW2ABd3.js +59 -0
- package/dist/my-button.js +2 -74
- package/dist/my-calendar-ylD4tbTZ.js +135 -0
- package/dist/my-calendar.js +2 -146
- package/dist/my-element-BWehTtOJ.js +23 -0
- package/dist/my-element.js +2 -33
- package/dist/my-grid-DduCSbuo.js +592 -0
- package/dist/my-grid.js +3 -0
- package/dist/vite.svg +1 -0
- package/package.json +10 -7
- package/dist/index.d.ts +0 -3
- package/dist/my-button.d.ts +0 -8
- package/dist/my-calendar.d.ts +0 -12
- package/dist/my-element.d.ts +0 -6
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
function __decorate(e, t, n, r) {
|
|
2
|
+
var i = arguments.length, a = i < 3 ? t : r === null ? r = Object.getOwnPropertyDescriptor(t, n) : r, o;
|
|
3
|
+
if (typeof Reflect == "object" && typeof Reflect.decorate == "function") a = Reflect.decorate(e, t, n, r);
|
|
4
|
+
else for (var s = e.length - 1; s >= 0; s--) (o = e[s]) && (a = (i < 3 ? o(a) : i > 3 ? o(t, n, a) : o(t, n)) || a);
|
|
5
|
+
return i > 3 && a && Object.defineProperty(t, n, a), a;
|
|
6
|
+
}
|
|
7
|
+
export { __decorate as t };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import "./decorate-BnP3GfGh.js";
|
|
2
|
+
import { t as MyElement } from "./my-element-BWehTtOJ.js";
|
|
3
|
+
import { t as MyButton } from "./my-button-BXW2ABd3.js";
|
|
4
|
+
import { t as MyCalendar } from "./my-calendar-ylD4tbTZ.js";
|
|
5
|
+
import { t as MyGrid } from "./my-grid-DduCSbuo.js";
|
|
6
|
+
export { MyButton, MyCalendar, MyElement, MyGrid };
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { t as __decorate } from "./decorate-BnP3GfGh.js";
|
|
2
|
+
import { LitElement, css, html } from "lit";
|
|
3
|
+
import { customElement, property } from "lit/decorators.js";
|
|
4
|
+
var MyButton = class extends LitElement {
|
|
5
|
+
constructor(...e) {
|
|
6
|
+
super(...e), this.label = "Button", this.disabled = !1, this.variant = "primary";
|
|
7
|
+
}
|
|
8
|
+
render() {
|
|
9
|
+
return html`
|
|
10
|
+
<button
|
|
11
|
+
class="button ${this.variant}"
|
|
12
|
+
?disabled=${this.disabled}
|
|
13
|
+
>
|
|
14
|
+
${this.label}
|
|
15
|
+
</button>
|
|
16
|
+
`;
|
|
17
|
+
}
|
|
18
|
+
static #e = this.styles = css`
|
|
19
|
+
.button {
|
|
20
|
+
border: none;
|
|
21
|
+
color: white;
|
|
22
|
+
padding: 12px 24px;
|
|
23
|
+
text-align: center;
|
|
24
|
+
text-decoration: none;
|
|
25
|
+
display: inline-block;
|
|
26
|
+
font-size: 16px;
|
|
27
|
+
margin: 4px 2px;
|
|
28
|
+
cursor: pointer;
|
|
29
|
+
border-radius: 8px;
|
|
30
|
+
transition: background-color 0.3s ease;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.button:disabled {
|
|
34
|
+
cursor: not-allowed;
|
|
35
|
+
opacity: 0.6;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.primary {
|
|
39
|
+
background-color: #4CAF50; /* Green */
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.primary:hover:not(:disabled) {
|
|
43
|
+
background-color: #45a049;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.secondary {
|
|
47
|
+
background-color: #008CBA; /* Blue */
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.secondary:hover:not(:disabled) {
|
|
51
|
+
background-color: #007bb5;
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
};
|
|
55
|
+
__decorate([property({ type: String })], MyButton.prototype, "label", void 0), __decorate([property({
|
|
56
|
+
type: Boolean,
|
|
57
|
+
reflect: !0
|
|
58
|
+
})], MyButton.prototype, "disabled", void 0), __decorate([property({ type: String })], MyButton.prototype, "variant", void 0), MyButton = __decorate([customElement("my-button")], MyButton);
|
|
59
|
+
export { MyButton as t };
|
package/dist/my-button.js
CHANGED
|
@@ -1,75 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
import { LitElement, css, html } from 'lit';
|
|
8
|
-
import { customElement, property } from 'lit/decorators.js';
|
|
9
|
-
let MyButton = class MyButton extends LitElement {
|
|
10
|
-
constructor() {
|
|
11
|
-
super(...arguments);
|
|
12
|
-
this.label = 'Button';
|
|
13
|
-
this.disabled = false;
|
|
14
|
-
this.variant = 'primary';
|
|
15
|
-
}
|
|
16
|
-
render() {
|
|
17
|
-
return html `
|
|
18
|
-
<button
|
|
19
|
-
class="button ${this.variant}"
|
|
20
|
-
?disabled=${this.disabled}
|
|
21
|
-
>
|
|
22
|
-
${this.label}
|
|
23
|
-
</button>
|
|
24
|
-
`;
|
|
25
|
-
}
|
|
26
|
-
static { this.styles = css `
|
|
27
|
-
.button {
|
|
28
|
-
border: none;
|
|
29
|
-
color: white;
|
|
30
|
-
padding: 12px 24px;
|
|
31
|
-
text-align: center;
|
|
32
|
-
text-decoration: none;
|
|
33
|
-
display: inline-block;
|
|
34
|
-
font-size: 16px;
|
|
35
|
-
margin: 4px 2px;
|
|
36
|
-
cursor: pointer;
|
|
37
|
-
border-radius: 8px;
|
|
38
|
-
transition: background-color 0.3s ease;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.button:disabled {
|
|
42
|
-
cursor: not-allowed;
|
|
43
|
-
opacity: 0.6;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
.primary {
|
|
47
|
-
background-color: #4CAF50; /* Green */
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
.primary:hover:not(:disabled) {
|
|
51
|
-
background-color: #45a049;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
.secondary {
|
|
55
|
-
background-color: #008CBA; /* Blue */
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
.secondary:hover:not(:disabled) {
|
|
59
|
-
background-color: #007bb5;
|
|
60
|
-
}
|
|
61
|
-
`; }
|
|
62
|
-
};
|
|
63
|
-
__decorate([
|
|
64
|
-
property({ type: String })
|
|
65
|
-
], MyButton.prototype, "label", void 0);
|
|
66
|
-
__decorate([
|
|
67
|
-
property({ type: Boolean, reflect: true })
|
|
68
|
-
], MyButton.prototype, "disabled", void 0);
|
|
69
|
-
__decorate([
|
|
70
|
-
property({ type: String })
|
|
71
|
-
], MyButton.prototype, "variant", void 0);
|
|
72
|
-
MyButton = __decorate([
|
|
73
|
-
customElement('my-button')
|
|
74
|
-
], MyButton);
|
|
1
|
+
import "./decorate-BnP3GfGh.js";
|
|
2
|
+
import { t as MyButton } from "./my-button-BXW2ABd3.js";
|
|
75
3
|
export { MyButton };
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { t as __decorate } from "./decorate-BnP3GfGh.js";
|
|
2
|
+
import { LitElement, css, html } from "lit";
|
|
3
|
+
import { customElement, state } from "lit/decorators.js";
|
|
4
|
+
var MyCalendar = class extends LitElement {
|
|
5
|
+
constructor(...e) {
|
|
6
|
+
super(...e), this.date = /* @__PURE__ */ new Date();
|
|
7
|
+
}
|
|
8
|
+
get year() {
|
|
9
|
+
return this.date.getFullYear();
|
|
10
|
+
}
|
|
11
|
+
get month() {
|
|
12
|
+
return this.date.getMonth();
|
|
13
|
+
}
|
|
14
|
+
_changeMonth(e) {
|
|
15
|
+
this.date = new Date(this.year, this.month + e, 1);
|
|
16
|
+
}
|
|
17
|
+
_renderHeader() {
|
|
18
|
+
return html`
|
|
19
|
+
<div class="header">
|
|
20
|
+
<button @click=${() => this._changeMonth(-1)}>‹</button>
|
|
21
|
+
<div class="month-year">${this.date.toLocaleString("default", { month: "long" })} ${this.year}</div>
|
|
22
|
+
<button @click=${() => this._changeMonth(1)}>›</button>
|
|
23
|
+
</div>
|
|
24
|
+
`;
|
|
25
|
+
}
|
|
26
|
+
_renderDaysOfWeek() {
|
|
27
|
+
return html`
|
|
28
|
+
<div class="days-of-week">
|
|
29
|
+
${[
|
|
30
|
+
"Sun",
|
|
31
|
+
"Mon",
|
|
32
|
+
"Tue",
|
|
33
|
+
"Wed",
|
|
34
|
+
"Thu",
|
|
35
|
+
"Fri",
|
|
36
|
+
"Sat"
|
|
37
|
+
].map((e) => html`<div>${e}</div>`)}
|
|
38
|
+
</div>
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
_renderDates() {
|
|
42
|
+
let e = /* @__PURE__ */ new Date(), i = new Date(this.year, this.month, 1).getDay(), a = new Date(this.year, this.month + 1, 0).getDate(), o = [];
|
|
43
|
+
for (let e = 0; e < i; e++) o.push(html`<div class="date-cell empty"></div>`);
|
|
44
|
+
for (let i = 1; i <= a; i++) {
|
|
45
|
+
let a = this.year === e.getFullYear() && this.month === e.getMonth() && i === e.getDate();
|
|
46
|
+
o.push(html`<div class="date-cell ${a ? "today" : ""}">${i}</div>`);
|
|
47
|
+
}
|
|
48
|
+
return html`<div class="date-grid">${o}</div>`;
|
|
49
|
+
}
|
|
50
|
+
render() {
|
|
51
|
+
return html`
|
|
52
|
+
<div class="calendar-container">
|
|
53
|
+
${this._renderHeader()}
|
|
54
|
+
${this._renderDaysOfWeek()}
|
|
55
|
+
${this._renderDates()}
|
|
56
|
+
</div>
|
|
57
|
+
`;
|
|
58
|
+
}
|
|
59
|
+
static #e = this.styles = css`
|
|
60
|
+
:host {
|
|
61
|
+
display: block;
|
|
62
|
+
max-width: 350px;
|
|
63
|
+
border: 1px solid #ccc;
|
|
64
|
+
border-radius: 8px;
|
|
65
|
+
padding: 16px;
|
|
66
|
+
font-family: sans-serif;
|
|
67
|
+
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.header {
|
|
71
|
+
display: flex;
|
|
72
|
+
justify-content: space-between;
|
|
73
|
+
align-items: center;
|
|
74
|
+
margin-bottom: 16px;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.header button {
|
|
78
|
+
background: none;
|
|
79
|
+
border: 1px solid #ccc;
|
|
80
|
+
border-radius: 50%;
|
|
81
|
+
width: 32px;
|
|
82
|
+
height: 32px;
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
font-size: 18px;
|
|
85
|
+
transition: background-color 0.2s;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.header button:hover {
|
|
89
|
+
background-color: #eee;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.month-year {
|
|
93
|
+
font-size: 1.2em;
|
|
94
|
+
font-weight: bold;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.days-of-week, .date-grid {
|
|
98
|
+
display: grid;
|
|
99
|
+
grid-template-columns: repeat(7, 1fr);
|
|
100
|
+
text-align: center;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.days-of-week > div {
|
|
104
|
+
font-weight: bold;
|
|
105
|
+
padding-bottom: 8px;
|
|
106
|
+
font-size: 0.9em;
|
|
107
|
+
color: #666;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
.date-cell {
|
|
111
|
+
padding: 4px 0;
|
|
112
|
+
cursor: pointer;
|
|
113
|
+
border-radius: 50%;
|
|
114
|
+
width: 32px;
|
|
115
|
+
height: 32px;
|
|
116
|
+
display: flex;
|
|
117
|
+
justify-content: center;
|
|
118
|
+
align-items: center;
|
|
119
|
+
margin: 2px auto;
|
|
120
|
+
transition: background-color 0.2s;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.date-cell:not(.empty):hover {
|
|
124
|
+
background-color: #eee;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.date-cell.today {
|
|
128
|
+
background-color: #4CAF50;
|
|
129
|
+
color: white;
|
|
130
|
+
font-weight: bold;
|
|
131
|
+
}
|
|
132
|
+
`;
|
|
133
|
+
};
|
|
134
|
+
__decorate([state()], MyCalendar.prototype, "date", void 0), MyCalendar = __decorate([customElement("my-calendar")], MyCalendar);
|
|
135
|
+
export { MyCalendar as t };
|
package/dist/my-calendar.js
CHANGED
|
@@ -1,147 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
import { LitElement, css, html } from 'lit';
|
|
8
|
-
import { customElement, state } from 'lit/decorators.js';
|
|
9
|
-
let MyCalendar = class MyCalendar extends LitElement {
|
|
10
|
-
constructor() {
|
|
11
|
-
super(...arguments);
|
|
12
|
-
this.date = new Date();
|
|
13
|
-
}
|
|
14
|
-
get year() {
|
|
15
|
-
return this.date.getFullYear();
|
|
16
|
-
}
|
|
17
|
-
get month() {
|
|
18
|
-
return this.date.getMonth();
|
|
19
|
-
}
|
|
20
|
-
_changeMonth(offset) {
|
|
21
|
-
this.date = new Date(this.year, this.month + offset, 1);
|
|
22
|
-
}
|
|
23
|
-
_renderHeader() {
|
|
24
|
-
const monthName = this.date.toLocaleString('default', { month: 'long' });
|
|
25
|
-
return html `
|
|
26
|
-
<div class="header">
|
|
27
|
-
<button @click=${() => this._changeMonth(-1)}>‹</button>
|
|
28
|
-
<div class="month-year">${monthName} ${this.year}</div>
|
|
29
|
-
<button @click=${() => this._changeMonth(1)}>›</button>
|
|
30
|
-
</div>
|
|
31
|
-
`;
|
|
32
|
-
}
|
|
33
|
-
_renderDaysOfWeek() {
|
|
34
|
-
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
35
|
-
return html `
|
|
36
|
-
<div class="days-of-week">
|
|
37
|
-
${days.map(day => html `<div>${day}</div>`)}
|
|
38
|
-
</div>
|
|
39
|
-
`;
|
|
40
|
-
}
|
|
41
|
-
_renderDates() {
|
|
42
|
-
const today = new Date();
|
|
43
|
-
const firstDayOfMonth = new Date(this.year, this.month, 1).getDay();
|
|
44
|
-
const daysInMonth = new Date(this.year, this.month + 1, 0).getDate();
|
|
45
|
-
const dates = [];
|
|
46
|
-
for (let i = 0; i < firstDayOfMonth; i++) {
|
|
47
|
-
dates.push(html `<div class="date-cell empty"></div>`);
|
|
48
|
-
}
|
|
49
|
-
for (let i = 1; i <= daysInMonth; i++) {
|
|
50
|
-
const isToday = this.year === today.getFullYear() &&
|
|
51
|
-
this.month === today.getMonth() &&
|
|
52
|
-
i === today.getDate();
|
|
53
|
-
dates.push(html `<div class="date-cell ${isToday ? 'today' : ''}">${i}</div>`);
|
|
54
|
-
}
|
|
55
|
-
return html `<div class="date-grid">${dates}</div>`;
|
|
56
|
-
}
|
|
57
|
-
render() {
|
|
58
|
-
return html `
|
|
59
|
-
<div class="calendar-container">
|
|
60
|
-
${this._renderHeader()}
|
|
61
|
-
${this._renderDaysOfWeek()}
|
|
62
|
-
${this._renderDates()}
|
|
63
|
-
</div>
|
|
64
|
-
`;
|
|
65
|
-
}
|
|
66
|
-
static { this.styles = css `
|
|
67
|
-
:host {
|
|
68
|
-
display: block;
|
|
69
|
-
max-width: 350px;
|
|
70
|
-
border: 1px solid #ccc;
|
|
71
|
-
border-radius: 8px;
|
|
72
|
-
padding: 16px;
|
|
73
|
-
font-family: sans-serif;
|
|
74
|
-
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
.header {
|
|
78
|
-
display: flex;
|
|
79
|
-
justify-content: space-between;
|
|
80
|
-
align-items: center;
|
|
81
|
-
margin-bottom: 16px;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
.header button {
|
|
85
|
-
background: none;
|
|
86
|
-
border: 1px solid #ccc;
|
|
87
|
-
border-radius: 50%;
|
|
88
|
-
width: 32px;
|
|
89
|
-
height: 32px;
|
|
90
|
-
cursor: pointer;
|
|
91
|
-
font-size: 18px;
|
|
92
|
-
transition: background-color 0.2s;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
.header button:hover {
|
|
96
|
-
background-color: #eee;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
.month-year {
|
|
100
|
-
font-size: 1.2em;
|
|
101
|
-
font-weight: bold;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
.days-of-week, .date-grid {
|
|
105
|
-
display: grid;
|
|
106
|
-
grid-template-columns: repeat(7, 1fr);
|
|
107
|
-
text-align: center;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
.days-of-week > div {
|
|
111
|
-
font-weight: bold;
|
|
112
|
-
padding-bottom: 8px;
|
|
113
|
-
font-size: 0.9em;
|
|
114
|
-
color: #666;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
.date-cell {
|
|
118
|
-
padding: 4px 0;
|
|
119
|
-
cursor: pointer;
|
|
120
|
-
border-radius: 50%;
|
|
121
|
-
width: 32px;
|
|
122
|
-
height: 32px;
|
|
123
|
-
display: flex;
|
|
124
|
-
justify-content: center;
|
|
125
|
-
align-items: center;
|
|
126
|
-
margin: 2px auto;
|
|
127
|
-
transition: background-color 0.2s;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
.date-cell:not(.empty):hover {
|
|
131
|
-
background-color: #eee;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
.date-cell.today {
|
|
135
|
-
background-color: #4CAF50;
|
|
136
|
-
color: white;
|
|
137
|
-
font-weight: bold;
|
|
138
|
-
}
|
|
139
|
-
`; }
|
|
140
|
-
};
|
|
141
|
-
__decorate([
|
|
142
|
-
state()
|
|
143
|
-
], MyCalendar.prototype, "date", void 0);
|
|
144
|
-
MyCalendar = __decorate([
|
|
145
|
-
customElement('my-calendar')
|
|
146
|
-
], MyCalendar);
|
|
1
|
+
import "./decorate-BnP3GfGh.js";
|
|
2
|
+
import { t as MyCalendar } from "./my-calendar-ylD4tbTZ.js";
|
|
147
3
|
export { MyCalendar };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { t as __decorate } from "./decorate-BnP3GfGh.js";
|
|
2
|
+
import { LitElement, css, html } from "lit";
|
|
3
|
+
import { customElement, property } from "lit/decorators.js";
|
|
4
|
+
var MyElement = class extends LitElement {
|
|
5
|
+
constructor(...e) {
|
|
6
|
+
super(...e), this.name = "World";
|
|
7
|
+
}
|
|
8
|
+
render() {
|
|
9
|
+
return html`
|
|
10
|
+
<h1>Hello, ${this.name}!</h1>
|
|
11
|
+
`;
|
|
12
|
+
}
|
|
13
|
+
static #e = this.styles = css`
|
|
14
|
+
:host {
|
|
15
|
+
display: block;
|
|
16
|
+
border: solid 1px gray;
|
|
17
|
+
padding: 16px;
|
|
18
|
+
max-width: 800px;
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
};
|
|
22
|
+
__decorate([property()], MyElement.prototype, "name", void 0), MyElement = __decorate([customElement("my-element")], MyElement);
|
|
23
|
+
export { MyElement as t };
|
package/dist/my-element.js
CHANGED
|
@@ -1,34 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
import { LitElement, css, html } from 'lit';
|
|
8
|
-
import { customElement, property } from 'lit/decorators.js';
|
|
9
|
-
let MyElement = class MyElement extends LitElement {
|
|
10
|
-
constructor() {
|
|
11
|
-
super(...arguments);
|
|
12
|
-
this.name = 'World';
|
|
13
|
-
}
|
|
14
|
-
render() {
|
|
15
|
-
return html `
|
|
16
|
-
<h1>Hello, ${this.name}!</h1>
|
|
17
|
-
`;
|
|
18
|
-
}
|
|
19
|
-
static { this.styles = css `
|
|
20
|
-
:host {
|
|
21
|
-
display: block;
|
|
22
|
-
border: solid 1px gray;
|
|
23
|
-
padding: 16px;
|
|
24
|
-
max-width: 800px;
|
|
25
|
-
}
|
|
26
|
-
`; }
|
|
27
|
-
};
|
|
28
|
-
__decorate([
|
|
29
|
-
property()
|
|
30
|
-
], MyElement.prototype, "name", void 0);
|
|
31
|
-
MyElement = __decorate([
|
|
32
|
-
customElement('my-element')
|
|
33
|
-
], MyElement);
|
|
1
|
+
import "./decorate-BnP3GfGh.js";
|
|
2
|
+
import { t as MyElement } from "./my-element-BWehTtOJ.js";
|
|
34
3
|
export { MyElement };
|
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
import { t as __decorate } from "./decorate-BnP3GfGh.js";
|
|
2
|
+
import { LitElement, css, html } from "lit";
|
|
3
|
+
import { customElement, property, state } from "lit/decorators.js";
|
|
4
|
+
import { when } from "lit/directives/when.js";
|
|
5
|
+
import { classMap } from "lit/directives/class-map.js";
|
|
6
|
+
import { styleMap } from "lit/directives/style-map.js";
|
|
7
|
+
import { repeat } from "lit/directives/repeat.js";
|
|
8
|
+
var MyGrid = class extends LitElement {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(), this.columns = [], this.data = [], this.itemsPerPage = 10, this.columnReordering = !0, this.height = "auto", this.enableColumnVisibility = !0, this.enableFilter = !0, this._sortKey = null, this._sortDirection = "asc", this._draggedColumnIndex = null, this._dragOverColumnIndex = null, this._selectedRowId = null, this._selectedColumnKey = null, this._filterValues = {}, this._activeFilterColumn = null, this._filterSearchTerm = "", this._currentPage = 1, this._hiddenColumns = /* @__PURE__ */ new Set(), this._showColumnMenu = !1, this._filterMenuSortDirection = "asc", this._resizingColumnIndex = null, this._startX = 0, this._startWidth = 0, this._handleDocumentClick = this._handleDocumentClick.bind(this), this._handleResizeMove = this._handleResizeMove.bind(this), this._handleResizeEnd = this._handleResizeEnd.bind(this);
|
|
11
|
+
}
|
|
12
|
+
connectedCallback() {
|
|
13
|
+
super.connectedCallback(), document.addEventListener("click", this._handleDocumentClick), document.addEventListener("mousemove", this._handleResizeMove), document.addEventListener("mouseup", this._handleResizeEnd);
|
|
14
|
+
}
|
|
15
|
+
disconnectedCallback() {
|
|
16
|
+
super.disconnectedCallback(), document.removeEventListener("click", this._handleDocumentClick), document.removeEventListener("mousemove", this._handleResizeMove), document.removeEventListener("mouseup", this._handleResizeEnd);
|
|
17
|
+
}
|
|
18
|
+
updated(e) {
|
|
19
|
+
super.updated(e), e.has("enableFilter") && (this._filterValues = {}, this._activeFilterColumn = null, this._filterSearchTerm = "", this._resetPage());
|
|
20
|
+
}
|
|
21
|
+
_handleDocumentClick(e) {
|
|
22
|
+
this._showColumnMenu &&= !1, this._activeFilterColumn && (this._activeFilterColumn = null, this._filterSearchTerm = "");
|
|
23
|
+
}
|
|
24
|
+
get _visibleColumns() {
|
|
25
|
+
return this.columns.filter((e) => !this._hiddenColumns.has(e.key));
|
|
26
|
+
}
|
|
27
|
+
get _gridColumnTemplate() {
|
|
28
|
+
let e = "";
|
|
29
|
+
return this.enableColumnVisibility && (e += "40px "), e += this._visibleColumns.map((e) => e.width || "minmax(150px, 1fr)").join(" "), e;
|
|
30
|
+
}
|
|
31
|
+
_resetPage() {
|
|
32
|
+
this._currentPage = 1;
|
|
33
|
+
}
|
|
34
|
+
_toggleColumnMenu(e) {
|
|
35
|
+
e.stopPropagation(), this._showColumnMenu = !this._showColumnMenu, this._activeFilterColumn = null;
|
|
36
|
+
}
|
|
37
|
+
_toggleColumnVisibility(e) {
|
|
38
|
+
let o = new Set(this._hiddenColumns);
|
|
39
|
+
o.has(e) ? o.delete(e) : o.add(e), this._hiddenColumns = o;
|
|
40
|
+
}
|
|
41
|
+
_handleItemsPerPageChange(e) {
|
|
42
|
+
let o = e.target;
|
|
43
|
+
this.itemsPerPage = Number(o.value), this._resetPage();
|
|
44
|
+
}
|
|
45
|
+
_handleHeaderClick(e) {
|
|
46
|
+
this._sortKey === e ? this._sortDirection = this._sortDirection === "asc" ? "desc" : "asc" : (this._sortKey = e, this._sortDirection = "asc"), this._resetPage();
|
|
47
|
+
}
|
|
48
|
+
_toggleFilterMenu(e, o) {
|
|
49
|
+
e.stopPropagation(), this._activeFilterColumn === o ? this._activeFilterColumn = null : (this._activeFilterColumn = o, this._showColumnMenu = !1, this._filterMenuSortDirection = "asc"), this._filterSearchTerm = "";
|
|
50
|
+
}
|
|
51
|
+
_toggleFilterMenuSort(e) {
|
|
52
|
+
e.stopPropagation(), this._filterMenuSortDirection = this._filterMenuSortDirection === "asc" ? "desc" : "asc";
|
|
53
|
+
}
|
|
54
|
+
_getUniqueValues(e) {
|
|
55
|
+
let o = new Set(this.data.map((o) => o[e]));
|
|
56
|
+
return Array.from(o).sort((e, o) => {
|
|
57
|
+
if (e === o) return 0;
|
|
58
|
+
if (e == null) return 1;
|
|
59
|
+
if (o == null) return -1;
|
|
60
|
+
let s = 0;
|
|
61
|
+
if (typeof e == "number" && typeof o == "number") s = e - o;
|
|
62
|
+
else {
|
|
63
|
+
let c = Date.parse(String(e)), l = Date.parse(String(o));
|
|
64
|
+
s = !isNaN(c) && !isNaN(l) && String(e).includes("-") && String(o).includes("-") ? c - l : String(e).localeCompare(String(o));
|
|
65
|
+
}
|
|
66
|
+
return this._filterMenuSortDirection === "asc" ? s : -s;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
_isFilterActive(e) {
|
|
70
|
+
return !!this._filterValues[e];
|
|
71
|
+
}
|
|
72
|
+
_handleFilterValueChange(e, o, s) {
|
|
73
|
+
let c = this._filterValues[e];
|
|
74
|
+
if (c) {
|
|
75
|
+
let l = new Set(c);
|
|
76
|
+
s ? l.add(o) : l.delete(o);
|
|
77
|
+
let u = this._getUniqueValues(e);
|
|
78
|
+
if (l.size === u.length) {
|
|
79
|
+
let o = { ...this._filterValues };
|
|
80
|
+
delete o[e], this._filterValues = o;
|
|
81
|
+
} else this._filterValues = {
|
|
82
|
+
...this._filterValues,
|
|
83
|
+
[e]: l
|
|
84
|
+
};
|
|
85
|
+
} else if (!s) {
|
|
86
|
+
let s = this._getUniqueValues(e);
|
|
87
|
+
c = new Set(s), c.delete(o), this._filterValues = {
|
|
88
|
+
...this._filterValues,
|
|
89
|
+
[e]: c
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
this._resetPage();
|
|
93
|
+
}
|
|
94
|
+
_handleSelectAll(e, o) {
|
|
95
|
+
if (o) {
|
|
96
|
+
let o = { ...this._filterValues };
|
|
97
|
+
delete o[e], this._filterValues = o;
|
|
98
|
+
} else this._filterValues = {
|
|
99
|
+
...this._filterValues,
|
|
100
|
+
[e]: /* @__PURE__ */ new Set()
|
|
101
|
+
};
|
|
102
|
+
this._resetPage();
|
|
103
|
+
}
|
|
104
|
+
_handleFilterSearch(e) {
|
|
105
|
+
this._filterSearchTerm = e.target.value;
|
|
106
|
+
}
|
|
107
|
+
_handleResizeStart(e, o) {
|
|
108
|
+
e.preventDefault(), e.stopPropagation(), this._resizingColumnIndex = o, this._startX = e.pageX;
|
|
109
|
+
let s = this.shadowRoot?.querySelectorAll(".header-cell"), c = o + (this.enableColumnVisibility ? 1 : 0);
|
|
110
|
+
s && s[c] ? this._startWidth = s[c].getBoundingClientRect().width : this._startWidth = 150;
|
|
111
|
+
}
|
|
112
|
+
_handleResizeMove(e) {
|
|
113
|
+
if (this._resizingColumnIndex !== null) {
|
|
114
|
+
let o = e.pageX - this._startX, s = Math.max(50, this._startWidth + o), c = this._visibleColumns[this._resizingColumnIndex], l = this.columns.findIndex((e) => e.key === c.key);
|
|
115
|
+
if (l !== -1) {
|
|
116
|
+
let e = [...this.columns];
|
|
117
|
+
e[l] = {
|
|
118
|
+
...e[l],
|
|
119
|
+
width: `${s}px`
|
|
120
|
+
}, this.columns = e;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
_handleResizeEnd() {
|
|
125
|
+
this._resizingColumnIndex = null;
|
|
126
|
+
}
|
|
127
|
+
get _filteredData() {
|
|
128
|
+
if (!this.enableFilter) return this.data;
|
|
129
|
+
let e = this.data, o = Object.keys(this._filterValues);
|
|
130
|
+
return o.length > 0 && (e = e.filter((e) => o.every((o) => {
|
|
131
|
+
let s = this._filterValues[o];
|
|
132
|
+
return !s || s.size === 0 ? !1 : s ? s.has(e[o]) : !0;
|
|
133
|
+
}))), e;
|
|
134
|
+
}
|
|
135
|
+
get _sortedData() {
|
|
136
|
+
let e = this._filteredData;
|
|
137
|
+
return this._sortKey ? [...e].sort((e, o) => {
|
|
138
|
+
let s = e[this._sortKey], c = o[this._sortKey];
|
|
139
|
+
if (s === c) return 0;
|
|
140
|
+
if (s == null) return 1;
|
|
141
|
+
if (c == null) return -1;
|
|
142
|
+
let l = 0;
|
|
143
|
+
return l = typeof s == "string" && typeof c == "string" ? s.localeCompare(c) : typeof s == "number" && typeof c == "number" ? s - c : String(s).localeCompare(String(c)), this._sortDirection === "asc" ? l : -l;
|
|
144
|
+
}) : e;
|
|
145
|
+
}
|
|
146
|
+
get _paginatedData() {
|
|
147
|
+
let e = (this._currentPage - 1) * this.itemsPerPage, o = e + this.itemsPerPage;
|
|
148
|
+
return this._sortedData.slice(e, o);
|
|
149
|
+
}
|
|
150
|
+
_handleCellClick(e, o) {
|
|
151
|
+
let s = e.id;
|
|
152
|
+
this._selectedRowId === s && this._selectedColumnKey === o ? (this._selectedRowId = null, this._selectedColumnKey = null) : (this._selectedRowId = s, this._selectedColumnKey = o);
|
|
153
|
+
}
|
|
154
|
+
_handleDragStart(e, o) {
|
|
155
|
+
if (this._resizingColumnIndex !== null) {
|
|
156
|
+
e.preventDefault();
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
if (!this.columnReordering) {
|
|
160
|
+
e.preventDefault();
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (this._draggedColumnIndex = o, e.dataTransfer) {
|
|
164
|
+
e.dataTransfer.effectAllowed = "move", e.dataTransfer.setData("text/plain", o.toString());
|
|
165
|
+
let s = e.target;
|
|
166
|
+
e.dataTransfer.setDragImage(s, e.offsetX, e.offsetY);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
_handleDragOver(e, o) {
|
|
170
|
+
this.columnReordering && (e.preventDefault(), e.dataTransfer && (e.dataTransfer.dropEffect = "move"), this._draggedColumnIndex !== null && this._draggedColumnIndex !== o && (this._dragOverColumnIndex = o));
|
|
171
|
+
}
|
|
172
|
+
_handleDragLeave() {
|
|
173
|
+
this.columnReordering && (this._dragOverColumnIndex = null);
|
|
174
|
+
}
|
|
175
|
+
_handleDrop(e, o) {
|
|
176
|
+
if (this.columnReordering) {
|
|
177
|
+
if (e.preventDefault(), e.dataTransfer) {
|
|
178
|
+
let s = parseInt(e.dataTransfer.getData("text/plain"), 10);
|
|
179
|
+
if (this._draggedColumnIndex !== null && s !== o) {
|
|
180
|
+
let e = [...this._visibleColumns], [c] = e.splice(s, 1);
|
|
181
|
+
e.splice(o, 0, c);
|
|
182
|
+
let l = [], u = 0;
|
|
183
|
+
for (let o of this.columns) this._hiddenColumns.has(o.key) ? l.push(o) : l.push(e[u++]);
|
|
184
|
+
this.columns = l;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
this._draggedColumnIndex = null, this._dragOverColumnIndex = null;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
_handleDragEnd() {
|
|
191
|
+
this.columnReordering && (this._draggedColumnIndex = null, this._dragOverColumnIndex = null);
|
|
192
|
+
}
|
|
193
|
+
_formatLink(e, o) {
|
|
194
|
+
return e.replace(/{(\w+)}/g, (e, s) => o[s] === void 0 ? e : String(o[s]));
|
|
195
|
+
}
|
|
196
|
+
_renderCell(e, o) {
|
|
197
|
+
let s = e[o.key];
|
|
198
|
+
return o.linkTemplate ? html`<a href="${this._formatLink(o.linkTemplate, e)}">${s}</a>` : s;
|
|
199
|
+
}
|
|
200
|
+
_renderColumnMenu() {
|
|
201
|
+
return this._showColumnMenu ? html`
|
|
202
|
+
<div class="column-menu" @click=${(e) => e.stopPropagation()}>
|
|
203
|
+
${this.columns.map((e) => html`
|
|
204
|
+
<label>
|
|
205
|
+
<input
|
|
206
|
+
type="checkbox"
|
|
207
|
+
.checked=${!this._hiddenColumns.has(e.key)}
|
|
208
|
+
@change=${() => this._toggleColumnVisibility(e.key)}
|
|
209
|
+
/>
|
|
210
|
+
${e.header}
|
|
211
|
+
</label>
|
|
212
|
+
`)}
|
|
213
|
+
</div>
|
|
214
|
+
` : null;
|
|
215
|
+
}
|
|
216
|
+
_renderFilterMenu(e, o) {
|
|
217
|
+
if (this._activeFilterColumn !== e) return null;
|
|
218
|
+
let s = this._getUniqueValues(e).filter((e) => String(e).toLowerCase().includes(this._filterSearchTerm.toLowerCase())), l = this._filterValues[e], u = !l, d = u || !!l && s.every((e) => l.has(e));
|
|
219
|
+
return html`
|
|
220
|
+
<div class="${o > this._visibleColumns.length - 3 ? "filter-menu right-aligned" : "filter-menu"}" @click=${(e) => e.stopPropagation()}>
|
|
221
|
+
<div class="filter-search-container">
|
|
222
|
+
<input
|
|
223
|
+
type="text"
|
|
224
|
+
class="filter-search"
|
|
225
|
+
placeholder="Search..."
|
|
226
|
+
.value=${this._filterSearchTerm}
|
|
227
|
+
@input=${this._handleFilterSearch}
|
|
228
|
+
/>
|
|
229
|
+
<button class="filter-sort-btn" @click=${this._toggleFilterMenuSort} title="Sort Values">
|
|
230
|
+
${this._filterMenuSortDirection === "asc" ? "▲" : "▼"}
|
|
231
|
+
</button>
|
|
232
|
+
</div>
|
|
233
|
+
<div class="filter-list">
|
|
234
|
+
<label>
|
|
235
|
+
<input
|
|
236
|
+
type="checkbox"
|
|
237
|
+
.checked=${d}
|
|
238
|
+
@change=${(o) => this._handleSelectAll(e, o.target.checked)}
|
|
239
|
+
/>
|
|
240
|
+
(Select All)
|
|
241
|
+
</label>
|
|
242
|
+
${s.map((o) => html`
|
|
243
|
+
<label>
|
|
244
|
+
<input
|
|
245
|
+
type="checkbox"
|
|
246
|
+
.checked=${u || !!l && l.has(o)}
|
|
247
|
+
@change=${(s) => this._handleFilterValueChange(e, o, s.target.checked)}
|
|
248
|
+
/>
|
|
249
|
+
${String(o)}
|
|
250
|
+
</label>
|
|
251
|
+
`)}
|
|
252
|
+
</div>
|
|
253
|
+
</div>
|
|
254
|
+
`;
|
|
255
|
+
}
|
|
256
|
+
_renderHeader(e) {
|
|
257
|
+
return html`
|
|
258
|
+
<div class="grid-header">
|
|
259
|
+
<div class="grid-row" style=${styleMap(e)}>
|
|
260
|
+
${when(this.enableColumnVisibility, () => html`
|
|
261
|
+
<div class="grid-cell header-cell settings-cell" @click=${this._toggleColumnMenu}>
|
|
262
|
+
⚙️
|
|
263
|
+
${this._renderColumnMenu()}
|
|
264
|
+
</div>
|
|
265
|
+
`)}
|
|
266
|
+
${this._visibleColumns.map((e, o) => {
|
|
267
|
+
let s = {
|
|
268
|
+
"grid-cell": !0,
|
|
269
|
+
"header-cell": !0,
|
|
270
|
+
"drag-over": this._dragOverColumnIndex === o,
|
|
271
|
+
reorderable: this.columnReordering,
|
|
272
|
+
"align-center": e.align === "center",
|
|
273
|
+
"align-right": e.align === "right"
|
|
274
|
+
};
|
|
275
|
+
return html`
|
|
276
|
+
<div
|
|
277
|
+
.draggable=${this.columnReordering}
|
|
278
|
+
class=${classMap(s)}
|
|
279
|
+
@click=${() => this._handleHeaderClick(e.key)}
|
|
280
|
+
@dragstart=${(e) => this._handleDragStart(e, o)}
|
|
281
|
+
@dragover=${(e) => this._handleDragOver(e, o)}
|
|
282
|
+
@dragleave=${this._handleDragLeave}
|
|
283
|
+
@drop=${(e) => this._handleDrop(e, o)}
|
|
284
|
+
@dragend=${this._handleDragEnd}
|
|
285
|
+
>
|
|
286
|
+
<span class="header-text">${e.header}</span>
|
|
287
|
+
<div class="header-icons">
|
|
288
|
+
${when(this.enableFilter, () => html`
|
|
289
|
+
<span class="filter-icon ${this._isFilterActive(e.key) ? "active" : ""}" @click=${(o) => this._toggleFilterMenu(o, e.key)}>
|
|
290
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
291
|
+
<polygon points="22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3"></polygon>
|
|
292
|
+
</svg>
|
|
293
|
+
</span>
|
|
294
|
+
`)}
|
|
295
|
+
${this._sortKey === e.key ? html`<span class="sort-indicator">${this._sortDirection === "asc" ? "▲" : "▼"}</span>` : ""}
|
|
296
|
+
</div>
|
|
297
|
+
${this._renderFilterMenu(e.key, o)}
|
|
298
|
+
<div class="resize-handle" @mousedown=${(e) => this._handleResizeStart(e, o)} @click=${(e) => e.stopPropagation()}></div>
|
|
299
|
+
</div>
|
|
300
|
+
`;
|
|
301
|
+
})}
|
|
302
|
+
</div>
|
|
303
|
+
</div>
|
|
304
|
+
`;
|
|
305
|
+
}
|
|
306
|
+
_renderBody(e) {
|
|
307
|
+
return html`
|
|
308
|
+
<div class="grid-body">
|
|
309
|
+
${repeat(this._paginatedData, (e) => e.id, (o) => html`
|
|
310
|
+
<div class="grid-row ${this.rowClass ? this.rowClass(o) : ""}" style=${styleMap(e)}>
|
|
311
|
+
${when(this.enableColumnVisibility, () => html`<div class="grid-cell data-cell"></div>`)}
|
|
312
|
+
${this._visibleColumns.map((e) => {
|
|
313
|
+
let s = {
|
|
314
|
+
"grid-cell": !0,
|
|
315
|
+
"data-cell": !0,
|
|
316
|
+
selected: this._selectedRowId === o.id && this._selectedColumnKey === e.key,
|
|
317
|
+
"align-center": e.align === "center",
|
|
318
|
+
"align-right": e.align === "right",
|
|
319
|
+
[`col-${e.key}`]: !0
|
|
320
|
+
};
|
|
321
|
+
return html`
|
|
322
|
+
<div
|
|
323
|
+
title="${String(o[e.key] ?? "")}"
|
|
324
|
+
class=${classMap(s)}
|
|
325
|
+
@click=${() => this._handleCellClick(o, e.key)}
|
|
326
|
+
>
|
|
327
|
+
${this._renderCell(o, e)}
|
|
328
|
+
</div>
|
|
329
|
+
`;
|
|
330
|
+
})}
|
|
331
|
+
</div>
|
|
332
|
+
`)}
|
|
333
|
+
</div>
|
|
334
|
+
`;
|
|
335
|
+
}
|
|
336
|
+
_renderPaginationControls() {
|
|
337
|
+
let e = this._sortedData.length, o = Math.ceil(e / this.itemsPerPage);
|
|
338
|
+
return o <= 1 ? "" : html`
|
|
339
|
+
<div class="pagination">
|
|
340
|
+
<div class="pagination-group">
|
|
341
|
+
<button @click=${() => this._currentPage = 1} ?disabled=${this._currentPage === 1}><< First</button>
|
|
342
|
+
<button @click=${() => this._currentPage--} ?disabled=${this._currentPage === 1}>< Previous</button>
|
|
343
|
+
</div>
|
|
344
|
+
<div class="pagination-info">
|
|
345
|
+
<span>Page ${this._currentPage} of ${o}</span>
|
|
346
|
+
</div>
|
|
347
|
+
<div class="pagination-group">
|
|
348
|
+
<button @click=${() => this._currentPage++} ?disabled=${this._currentPage === o}>Next ></button>
|
|
349
|
+
<button @click=${() => this._currentPage = o} ?disabled=${this._currentPage === o}>Last >></button>
|
|
350
|
+
</div>
|
|
351
|
+
</div>
|
|
352
|
+
`;
|
|
353
|
+
}
|
|
354
|
+
render() {
|
|
355
|
+
let e = { height: this.height }, o = { "grid-template-columns": this._gridColumnTemplate };
|
|
356
|
+
return html`
|
|
357
|
+
<div class="toolbar">
|
|
358
|
+
<div class="items-per-page">
|
|
359
|
+
<span>Rows per page:</span>
|
|
360
|
+
<select @change=${this._handleItemsPerPageChange} .value=${this.itemsPerPage.toString()}>
|
|
361
|
+
<option value="10">10</option>
|
|
362
|
+
<option value="20">20</option>
|
|
363
|
+
<option value="50">50</option>
|
|
364
|
+
</select>
|
|
365
|
+
</div>
|
|
366
|
+
</div>
|
|
367
|
+
<div class="grid-wrapper" style=${styleMap(e)}>
|
|
368
|
+
<div class="grid-container">
|
|
369
|
+
${this._renderHeader(o)}
|
|
370
|
+
${this._renderBody(o)}
|
|
371
|
+
</div>
|
|
372
|
+
</div>
|
|
373
|
+
${this._renderPaginationControls()}
|
|
374
|
+
`;
|
|
375
|
+
}
|
|
376
|
+
static #e = this.styles = css`
|
|
377
|
+
:host {
|
|
378
|
+
display: block;
|
|
379
|
+
font-family: sans-serif;
|
|
380
|
+
}
|
|
381
|
+
/* Default styles for all elements inside the component */
|
|
382
|
+
* {
|
|
383
|
+
box-sizing: border-box;
|
|
384
|
+
color: #000; /* Default text color black */
|
|
385
|
+
}
|
|
386
|
+
input, select, button {
|
|
387
|
+
background-color: #fff; /* Default background white */
|
|
388
|
+
color: #000; /* Default text color black */
|
|
389
|
+
border: 1px solid #ccc;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
.toolbar {
|
|
393
|
+
margin-bottom: 8px;
|
|
394
|
+
display: flex;
|
|
395
|
+
justify-content: flex-end;
|
|
396
|
+
align-items: center;
|
|
397
|
+
}
|
|
398
|
+
.toolbar button { padding: 6px 12px; border-radius: 4px; background-color: #f8f8f8; cursor: pointer; }
|
|
399
|
+
.toolbar button:hover { background-color: #eee; }
|
|
400
|
+
|
|
401
|
+
.items-per-page {
|
|
402
|
+
display: flex;
|
|
403
|
+
align-items: center;
|
|
404
|
+
gap: 8px;
|
|
405
|
+
font-size: 0.9em;
|
|
406
|
+
}
|
|
407
|
+
.items-per-page select {
|
|
408
|
+
padding: 4px 8px;
|
|
409
|
+
border-radius: 4px;
|
|
410
|
+
cursor: pointer;
|
|
411
|
+
font-size: 1em;
|
|
412
|
+
color: #000;
|
|
413
|
+
}
|
|
414
|
+
.items-per-page select:hover {
|
|
415
|
+
border-color: #888;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
.grid-wrapper {
|
|
419
|
+
overflow: auto;
|
|
420
|
+
border: 1px solid #ccc;
|
|
421
|
+
border-radius: 4px;
|
|
422
|
+
}
|
|
423
|
+
.grid-container {
|
|
424
|
+
display: inline-block;
|
|
425
|
+
min-width: 100%;
|
|
426
|
+
vertical-align: top;
|
|
427
|
+
}
|
|
428
|
+
.grid-header {
|
|
429
|
+
position: sticky;
|
|
430
|
+
top: 0;
|
|
431
|
+
z-index: 2;
|
|
432
|
+
background-color: #e8e8e8;
|
|
433
|
+
}
|
|
434
|
+
.grid-row {
|
|
435
|
+
display: grid;
|
|
436
|
+
border-bottom: 1px solid #ddd;
|
|
437
|
+
}
|
|
438
|
+
.grid-body .grid-row:last-of-type {
|
|
439
|
+
border-bottom: none;
|
|
440
|
+
}
|
|
441
|
+
.grid-cell {
|
|
442
|
+
padding: 12px 15px;
|
|
443
|
+
text-align: left;
|
|
444
|
+
color: #000;
|
|
445
|
+
overflow: hidden;
|
|
446
|
+
text-overflow: ellipsis;
|
|
447
|
+
white-space: nowrap;
|
|
448
|
+
border-right: 1px solid #ddd; /* Add right border */
|
|
449
|
+
}
|
|
450
|
+
.grid-cell:last-child {
|
|
451
|
+
border-right: none; /* Remove right border for last cell */
|
|
452
|
+
}
|
|
453
|
+
.grid-cell.align-center { justify-content: center; text-align: center; }
|
|
454
|
+
.grid-cell.align-right { justify-content: flex-end; text-align: right; }
|
|
455
|
+
|
|
456
|
+
.header-cell {
|
|
457
|
+
display: flex;
|
|
458
|
+
align-items: center;
|
|
459
|
+
justify-content: space-between;
|
|
460
|
+
font-weight: bold;
|
|
461
|
+
cursor: pointer;
|
|
462
|
+
user-select: none;
|
|
463
|
+
position: relative;
|
|
464
|
+
overflow: visible;
|
|
465
|
+
border-bottom: 1px solid #ccc; /* Add bottom border to header */
|
|
466
|
+
}
|
|
467
|
+
.header-text {
|
|
468
|
+
overflow: hidden;
|
|
469
|
+
text-overflow: ellipsis;
|
|
470
|
+
white-space: nowrap;
|
|
471
|
+
flex-grow: 1;
|
|
472
|
+
}
|
|
473
|
+
.header-icons {
|
|
474
|
+
display: flex;
|
|
475
|
+
align-items: center;
|
|
476
|
+
gap: 4px;
|
|
477
|
+
}
|
|
478
|
+
.sort-indicator {
|
|
479
|
+
flex-shrink: 0;
|
|
480
|
+
}
|
|
481
|
+
.filter-icon {
|
|
482
|
+
display: flex;
|
|
483
|
+
align-items: center;
|
|
484
|
+
justify-content: center;
|
|
485
|
+
width: 16px;
|
|
486
|
+
height: 16px;
|
|
487
|
+
color: #888; /* Default grey icon */
|
|
488
|
+
padding: 2px;
|
|
489
|
+
border-radius: 2px;
|
|
490
|
+
cursor: pointer;
|
|
491
|
+
}
|
|
492
|
+
.filter-icon:hover {
|
|
493
|
+
color: #000; /* Black icon on hover */
|
|
494
|
+
}
|
|
495
|
+
.filter-icon.active {
|
|
496
|
+
color: #007bff; /* Blue icon when active */
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
.settings-cell {
|
|
500
|
+
justify-content: center;
|
|
501
|
+
position: relative;
|
|
502
|
+
overflow: visible;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
.column-menu, .filter-menu {
|
|
506
|
+
position: absolute;
|
|
507
|
+
top: 100%;
|
|
508
|
+
left: 0;
|
|
509
|
+
background-color: white;
|
|
510
|
+
border: 1px solid #ccc;
|
|
511
|
+
border-radius: 4px;
|
|
512
|
+
padding: 8px;
|
|
513
|
+
z-index: 100;
|
|
514
|
+
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
|
|
515
|
+
min-width: 150px;
|
|
516
|
+
display: flex;
|
|
517
|
+
flex-direction: column;
|
|
518
|
+
gap: 4px;
|
|
519
|
+
max-height: 250px;
|
|
520
|
+
overflow-y: auto;
|
|
521
|
+
text-align: left;
|
|
522
|
+
font-weight: normal;
|
|
523
|
+
}
|
|
524
|
+
.filter-menu.right-aligned {
|
|
525
|
+
left: auto;
|
|
526
|
+
right: 0;
|
|
527
|
+
}
|
|
528
|
+
.column-menu label, .filter-menu label {
|
|
529
|
+
display: flex;
|
|
530
|
+
align-items: center;
|
|
531
|
+
gap: 8px;
|
|
532
|
+
cursor: pointer;
|
|
533
|
+
font-weight: normal;
|
|
534
|
+
white-space: nowrap;
|
|
535
|
+
padding: 2px 0;
|
|
536
|
+
}
|
|
537
|
+
.filter-search-container {
|
|
538
|
+
display: flex;
|
|
539
|
+
gap: 4px;
|
|
540
|
+
margin-bottom: 4px;
|
|
541
|
+
}
|
|
542
|
+
.filter-search {
|
|
543
|
+
width: 100%;
|
|
544
|
+
padding: 4px;
|
|
545
|
+
border-radius: 4px;
|
|
546
|
+
flex-grow: 1;
|
|
547
|
+
}
|
|
548
|
+
.filter-sort-btn {
|
|
549
|
+
padding: 4px 8px;
|
|
550
|
+
cursor: pointer;
|
|
551
|
+
font-size: 0.8em;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
.data-cell { cursor: pointer; }
|
|
555
|
+
.data-cell.selected { background-color: #aedcff; }
|
|
556
|
+
.data-cell a { color: #007bff; text-decoration: none; }
|
|
557
|
+
.data-cell a:hover { text-decoration: underline; }
|
|
558
|
+
|
|
559
|
+
.header-cell.reorderable { cursor: grab; }
|
|
560
|
+
.header-cell.drag-over { background-color: #cceeff; }
|
|
561
|
+
|
|
562
|
+
.grid-body .grid-row:nth-of-type(even) { background-color: #f2f2f2; }
|
|
563
|
+
.grid-body .grid-row:hover { background-color: #e0e0e0; }
|
|
564
|
+
|
|
565
|
+
.pagination {
|
|
566
|
+
display: flex;
|
|
567
|
+
justify-content: space-between;
|
|
568
|
+
align-items: center;
|
|
569
|
+
padding: 12px 0;
|
|
570
|
+
font-size: 0.9em;
|
|
571
|
+
color: #000;
|
|
572
|
+
}
|
|
573
|
+
.pagination-group { display: flex; gap: 8px; }
|
|
574
|
+
.pagination button { padding: 6px 12px; border-radius: 4px; background-color: #f8f8f8; cursor: pointer; }
|
|
575
|
+
.pagination button:disabled { cursor: not-allowed; opacity: 0.5; }
|
|
576
|
+
|
|
577
|
+
.resize-handle {
|
|
578
|
+
position: absolute;
|
|
579
|
+
top: 0;
|
|
580
|
+
right: 0;
|
|
581
|
+
width: 5px;
|
|
582
|
+
height: 100%;
|
|
583
|
+
cursor: col-resize;
|
|
584
|
+
z-index: 1;
|
|
585
|
+
}
|
|
586
|
+
.resize-handle:hover {
|
|
587
|
+
background-color: #007bff;
|
|
588
|
+
}
|
|
589
|
+
`;
|
|
590
|
+
};
|
|
591
|
+
__decorate([property({ type: Array })], MyGrid.prototype, "columns", void 0), __decorate([property({ type: Array })], MyGrid.prototype, "data", void 0), __decorate([property({ type: Number })], MyGrid.prototype, "itemsPerPage", void 0), __decorate([property({ type: Boolean })], MyGrid.prototype, "columnReordering", void 0), __decorate([property({ type: String })], MyGrid.prototype, "height", void 0), __decorate([property({ type: Boolean })], MyGrid.prototype, "enableColumnVisibility", void 0), __decorate([property({ type: Boolean })], MyGrid.prototype, "enableFilter", void 0), __decorate([property()], MyGrid.prototype, "rowClass", void 0), __decorate([state()], MyGrid.prototype, "_sortKey", void 0), __decorate([state()], MyGrid.prototype, "_sortDirection", void 0), __decorate([state()], MyGrid.prototype, "_draggedColumnIndex", void 0), __decorate([state()], MyGrid.prototype, "_dragOverColumnIndex", void 0), __decorate([state()], MyGrid.prototype, "_selectedRowId", void 0), __decorate([state()], MyGrid.prototype, "_selectedColumnKey", void 0), __decorate([state()], MyGrid.prototype, "_filterValues", void 0), __decorate([state()], MyGrid.prototype, "_activeFilterColumn", void 0), __decorate([state()], MyGrid.prototype, "_filterSearchTerm", void 0), __decorate([state()], MyGrid.prototype, "_currentPage", void 0), __decorate([state()], MyGrid.prototype, "_hiddenColumns", void 0), __decorate([state()], MyGrid.prototype, "_showColumnMenu", void 0), __decorate([state()], MyGrid.prototype, "_filterMenuSortDirection", void 0), __decorate([state()], MyGrid.prototype, "_resizingColumnIndex", void 0), MyGrid = __decorate([customElement("my-grid")], MyGrid);
|
|
592
|
+
export { MyGrid as t };
|
package/dist/my-grid.js
ADDED
package/dist/vite.svg
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
package/package.json
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parksw/sw-ui-components",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.3",
|
|
5
5
|
"type": "module",
|
|
6
|
-
"main": "dist/index.js",
|
|
7
|
-
"module": "dist/index.js",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
8
9
|
"files": [
|
|
9
10
|
"dist"
|
|
10
11
|
],
|
|
11
12
|
"exports": {
|
|
12
13
|
".": "./dist/index.js",
|
|
13
|
-
"./my-button
|
|
14
|
-
"./my-calendar
|
|
15
|
-
"./my-element
|
|
14
|
+
"./my-button": "./dist/my-button.js",
|
|
15
|
+
"./my-calendar": "./dist/my-calendar.js",
|
|
16
|
+
"./my-element": "./dist/my-element.js",
|
|
17
|
+
"./my-grid": "./dist/my-grid.js",
|
|
18
|
+
"./style.css": "./dist/style.css"
|
|
16
19
|
},
|
|
17
20
|
"scripts": {
|
|
18
21
|
"dev": "vite",
|
|
19
|
-
"build": "tsc",
|
|
22
|
+
"build": "tsc && vite build",
|
|
20
23
|
"preview": "vite preview"
|
|
21
24
|
},
|
|
22
25
|
"dependencies": {
|
package/dist/index.d.ts
DELETED
package/dist/my-button.d.ts
DELETED
package/dist/my-calendar.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { LitElement } from 'lit';
|
|
2
|
-
export declare class MyCalendar extends LitElement {
|
|
3
|
-
private date;
|
|
4
|
-
private get year();
|
|
5
|
-
private get month();
|
|
6
|
-
private _changeMonth;
|
|
7
|
-
private _renderHeader;
|
|
8
|
-
private _renderDaysOfWeek;
|
|
9
|
-
private _renderDates;
|
|
10
|
-
render(): import("lit-html").TemplateResult<1>;
|
|
11
|
-
static styles: import("lit").CSSResult;
|
|
12
|
-
}
|