@kubex/zinc 1.0.20 → 1.0.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubex/zinc",
3
- "version": "1.0.20",
3
+ "version": "1.0.21",
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",
@@ -156,6 +156,7 @@ export default class ZnInlineEdit extends ZincElement implements ZincFormControl
156
156
  submitKeyHandler = (e: KeyboardEvent) => {
157
157
  if (e.key === 'Enter' && this.isEditing) {
158
158
  this.isEditing = false;
159
+ this.emit('zn-submit', {detail: {value: this.value, element: this}});
159
160
  this.formControlController.submit();
160
161
  this.input.blur();
161
162
  }
@@ -186,6 +187,7 @@ export default class ZnInlineEdit extends ZincElement implements ZincFormControl
186
187
  handleSubmitClick = (e: MouseEvent) => {
187
188
  e.preventDefault();
188
189
  this.isEditing = false;
190
+ this.emit('zn-submit', {detail: {value: this.value, element: this}});
189
191
  this.formControlController.submit();
190
192
  };
191
193
 
@@ -1,5 +1,6 @@
1
1
  import {classMap} from "lit/directives/class-map.js";
2
2
  import {type CSSResultGroup, html, type PropertyValues, unsafeCSS} from 'lit';
3
+ import {ifDefined} from "lit/directives/if-defined.js";
3
4
  import {property} from 'lit/decorators.js';
4
5
  import ZincElement from '../../internal/zinc-element';
5
6
  import ZnDropdown from "../dropdown";
@@ -41,6 +42,7 @@ export default class ZnNavbar extends ZincElement {
41
42
  @property({type: Array}) dropdown = [];
42
43
  @property({attribute: "no-pad", type: Boolean}) noPad: false
43
44
  @property({attribute: 'manual-add-items', type: Boolean}) manualAddItems = false;
45
+ @property({type: Boolean}) isolated = false;
44
46
 
45
47
  private _preItems: NodeListOf<Element>;
46
48
  private _postItems: NodeListOf<Element>;
@@ -194,6 +196,17 @@ export default class ZnNavbar extends ZincElement {
194
196
  //console.log("Showing More")
195
197
  }
196
198
 
199
+ private handleClick = (e: MouseEvent) => {
200
+ const path = e.composedPath();
201
+ const tabAttr = this.isolated ? 'data-tab' : 'tab';
202
+ const li = path.find(el => el instanceof HTMLElement && el.tagName === 'LI' && (el.hasAttribute(tabAttr) || el.hasAttribute('tab-uri'))) as HTMLElement;
203
+
204
+ if (li) {
205
+ e.stopPropagation();
206
+ this.emit('zn-select', {detail: {item: li}});
207
+ }
208
+ };
209
+
197
210
  render() {
198
211
  if (!this.navigation) {
199
212
  this.navigation = [];
@@ -211,7 +224,7 @@ export default class ZnNavbar extends ZincElement {
211
224
  'navbar__container--stacked': this.stacked,
212
225
  'navbar__container--icon-bar': this.iconBar
213
226
  })}">
214
- <ul class="${classMap({
227
+ <ul @click="${this.handleClick}" class="${classMap({
215
228
  'navbar': true,
216
229
  'navbar--slim': this.slim,
217
230
  'navbar--border': this.border,
@@ -232,7 +245,11 @@ export default class ZnNavbar extends ZincElement {
232
245
  <li class="${classMap({'active': item.active})}" tab-uri="${item.path}">${content}</li>`;
233
246
  }
234
247
  return html`
235
- <li class="${classMap({'active': item.active})}" tab="${item.tab}">${content}</li>`;
248
+ <li class="${classMap({'active': item.active})}"
249
+ tab="${ifDefined(!this.isolated ? item.tab : undefined)}"
250
+ data-tab="${ifDefined(this.isolated ? item.tab : undefined)}">
251
+ ${content}
252
+ </li>`;
236
253
  })}
237
254
  <li class="more">
238
255
  <zn-dropdown placement="bottom-end" id="extended-dropdown">
@@ -10,6 +10,7 @@ import ZnNavbar from '../navbar';
10
10
  import type {PropertyValues} from 'lit';
11
11
  import type {ZincFormControl} from '../../internal/zinc-element';
12
12
  import type {ZnMenuSelectEvent} from '../../events/zn-menu-select';
13
+ import type {ZnSelectEvent} from "../../events/zn-select";
13
14
 
14
15
  import styles from './translations.scss';
15
16
 
@@ -110,7 +111,7 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
110
111
  }
111
112
  }
112
113
 
113
- private handleLanguageAdd(e: ZnMenuSelectEvent) {
114
+ private handleLanguageAdd = (e: ZnMenuSelectEvent) => {
114
115
  const element = e.detail.element as HTMLElement;
115
116
  const languageCode = element.getAttribute('data-path');
116
117
  if (languageCode) {
@@ -119,21 +120,21 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
119
120
  this._activeLanguage = languageCode;
120
121
  this.updateValue();
121
122
  }
122
- }
123
+ };
123
124
 
124
- private handleNavbarClick(e: MouseEvent) {
125
- const path = e.composedPath();
126
- const li = path.find(el => el instanceof HTMLElement && el.tagName === 'LI' && el.hasAttribute('tab')) as HTMLElement;
125
+ private handleNavbarClick = (e: ZnSelectEvent) => {
126
+ e.stopPropagation();
127
+ const li = e.detail.item as HTMLElement;
127
128
  if (li) {
128
- const tab = li.getAttribute('tab');
129
+ const tab = li.getAttribute('tab') || li.getAttribute('data-tab');
129
130
  if (tab) {
130
131
  this._activeLanguage = tab;
131
132
  this.requestUpdate();
132
133
  }
133
134
  }
134
- }
135
+ };
135
136
 
136
- private handleValueUpdate(e: CustomEvent) {
137
+ private handleValueUpdate = (e: CustomEvent) => {
137
138
  const target = e.target as (ZnInput | ZnInlineEdit);
138
139
  if (this._activeLanguage) {
139
140
  const newValue: string = target.value as string;
@@ -142,7 +143,7 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
142
143
  this.updateValue();
143
144
  }
144
145
  }
145
- }
146
+ };
146
147
 
147
148
  private updateValue() {
148
149
  this.value = JSON.stringify(this.values);
@@ -150,6 +151,24 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
150
151
  this.emit('zn-input');
151
152
  }
152
153
 
154
+ private handleKeyDown = (event: KeyboardEvent) => {
155
+ if (event.key === 'Enter') {
156
+ if (event.target instanceof ZnInlineEdit) {
157
+ return;
158
+ }
159
+
160
+ const hasModifier = event.altKey || event.ctrlKey || event.metaKey || event.shiftKey;
161
+
162
+ if (!hasModifier && !event.defaultPrevented && !event.isComposing) {
163
+ this.formControlController.submit();
164
+ }
165
+ }
166
+ };
167
+
168
+ private handleSubmit = () => {
169
+ this.formControlController.submit();
170
+ };
171
+
153
172
  render() {
154
173
  const availableLanguages = Object.entries(this.languages)
155
174
  .filter(([code]) => !Object.prototype.hasOwnProperty.call(this.values, code))
@@ -178,7 +197,8 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
178
197
  'form-control': true,
179
198
  'form-control--medium': true,
180
199
  'form-control--has-label': hasLabel,
181
- })}">
200
+ })}"
201
+ @keydown="${this.handleKeyDown}">
182
202
  <label part="form-control-label" class="form-control__label" for="input"
183
203
  aria-hidden=${hasLabel ? 'false' : 'true'}>
184
204
  <slot name="label">${this.label}</slot>
@@ -187,7 +207,9 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
187
207
  <zn-navbar
188
208
  .navigation="${navigation}"
189
209
  .dropdown="${availableLanguages}"
190
- @click="${this.handleNavbarClick}"
210
+ name="${this.name}-translations-navbar"
211
+ isolated
212
+ @zn-select="${this.handleNavbarClick}"
191
213
  @zn-menu-select="${this.handleLanguageAdd}"
192
214
  manual-add-items
193
215
  ></zn-navbar>
@@ -196,12 +218,15 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
196
218
  ${useInlineEdit ? html`
197
219
  <zn-inline-edit
198
220
  .value=${currentTranslation}
221
+ name="${this.name}"
199
222
  @zn-change="${this.handleValueUpdate}"
200
223
  @zn-input="${this.handleValueUpdate}"
224
+ @zn-submit="${this.handleSubmit}"
201
225
  ></zn-inline-edit>
202
226
  ` : html`
203
227
  <zn-input
204
228
  .value="${currentTranslation || ''}"
229
+ name="${this.name}"
205
230
  placeholder="Enter translation..."
206
231
  @zn-change="${this.handleValueUpdate}"
207
232
  ></zn-input>
@@ -1,6 +1,6 @@
1
1
  import type ZnMenuItem from "../components/menu-item";
2
2
 
3
- export type ZnSelectEvent = CustomEvent<{ item: ZnMenuItem }>;
3
+ export type ZnSelectEvent = CustomEvent<{ item: ZnMenuItem | HTMLElement }>;
4
4
 
5
5
  declare global {
6
6
  interface GlobalEventHandlersEventMap {