overview-components 1.0.67 → 1.0.69

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.
@@ -0,0 +1,526 @@
1
+ import { customElement as C } from "../node_modules/@lit/reactive-element/decorators/custom-element.js";
2
+ import { property as m } from "../node_modules/@lit/reactive-element/decorators/property.js";
3
+ import { state as y } from "../node_modules/@lit/reactive-element/decorators/state.js";
4
+ import { LitElement as L, html as v, css as T } from "lit";
5
+ import { msg as S } from "@lit/localize";
6
+ import R from "sortablejs";
7
+ import { isEmpty as K } from "lodash";
8
+ var k = Object.defineProperty, F = Object.getOwnPropertyDescriptor, a = (t, e, l, i) => {
9
+ for (var s = i > 1 ? void 0 : i ? F(e, l) : e, r = t.length - 1, h; r >= 0; r--)
10
+ (h = t[r]) && (s = (i ? h(e, l, s) : h(s)) || s);
11
+ return i && s && k(e, l, s), s;
12
+ };
13
+ let n = class extends L {
14
+ constructor() {
15
+ super(...arguments), this.value = [], this.options = [], this.label = "", this.rightLabel = "", this.allowRightSearch = !1, this.allowSelectAll = !1, this.showRightTotal = !1, this.autoSearch = !0, this.enableAssignmentsOrdering = !0, this.onChange = (t) => {
16
+ }, this.filterText = "", this.filterTextRight = "", this.appliedFilterText = "", this.appliedFilterTextRight = "", this.selectedLeftKeys = [], this.selectedRightKeys = [], this.lastSelectedIndexLeft = null, this.lastSelectedIndexRight = null, this.sortableInstances = [], this.sortableGroupId = `group-${Math.random().toString(36).substring(2, 9)}`;
17
+ }
18
+ connectedCallback() {
19
+ super.connectedCallback();
20
+ }
21
+ disconnectedCallback() {
22
+ super.disconnectedCallback(), this.destroySortables();
23
+ }
24
+ updated(t) {
25
+ this.enableAssignmentsOrdering && (t.has("value") || t.has("options")) && this.initSortables();
26
+ }
27
+ firstUpdated() {
28
+ this.enableAssignmentsOrdering && this.initSortables();
29
+ }
30
+ destroySortables() {
31
+ this.sortableInstances.forEach((t) => t.destroy()), this.sortableInstances = [];
32
+ }
33
+ initSortables() {
34
+ this.updateComplete.then(() => {
35
+ var d, c;
36
+ this.destroySortables();
37
+ const t = (d = this.shadowRoot) == null ? void 0 : d.querySelector("#left-list"), e = (c = this.shadowRoot) == null ? void 0 : c.querySelector("#right-list");
38
+ if (!t || !e) return;
39
+ let l = [], i = [];
40
+ const s = {
41
+ group: {
42
+ name: this.sortableGroupId,
43
+ pull: !0,
44
+ put: !0
45
+ },
46
+ animation: 150,
47
+ handle: ".drag-handle",
48
+ onStart: (o) => {
49
+ l = Array.from(o.from.childNodes);
50
+ },
51
+ onMove: (o) => {
52
+ o.to !== o.from && i.length === 0 && (i = Array.from(o.to.childNodes));
53
+ },
54
+ onEnd: (o) => {
55
+ o.from && l.length > 0 && (o.from.innerHTML = "", l.forEach((f) => o.from.appendChild(f))), o.to && o.to !== o.from && i.length > 0 && (o.to.innerHTML = "", i.forEach((f) => o.to.appendChild(f))), this.updateDataAfterDrag(o), this.requestUpdate();
56
+ }
57
+ }, r = R.create(t, s), h = R.create(e, s);
58
+ this.sortableInstances.push(r, h);
59
+ });
60
+ }
61
+ updateDataAfterDrag(t) {
62
+ var I;
63
+ const { from: e, to: l, oldIndex: i, newIndex: s } = t, r = e.id === "left-list" ? "left" : "right", h = l.id === "left-list" ? "left" : "right", d = t.item.getAttribute("id"), c = [...this.options, ...this.value], o = c.find((p) => String(p.value) === d);
64
+ if (!o) return;
65
+ const f = r === "left" ? this.selectedLeftKeys : this.selectedRightKeys, w = f.includes(o.value), b = w ? c.filter((p) => f.includes(p.value)) : [o];
66
+ if (r === h) {
67
+ const p = r === "left" ? [...this.options] : [...this.value];
68
+ if (w) {
69
+ const u = p.filter((g) => !f.includes(g.value));
70
+ u.splice(s, 0, ...b), r === "left" ? this.options = u : this.value = u;
71
+ } else {
72
+ const [u] = p.splice(i, 1);
73
+ p.splice(s, 0, u), r === "left" ? this.options = p : this.value = p;
74
+ }
75
+ } else if (r === "left") {
76
+ const p = this.options.filter(
77
+ (g) => !b.some((x) => x.value === g.value)
78
+ ), u = [...this.value];
79
+ b.forEach((g, x) => {
80
+ u.some(($) => $.value === g.value) || u.splice(s + x, 0, g);
81
+ }), this.options = p, this.value = u;
82
+ } else {
83
+ const p = this.value.filter(
84
+ (g) => !b.some((x) => x.value === g.value)
85
+ ), u = [...this.options];
86
+ b.forEach((g, x) => {
87
+ u.some(($) => $.value === g.value) || u.splice(s + x, 0, g);
88
+ }), this.value = p, this.options = u;
89
+ }
90
+ (I = this.onChange) == null || I.call(this, this.value), this.dispatchEvent(
91
+ new CustomEvent("onChange", {
92
+ detail: this.value
93
+ })
94
+ ), this.selectedLeftKeys = [], this.selectedRightKeys = [];
95
+ }
96
+ onInputChange(t, e) {
97
+ const l = t.detail.toLowerCase();
98
+ e === "left" ? (this.filterText = l, this.autoSearch && (this.appliedFilterText = l)) : (this.filterTextRight = l, this.autoSearch && (this.appliedFilterTextRight = l));
99
+ }
100
+ onInputKeyDown(t, e) {
101
+ !this.autoSearch && t.key === "Enter" && (e === "left" ? this.appliedFilterText = this.filterText : this.appliedFilterTextRight = this.filterTextRight);
102
+ }
103
+ getItemsForSide(t) {
104
+ return t === "left" ? this.options : this.value ?? [];
105
+ }
106
+ getSelectedKeysForSide(t) {
107
+ return t === "left" ? this.selectedLeftKeys : this.selectedRightKeys;
108
+ }
109
+ toggleSelection(t, e, l) {
110
+ const i = this.getItemsForSide(e), s = this.getSelectedKeysForSide(e), r = i.findIndex((c) => c.value === t.value), h = s.includes(t.value);
111
+ let d = [...s];
112
+ if (l != null && l.shiftKey) {
113
+ const c = e === "left" ? this.lastSelectedIndexLeft : this.lastSelectedIndexRight;
114
+ if (c !== null) {
115
+ const o = Math.min(c, r), f = Math.max(c, r), w = i.slice(o, f + 1).map((b) => b.value);
116
+ d = Array.from(/* @__PURE__ */ new Set([...d, ...w]));
117
+ }
118
+ } else
119
+ h ? d = s.filter((c) => c !== t.value) : d = [...s, t.value];
120
+ e === "left" ? (this.selectedLeftKeys = d, this.lastSelectedIndexLeft = r) : (this.selectedRightKeys = d, this.lastSelectedIndexRight = r);
121
+ }
122
+ areAllSelected(t) {
123
+ const e = this.getItemsForSide(t), l = this.getSelectedKeysForSide(t);
124
+ return e.length > 0 && e.every((i) => l.includes(i.value));
125
+ }
126
+ toggleSelectAll(t) {
127
+ const l = this.getItemsForSide(t).map((i) => i.value);
128
+ this.areAllSelected(t) ? t === "left" ? this.selectedLeftKeys = [] : this.selectedRightKeys = [] : t === "left" ? this.selectedLeftKeys = l : this.selectedRightKeys = l;
129
+ }
130
+ moveSelected(t, e) {
131
+ var c;
132
+ const l = this.getItemsForSide(t), i = this.getSelectedKeysForSide(t), s = l.filter((o) => i.includes(o.value)), h = [...this.getItemsForSide(e)];
133
+ s.forEach((o) => {
134
+ h.some((f) => f.value === o.value) || h.push(o);
135
+ });
136
+ const d = l.filter((o) => !i.includes(o.value));
137
+ t === "left" ? (this.options = d, this.selectedLeftKeys = [], this.value = h) : (this.value = d, this.selectedRightKeys = [], this.options = h), (c = this.onChange) == null || c.call(this, this.value), this.dispatchEvent(
138
+ new CustomEvent("onChange", {
139
+ detail: this.value
140
+ })
141
+ );
142
+ }
143
+ moveSingle(t, e, l) {
144
+ var i;
145
+ e === "left" ? (this.options = this.options.filter((s) => s.value !== t.value), (this.value ?? []).some((s) => s.value === t.value) || (this.value = [...this.value ?? [], t]), this.selectedLeftKeys = this.selectedLeftKeys.filter((s) => s !== t.value), this.appliedFilterTextRight = "") : (this.value = (this.value ?? []).filter((s) => s.value !== t.value), this.options.some((s) => s.value === t.value) || (this.options = [...this.options, t]), this.selectedRightKeys = this.selectedRightKeys.filter((s) => s !== t.value), this.appliedFilterText = ""), (i = this.onChange) == null || i.call(this, this.value), this.dispatchEvent(
146
+ new CustomEvent("onChange", {
147
+ detail: this.value
148
+ })
149
+ );
150
+ }
151
+ render() {
152
+ var t;
153
+ return v`<div class="container">
154
+ <div class="wrapper">
155
+ <label class="label">${this.label}</label>
156
+ <div class="tab">
157
+ <div class="input">
158
+ <lit-input
159
+ placeholder=${S("Napr. fakturace...")}
160
+ .onInput=${(e) => this.onInputChange(
161
+ new CustomEvent("onInput", { detail: e }),
162
+ "left"
163
+ )}
164
+ @keydown=${(e) => this.onInputKeyDown(e, "left")}
165
+ .onClear=${() => {
166
+ this.filterText = "", this.appliedFilterText = "";
167
+ }}
168
+ .size="medium"
169
+ ></lit-input>
170
+ </div>
171
+
172
+ <div class="content">
173
+ <lit-menu tabindex="0" id="left-list">
174
+ ${this.options.filter((e) => {
175
+ const l = e.title.toLowerCase(), i = this.appliedFilterText.toLowerCase();
176
+ return l.includes(i);
177
+ }).map((e) => {
178
+ const l = this.selectedLeftKeys.includes(e.value);
179
+ return v`
180
+ <lit-menu-item
181
+ class="no-select"
182
+ .key="${e.value}"
183
+ .id="${e.value}"
184
+ @click=${(i) => this.toggleSelection(e, "left", i)}
185
+ .isSelected=${l}
186
+ >
187
+ <div class="item">
188
+ <div class="item-text">${e.title}</div>
189
+
190
+ <div class="add-minus-icon">
191
+ ${this.enableAssignmentsOrdering ? v`
192
+ <div class="drag-handle">
193
+ <lit-icon
194
+ icon="hamburger"
195
+ size="1rem"
196
+ @click=${(i) => {
197
+ i.stopPropagation();
198
+ }}
199
+ ></lit-icon>
200
+ </div>
201
+ ` : null}
202
+
203
+ <lit-icon
204
+ .icon="${"add"}"
205
+ size="1rem"
206
+ @click=${(i) => {
207
+ i.stopPropagation(), this.moveSingle(e, "left", "right");
208
+ }}
209
+ ></lit-icon>
210
+ </div>
211
+ </div>
212
+ </lit-menu-item>
213
+ `;
214
+ })}
215
+ </lit-menu>
216
+ </div>
217
+
218
+ <div class="footer">
219
+ <div class="checkbox">
220
+ ${this.allowSelectAll ? v`
221
+ <lit-checkbox
222
+ .checked=${this.areAllSelected("left")}
223
+ @click=${() => this.toggleSelectAll("left")}
224
+ ></lit-checkbox>
225
+ <label>${S("Označit vše")}</label>
226
+ ` : null}
227
+ </div>
228
+
229
+ <div class="count">
230
+ <label>${S("celkem") + ":"}</label>
231
+ <label>${this.options.length}</label>
232
+ </div>
233
+ </div>
234
+ </div>
235
+ </div>
236
+ <div class="wrapper middle">
237
+ <lit-icon-button
238
+ .variant="${"text"}"
239
+ .icon="${"add"}"
240
+ @click=${() => this.moveSelected("left", "right")}
241
+ .disabled="${K(this.selectedLeftKeys)}"
242
+ ></lit-icon-button>
243
+ <lit-icon-button
244
+ .variant="${"text"}"
245
+ .icon="${"minus"}"
246
+ @click=${() => this.moveSelected("right", "left")}
247
+ .disabled="${K(this.selectedRightKeys)}"
248
+ ></lit-icon-button>
249
+ </div>
250
+ <div class="wrapper">
251
+ <label class="label">${this.rightLabel}</label>
252
+ <div class="tab">
253
+ <div class="input">
254
+ ${this.allowRightSearch ? v`
255
+ <lit-input
256
+ placeholder=${S("Napr. fakturace...")}
257
+ .onInput=${(e) => this.onInputChange(
258
+ new CustomEvent("onInput", { detail: e }),
259
+ "right"
260
+ )}
261
+ @keydown=${(e) => this.onInputKeyDown(e, "right")}
262
+ .onClear=${() => {
263
+ this.filterTextRight = "", this.appliedFilterTextRight = "";
264
+ }}
265
+ .size="medium"
266
+ ></lit-input>
267
+ ` : null}
268
+ </div>
269
+ <div class="content">
270
+ <lit-menu tabindex="1" id="right-list">
271
+ ${(this.value ?? []).filter((e) => {
272
+ const l = e.title.toLowerCase(), i = this.appliedFilterTextRight.toLowerCase();
273
+ return l.includes(i);
274
+ }).map((e) => {
275
+ const l = this.selectedRightKeys.includes(e.value);
276
+ return v`
277
+ <lit-menu-item
278
+ class="no-select"
279
+ .key="${e.value}"
280
+ id="${e.value}"
281
+ @click=${(i) => this.toggleSelection(e, "right", i)}
282
+ .isSelected=${l}
283
+ >
284
+ <div class="item">
285
+ <div class="item-text">${e.title}</div>
286
+ <div class="add-minus-icon">
287
+ ${this.enableAssignmentsOrdering ? v`
288
+ <div class="drag-handle">
289
+ <lit-icon
290
+ icon="hamburger"
291
+ size="1rem"
292
+ @click=${(i) => {
293
+ i.stopPropagation();
294
+ }}
295
+ ></lit-icon>
296
+ </div>
297
+ ` : null}
298
+ <lit-icon
299
+ .icon="${"minus"}"
300
+ size="1rem"
301
+ @click=${(i) => {
302
+ i.stopPropagation(), this.moveSingle(e, "right", "left");
303
+ }}
304
+ ></lit-icon>
305
+ </div>
306
+ </div>
307
+ </lit-menu-item>
308
+ `;
309
+ })}
310
+ </lit-menu>
311
+ </div>
312
+ <div class="footer">
313
+ <div class="checkbox">
314
+ ${this.allowSelectAll ? v`
315
+ <lit-checkbox
316
+ .checked=${this.areAllSelected("right")}
317
+ @click=${() => this.toggleSelectAll("right")}
318
+ ></lit-checkbox>
319
+ <label>${S("Označit vše")}</label>
320
+ ` : null}
321
+ </div>
322
+
323
+ <div class="count">
324
+ ${this.showRightTotal ? v`
325
+ <label>${S("celkem") + ":"}</label>
326
+ <label>${((t = this.value) == null ? void 0 : t.length) ?? 0}</label>
327
+ ` : null}
328
+ </div>
329
+ </div>
330
+ </div>
331
+ </div>
332
+ </div>`;
333
+ }
334
+ };
335
+ n.styles = [
336
+ T`
337
+ @media (max-width: 600px) {
338
+ .container {
339
+ flex-direction: column;
340
+ }
341
+ .wrapper.middle {
342
+ flex-direction: row !important;
343
+ justify-content: center;
344
+ height: auto !important;
345
+ padding-top: 0 !important;
346
+ }
347
+ }
348
+
349
+ .container {
350
+ display: flex;
351
+ justify-content: space-between;
352
+ width: 100%;
353
+ height: 100%;
354
+ gap: 0.375rem;
355
+ }
356
+
357
+ .wrapper {
358
+ display: flex;
359
+ flex-direction: column;
360
+ flex: 1 1 0;
361
+ height: 100%;
362
+ min-width: 0;
363
+ min-height: 0;
364
+ }
365
+
366
+ .wrapper.middle {
367
+ flex: 0 0 auto;
368
+ flex-direction: column;
369
+ padding-top: 2rem;
370
+ gap: 0.5rem;
371
+ align-items: center;
372
+ }
373
+
374
+ .label {
375
+ font-weight: 500;
376
+ font-size: 14px;
377
+ color: var(--text-secondary, #5d6371);
378
+ line-height: 1.5rem;
379
+ padding-left: 0.875rem;
380
+ margin-bottom: 0.375rem;
381
+ }
382
+
383
+ .tab {
384
+ display: flex;
385
+ flex-direction: column;
386
+ height: 100%;
387
+ border-radius: var(--border-radius-small, 0.5rem);
388
+ border: 1px solid var(--border-primary, #d0d3db);
389
+ padding: 0.5rem;
390
+ gap: 0.5rem;
391
+ min-height: 0;
392
+ }
393
+
394
+ .input {
395
+ }
396
+
397
+ .content {
398
+ flex-grow: 1;
399
+ overflow: auto;
400
+ min-height: 0;
401
+ }
402
+
403
+ .footer {
404
+ border-top: 1px solid var(--border-primary, #d0d3db);
405
+ display: flex;
406
+ justify-content: space-between;
407
+ align-items: center;
408
+ min-height: 2.375rem;
409
+ }
410
+
411
+ .footer.csv {
412
+ justify-content: end;
413
+ }
414
+
415
+ .csv-icon {
416
+ padding-right: 0.5rem;
417
+ }
418
+
419
+ .checkbox {
420
+ display: flex;
421
+ align-items: center;
422
+ padding: 0.25rem 0.5rem;
423
+ gap: 0.375rem;
424
+ font-size: 12px;
425
+ font-weight: 500;
426
+ }
427
+
428
+ .count {
429
+ display: flex;
430
+ align-items: center;
431
+ padding: 0.25rem 0.5rem;
432
+ gap: 0.375rem;
433
+ font-size: 12px;
434
+ font-weight: 400;
435
+ }
436
+
437
+ .item {
438
+ display: flex;
439
+ width: 100%;
440
+ justify-content: space-between;
441
+ align-items: center;
442
+ }
443
+
444
+ .item-text {
445
+ overflow: hidden;
446
+ white-space: nowrap;
447
+ text-overflow: ellipsis;
448
+ }
449
+
450
+ .add-minus-icon {
451
+ visibility: hidden;
452
+ display: flex;
453
+ align-items: center;
454
+ gap: 0.5rem;
455
+ }
456
+
457
+ .item:hover .add-minus-icon {
458
+ visibility: visible;
459
+ }
460
+
461
+ .no-select {
462
+ user-select: none;
463
+ min-height: 2rem;
464
+ }
465
+ `
466
+ ];
467
+ a([
468
+ m({ type: Array })
469
+ ], n.prototype, "value", 2);
470
+ a([
471
+ m({ type: Array })
472
+ ], n.prototype, "options", 2);
473
+ a([
474
+ m({ type: String })
475
+ ], n.prototype, "label", 2);
476
+ a([
477
+ m({ type: String })
478
+ ], n.prototype, "rightLabel", 2);
479
+ a([
480
+ m({ type: Boolean })
481
+ ], n.prototype, "allowRightSearch", 2);
482
+ a([
483
+ m({ type: Boolean })
484
+ ], n.prototype, "allowSelectAll", 2);
485
+ a([
486
+ m({ type: Boolean })
487
+ ], n.prototype, "showRightTotal", 2);
488
+ a([
489
+ m({ type: Boolean })
490
+ ], n.prototype, "autoSearch", 2);
491
+ a([
492
+ m({ type: Boolean })
493
+ ], n.prototype, "enableAssignmentsOrdering", 2);
494
+ a([
495
+ m({ type: Function })
496
+ ], n.prototype, "onChange", 2);
497
+ a([
498
+ y()
499
+ ], n.prototype, "filterText", 2);
500
+ a([
501
+ y()
502
+ ], n.prototype, "filterTextRight", 2);
503
+ a([
504
+ y()
505
+ ], n.prototype, "appliedFilterText", 2);
506
+ a([
507
+ y()
508
+ ], n.prototype, "appliedFilterTextRight", 2);
509
+ a([
510
+ y()
511
+ ], n.prototype, "selectedLeftKeys", 2);
512
+ a([
513
+ y()
514
+ ], n.prototype, "selectedRightKeys", 2);
515
+ a([
516
+ y()
517
+ ], n.prototype, "lastSelectedIndexLeft", 2);
518
+ a([
519
+ y()
520
+ ], n.prototype, "lastSelectedIndexRight", 2);
521
+ n = a([
522
+ C("lit-multiselect-item")
523
+ ], n);
524
+ export {
525
+ n as LitMultiselectItem
526
+ };