@kubex/zinc 1.0.5 → 1.0.7

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.
Files changed (29) hide show
  1. package/dist/custom-elements.json +302 -16
  2. package/dist/vscode.html-custom-data.json +13 -2
  3. package/dist/web-types.json +43 -5
  4. package/dist/zn.d.ts +81 -40
  5. package/dist/zn.min.js +333 -270
  6. package/package.json +1 -1
  7. package/src/components/bulk-actions/bulk-actions.component.ts +152 -84
  8. package/src/components/bulk-actions/bulk-actions.scss +2 -0
  9. package/src/components/chart/chart.component.ts +14 -12
  10. package/src/components/cols/cols.component.ts +7 -3
  11. package/src/components/cols/cols.scss +22 -14
  12. package/src/components/content-block/content-block.component.ts +164 -30
  13. package/src/components/data-select/data-select.component.ts +51 -10
  14. package/src/components/data-table/data-table.component.ts +58 -38
  15. package/src/components/data-table/data-table.scss +74 -7
  16. package/src/components/data-table-filter/data-table-filter.component.ts +1 -1
  17. package/src/components/editor/modules/attachment/attachment.ts +53 -41
  18. package/src/components/editor/modules/toolbar/toolbar.ts +42 -0
  19. package/src/components/empty-state/empty-state.component.ts +16 -8
  20. package/src/components/icon/icon.component.ts +2 -0
  21. package/src/components/icon/icon.scss +13 -0
  22. package/src/components/inline-edit/inline-edit.component.ts +24 -3
  23. package/src/components/inline-edit/inline-edit.scss +11 -1
  24. package/src/components/item/item.component.ts +11 -3
  25. package/src/components/item/item.scss +14 -19
  26. package/src/components/panel/panel.component.ts +2 -0
  27. package/src/components/panel/panel.scss +6 -0
  28. package/src/components/settings-container/settings-container.scss +11 -4
  29. package/src/components/style/style.component.ts +7 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubex/zinc",
3
- "version": "1.0.5",
3
+ "version": "1.0.7",
4
4
  "description": "A collection of web components for building web applications based off of @shoelace-style/Shoelace",
5
5
  "keywords": [
6
6
  "web components",
@@ -1,8 +1,15 @@
1
1
  import {classMap} from "lit/directives/class-map.js";
2
2
  import {type CSSResultGroup, html, type PropertyValues, unsafeCSS} from 'lit';
3
3
  import {FormControlController} from "../../internal/form";
4
+ import {litToHTML} from "../../utilities/lit-to-html";
4
5
  import {property, query} from 'lit/decorators.js';
5
6
  import ZincElement from '../../internal/zinc-element';
7
+ import ZnButton from "../button";
8
+ import ZnInput from "../input";
9
+ import ZnOption from "../option";
10
+ import ZnSelect from "../select";
11
+ import type {ZnChangeEvent} from "../../events/zn-change";
12
+ import type {ZnInputEvent} from "../../events/zn-input";
6
13
 
7
14
  import styles from './bulk-actions.scss';
8
15
 
@@ -29,7 +36,10 @@ export interface BulkActionItem {
29
36
  * @status experimental
30
37
  * @since 1.0
31
38
  *
32
- * @dependency zn-example
39
+ * @dependency zn-button
40
+ * @dependency zn-input
41
+ * @dependency zn-option
42
+ * @dependency zn-select
33
43
  *
34
44
  * @event zn-event-name - Emitted as an example.
35
45
  *
@@ -42,9 +52,15 @@ export interface BulkActionItem {
42
52
  */
43
53
  export default class ZnBulkActions extends ZincElement {
44
54
  static styles: CSSResultGroup = unsafeCSS(styles);
55
+ static dependencies = {
56
+ 'zn-button': ZnButton,
57
+ 'zn-input': ZnInput,
58
+ 'zn-option': ZnOption,
59
+ 'zn-select': ZnSelect,
60
+ };
45
61
 
46
62
  @query('.bulk-actions') container: HTMLDivElement;
47
- @query('.add-rule') addRule: HTMLSelectElement;
63
+ @query('.add-rule') addRule: ZnSelect;
48
64
  @query('input#main-input') input: HTMLInputElement;
49
65
 
50
66
  @property() name: string;
@@ -73,12 +89,13 @@ export default class ZnBulkActions extends ZincElement {
73
89
  <div class="${classMap({
74
90
  'bulk-actions': true
75
91
  })}">
76
- <select class="add-rule" @change="${this._addRule}">
77
- <option value="">Select Filter</option>
92
+ <zn-select class="add-rule" placeholder="Select Filter" @zn-change="${this._addRule}">
78
93
  ${this.actions.map((item: BulkActionItem) => html`
79
- <option value="${item.id}">${item.name.charAt(0).toUpperCase() + item.name.slice(1)}</option>`)}
80
- </select>
81
- <input id="main-input" name="${this.name}" value="${this.value}" type="hidden">
94
+ <zn-option value="${item.id}">
95
+ ${item.name.charAt(0).toUpperCase() + item.name.slice(1)}
96
+ </zn-option>`)}
97
+ </zn-select>
98
+ <input id="main-input" name="${this.name}" value="${this.value}" hidden>
82
99
  </div>
83
100
  `;
84
101
  }
@@ -95,8 +112,9 @@ export default class ZnBulkActions extends ZincElement {
95
112
  this.value = btoa(JSON.stringify(data));
96
113
  }
97
114
 
98
- private _addRule(event: Event | null, value: string = "") {
99
- const id = value ? value : event ? (event.target as HTMLSelectElement).value : '';
115
+ private _addRule(event: Event | null, value: string = "", pos?: number) {
116
+ const target = event?.target as ZnSelect;
117
+ const id = value ? value : target?.value || '';
100
118
  if (id === '') return;
101
119
 
102
120
  const filter = this.actions.find(item => item.id === id);
@@ -109,104 +127,154 @@ export default class ZnBulkActions extends ZincElement {
109
127
  value: ''
110
128
  });
111
129
 
112
- const row = document.createElement('div');
113
- row.classList.add('query-builder__row');
114
- row.id = uniqueId;
115
-
116
- const select = document.createElement('select');
117
- this.actions.forEach(item => {
118
- const option = document.createElement('option');
119
- option.value = item.id;
120
- option.text = item.name.charAt(0).toUpperCase() + item.name.slice(1);
121
- option.selected = item.id === filter.id;
122
- select.appendChild(option);
123
- });
124
- select.addEventListener('change', (e: Event) => this._changeRule(uniqueId, e));
125
- select.classList.add('query-builder__key');
130
+ const keySelect = html`
131
+ <zn-select class="query-builder__key"
132
+ @zn-change="${(e: ZnChangeEvent) => this._changeRule(uniqueId, e)}"
133
+ value="${filter.id}">
134
+ ${this.actions.map((item: BulkActionItem) => html`
135
+ <zn-option value="${item.id}">
136
+ ${item.name.charAt(0).toUpperCase() + item.name.slice(1)}
137
+ </zn-option>
138
+ `)}
139
+ </zn-select>
140
+ `;
126
141
 
127
- row.appendChild(select);
142
+ const input = this._createInput(uniqueId, filter);
143
+
144
+ const remove = html`
145
+ <zn-button class="query-builder__remove"
146
+ icon="delete"
147
+ icon-size="24"
148
+ color="transparent"
149
+ size="square"
150
+ @click="${(e: Event) => this._removeRule(uniqueId, e)}">
151
+ </zn-button>`;
152
+
153
+ const wrapper = html`
154
+ <div class="query-builder__wrapper">
155
+ ${input}
156
+ ${remove}
157
+ </div>
158
+ `;
128
159
 
129
- let input: HTMLSelectElement | HTMLInputElement | HTMLDivElement;
130
- if (filter.options) {
131
- input = document.createElement('select');
132
- const options = Object.keys(filter.options);
133
- options.forEach((item: string) => {
134
- const option = document.createElement('option');
135
- option.value = item;
136
- option.text = filter.options ? (filter.options[item]) : '';
137
- input.appendChild(option);
138
- });
139
- this._updateValue(uniqueId, {target: input});
140
- input.addEventListener('change', (e: Event) => this._updateValue(uniqueId, e));
141
- } else if (filter.type === 'bool' || filter.type === 'boolean') {
142
- input = document.createElement('select');
143
- const option1 = document.createElement('option');
144
- option1.value = '1';
145
- option1.text = 'True';
146
- input.appendChild(option1);
147
- const option2 = document.createElement('option');
148
- option2.value = '0';
149
- option2.text = 'False';
150
- input.appendChild(option2);
151
- input.addEventListener('change', (e: Event) => this._updateValue(uniqueId, e));
152
- } else if (filter.type === 'number') {
153
- input = document.createElement('input');
154
- input.setAttribute('type', 'number');
155
- input.addEventListener('input', (e: Event) => this._updateValue(uniqueId, e));
156
- } else if (filter.type === 'date') {
157
- input = document.createElement('input');
158
- input.setAttribute('type', 'date');
159
- input.addEventListener('input', (e: Event) => this._updateValue(uniqueId, e));
160
+ const rowElement = html`
161
+ <div id="${uniqueId}" class="query-builder__row">
162
+ ${keySelect}
163
+ ${wrapper}
164
+ </div>
165
+ `;
166
+
167
+ const row = litToHTML<HTMLDivElement>(rowElement);
168
+ if (!row) return;
169
+
170
+ if (pos !== undefined) {
171
+ this.container.insertBefore(row, this.container.children[pos]);
160
172
  } else {
161
- input = document.createElement('input');
162
- input.setAttribute('type', 'text');
163
- input.addEventListener('input', (e: Event) => this._updateValue(uniqueId, e));
173
+ this.container.insertBefore(row, this.addRule);
164
174
  }
165
175
 
166
- input.classList.add('query-builder__value');
167
- const wrapper = document.createElement('div');
168
- wrapper.classList.add('query-builder__wrapper');
169
- wrapper.appendChild(input);
170
- row.appendChild(wrapper);
171
-
172
- const remove = document.createElement('zn-button');
173
- remove.setAttribute('icon', 'delete');
174
- remove.setAttribute('icon-size', '24');
175
- remove.setAttribute('color', 'transparent');
176
- remove.setAttribute('size', 'square');
177
- remove.addEventListener('click', (e: Event) => this._removeRule(uniqueId, e));
178
- remove.classList.add('query-builder__remove');
179
- row.appendChild(remove);
180
-
181
- this.container.insertBefore(row, this.addRule);
176
+ // Reset back to default placeholder
182
177
  this.addRule.value = '';
178
+ this.addRule.displayLabel = '';
179
+ if (this.addRule.selectedOptions?.length) {
180
+ this.addRule.selectedOptions[0].selected = false;
181
+ }
182
+
183
183
  this._handleChange();
184
184
  }
185
185
 
186
- private _updateValue(id: string, event: Event | { target: HTMLSelectElement | HTMLInputElement | HTMLDivElement }) {
186
+ private _createInput(uniqueId: string, filter: BulkActionItem): ZnSelect | ZnInput | null {
187
+ if (filter.options) {
188
+ const input = html`
189
+ <zn-select class="query-builder__value"
190
+ @zn-change="${(e: ZnChangeEvent) => this._updateValue(uniqueId, e)}">
191
+ ${Object.keys(filter.options).map(key => html`
192
+ <zn-option value="${key}">
193
+ ${filter.options ? filter.options[key] : ''}
194
+ </zn-option>
195
+ `)}
196
+ </zn-select>`;
197
+ const el = litToHTML<ZnSelect>(input);
198
+ if (el) {
199
+ // initialize with current selection
200
+ this._updateValue(uniqueId, {target: el} as unknown as Event);
201
+ }
202
+ return el;
203
+ }
204
+
205
+ if (filter.type === 'bool' || filter.type === 'boolean') {
206
+ const input = html`
207
+ <zn-select class="query-builder__value"
208
+ @zn-change="${(e: ZnChangeEvent) => this._updateValue(uniqueId, e)}">
209
+ <zn-option value="1">True</zn-option>
210
+ <zn-option value="0">False</zn-option>
211
+ </zn-select>`;
212
+ return litToHTML<ZnSelect>(input);
213
+ }
214
+
215
+ if (filter.type === 'number') {
216
+ const input = html`
217
+ <zn-input type="number"
218
+ class="query-builder__value"
219
+ @zn-input="${(e: ZnInputEvent) => this._updateValue(uniqueId, e)}">
220
+ </zn-input>`;
221
+ return litToHTML<ZnInput>(input);
222
+ }
223
+
224
+ if (filter.type === 'date') {
225
+ const input = html`
226
+ <zn-input type="date"
227
+ class="query-builder__value"
228
+ @zn-input="${(e: ZnInputEvent) => this._updateValue(uniqueId, e)}">
229
+ </zn-input>`;
230
+ return litToHTML<ZnInput>(input);
231
+ }
232
+
233
+ const input = html`
234
+ <zn-input type="text"
235
+ class="query-builder__value"
236
+ @zn-input="${(e: ZnInputEvent) => this._updateValue(uniqueId, e)}">
237
+ </zn-input>`;
238
+ return litToHTML<ZnInput>(input);
239
+ }
240
+
241
+ private _updateValue(id: string, event: Event | { target: ZnSelect | ZnInput | HTMLDivElement }) {
187
242
  const filter = this._selectedRules.get(id);
188
243
  if (!filter) return;
189
244
 
190
- const input = event.target as HTMLSelectElement | HTMLInputElement;
191
- filter.value = input.value;
245
+ const input = event.target as ZnSelect | ZnInput;
246
+ filter.value = input.value as string;
192
247
 
193
248
  this._selectedRules.set(id, filter);
194
249
  this._handleChange();
195
250
  }
196
251
 
197
- private _changeRule(id: string, event: Event) {
252
+ private _getRulePosition(id: string): number {
253
+ const rules = this.container.querySelectorAll('.query-builder__row');
254
+ let position: number = -1;
255
+ rules.forEach((item, index) => {
256
+ if ((item as HTMLDivElement).id === id) {
257
+ position = index;
258
+ }
259
+ });
260
+ return position;
261
+ }
262
+
263
+ private _changeRule(id: string, event: ZnChangeEvent) {
198
264
  // remove the element from the dom
199
- const button = event.target as HTMLSelectElement;
200
- button.parentElement?.remove();
265
+ const pos: number = this._getRulePosition(id);
266
+ const select = event.target as ZnSelect;
267
+ select.popup.active = false;
268
+ select?.parentElement?.remove();
201
269
  // recreate the element based on the selected value;
202
- this._removeRule(id, event);
203
- this._addRule(event);
270
+ this._removeRule(id, event as unknown as Event);
271
+ this._addRule(event as unknown as Event, '', pos);
204
272
  }
205
273
 
206
274
  private _removeRule(id: string, event: Event) {
207
275
  this._selectedRules.delete(id);
208
- const button = event.target as HTMLButtonElement;
209
- button.parentElement?.remove();
276
+ const button = event.target as ZnButton;
277
+ button?.closest('.query-builder__row')?.remove();
210
278
  this._handleChange();
211
279
  }
212
280
 
@@ -40,7 +40,9 @@
40
40
  }
41
41
 
42
42
  &__wrapper {
43
+ display: flex;
43
44
  width: 100%;
45
+ gap: 10px;
44
46
  }
45
47
 
46
48
  &__date {
@@ -1,5 +1,5 @@
1
- import { type CSSResultGroup, html, type PropertyValues, unsafeCSS } from 'lit';
2
- import { property } from 'lit/decorators.js';
1
+ import {type CSSResultGroup, html, type PropertyValues, unsafeCSS} from 'lit';
2
+ import {property} from 'lit/decorators.js';
3
3
  import ApexCharts from "apexcharts";
4
4
  import ZincElement from '../../internal/zinc-element';
5
5
 
@@ -26,21 +26,22 @@ export default class ZnChart extends ZincElement {
26
26
  static styles: CSSResultGroup = unsafeCSS(styles);
27
27
 
28
28
  @property() type: 'area' | 'bar' | 'line' = 'bar';
29
- @property({ type: Array }) data: any[] = [];
30
- @property({ type: Array }) categories: string | string[] = '';
29
+ @property({type: Array}) data: any[] = [];
30
+ @property({type: Array}) categories: string | string[] = '';
31
31
 
32
32
  @property() xAxis: string;
33
- @property({ type: Number, attribute: 'd-size' }) datapointSize: number = 1;
33
+ @property({type: Number, attribute: 'd-size'}) datapointSize: number = 1;
34
+ @property({type: Boolean}) stacked = false;
34
35
 
35
36
  // Live
36
- @property({ type: Boolean }) live = false;
37
- @property({ attribute: 'data-url' }) dataUrl = '';
38
- @property({ attribute: 'live-interval', type: Number }) liveInterval = 1000;
39
- @property({ type: Number, reflect: true }) height = 300;
37
+ @property({type: Boolean}) live = false;
38
+ @property({attribute: 'data-url'}) dataUrl = '';
39
+ @property({attribute: 'live-interval', type: Number}) liveInterval = 1000;
40
+ @property({type: Number, reflect: true}) height = 300;
40
41
 
41
- @property({ attribute: 'enable-animations', type: Boolean }) enableAnimations = false;
42
+ @property({attribute: 'enable-animations', type: Boolean}) enableAnimations = false;
42
43
 
43
- @property({ attribute: 'y-axis-append' }) yAxisAppend: string;
44
+ @property({attribute: 'y-axis-append'}) yAxisAppend: string;
44
45
 
45
46
  private chart: ApexCharts;
46
47
 
@@ -54,10 +55,11 @@ export default class ZnChart extends ZincElement {
54
55
  animations: this.enableAnimations,
55
56
  chart: {
56
57
  type: this.type,
57
- toolbar: { show: false },
58
+ toolbar: {show: false},
58
59
  foreColor: theme == 'dark' ? "rgb(149, 163, 184)" : "rgb(123, 112, 151)",
59
60
  height: this.height + 'px',
60
61
  fontFamily: '"Inter", sans',
62
+ stacked: this.stacked,
61
63
  zoom: {
62
64
  enabled: false
63
65
  },
@@ -25,7 +25,6 @@ import styles from './cols.scss';
25
25
  export default class ZnCols extends ZincElement {
26
26
  static styles: CSSResultGroup = unsafeCSS(styles);
27
27
 
28
-
29
28
  @property({reflect: true, attribute: 'layout'}) layout: string = '';
30
29
 
31
30
  @property({attribute: 'mc', type: Number, reflect: true}) maxColumns: number = 0;
@@ -35,7 +34,11 @@ export default class ZnCols extends ZincElement {
35
34
  @property({type: Boolean}) border: boolean = false;
36
35
 
37
36
  @property({type: Boolean}) pad: boolean;
37
+
38
+ @property({type: Boolean}) divide: boolean = false;
39
+
38
40
  @property({attribute: 'pad-x', type: Boolean}) padX: boolean;
41
+
39
42
  @property({attribute: 'pad-y', type: Boolean}) padY: boolean;
40
43
 
41
44
  render() {
@@ -47,7 +50,7 @@ export default class ZnCols extends ZincElement {
47
50
 
48
51
  this.layout = layout.join(',');
49
52
 
50
- this.maxColumns = Math.min(5, layout.reduce((a, b) => a + b, 0));
53
+ this.maxColumns = layout.reduce((a, b) => a + b, 0);
51
54
 
52
55
  const prefix = 'zn-col-';
53
56
  this.querySelectorAll(':scope > *').forEach((element: HTMLElement, index) => {
@@ -66,7 +69,8 @@ export default class ZnCols extends ZincElement {
66
69
  'cols--pad': this.pad,
67
70
  'cols--pad-x': this.padX,
68
71
  'cols--pad-y': this.padY,
69
- [`cols--layout-${this.layout.replace(',', '')}`]: !!this.layout,
72
+ 'cols--divide': this.divide,
73
+ [`cols--layout-${this.layout.replaceAll(',', '')}`]: !!this.layout,
70
74
  [`cols--mc-${this.maxColumns}`]: !!this.maxColumns,
71
75
  })}">
72
76
  <slot></slot>
@@ -26,20 +26,10 @@
26
26
  }
27
27
  }
28
28
 
29
- &--mc-2 {
30
- --col-width: 40%;
31
- }
32
-
33
- &--mc-3 {
34
- --col-width: 30%;
35
- }
36
-
37
- &--mc-4 {
38
- --col-width: 23%;
39
- }
40
-
41
- &--mc-5 {
42
- --col-width: 18%;
29
+ @for $i from 1 through 12 {
30
+ &--mc-#{$i} {
31
+ --col-width: calc(100% / #{$i + 1});
32
+ }
43
33
  }
44
34
 
45
35
  &--layout-121 {
@@ -54,6 +44,24 @@
54
44
  }
55
45
  }
56
46
 
47
+ &--divide {
48
+ ::slotted(*:not(:last-child)) {
49
+ position: relative;
50
+
51
+ &:after {
52
+ content: "";
53
+ position: absolute;
54
+ display: block;
55
+ width: 1px;
56
+ top: 0;
57
+ height: 100%;
58
+ max-height: 100%;
59
+ right: calc((var(--zn-spacing-small) / 2) * -1);
60
+ background-color: rgb(var(--zn-border-color));
61
+ }
62
+ }
63
+ }
64
+
57
65
  &--no-gap {
58
66
  gap: 0;
59
67
  }