@kubex/zinc 1.0.21 → 1.0.23

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.21",
3
+ "version": "1.0.23",
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,7 +1,7 @@
1
1
  import {classMap} from 'lit/directives/class-map.js';
2
2
  import {FormControlController, validValidityState} from '../../internal/form';
3
3
  import {HasSlotController} from '../../internal/slot';
4
- import {html, unsafeCSS} from 'lit';
4
+ import {html, nothing, unsafeCSS} from 'lit';
5
5
  import {property, state} from 'lit/decorators.js';
6
6
  import ZincElement from '../../internal/zinc-element';
7
7
  import ZnInlineEdit from '../inline-edit';
@@ -30,13 +30,14 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
30
30
  @property() label: string = '';
31
31
  @property({type: Boolean, reflect: true}) disabled = false;
32
32
  @property({type: Boolean, reflect: true}) required = false;
33
+ @property({type: Boolean, reflect: true}) flush = false;
33
34
 
34
35
  @property({type: Object}) languages: Record<string, string> = {
35
36
  'en': 'English'
36
37
  };
37
38
  @property({type: Object}) values: Record<string, string> = {};
38
39
 
39
- @state() private _activeLanguage = '';
40
+ @state() private _activeLanguage = 'en';
40
41
 
41
42
  get validity(): ValidityState {
42
43
  return validValidityState;
@@ -100,12 +101,12 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
100
101
  this.value = JSON.stringify(this.values);
101
102
 
102
103
  // Ensure active language is valid
103
- if (!this._activeLanguage || !Object.prototype.hasOwnProperty.call(this.values, this._activeLanguage)) {
104
+ if (!this._activeLanguage || (!Object.prototype.hasOwnProperty.call(this.values, this._activeLanguage) && this._activeLanguage !== 'en')) {
104
105
  const keys = Object.keys(this.values);
105
106
  if (keys.length > 0) {
106
107
  this._activeLanguage = keys[0];
107
108
  } else {
108
- this._activeLanguage = '';
109
+ this._activeLanguage = 'en';
109
110
  }
110
111
  }
111
112
  }
@@ -171,21 +172,25 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
171
172
 
172
173
  render() {
173
174
  const availableLanguages = Object.entries(this.languages)
174
- .filter(([code]) => !Object.prototype.hasOwnProperty.call(this.values, code))
175
+ .filter(([code]) => code !== 'en' && !Object.prototype.hasOwnProperty.call(this.values, code))
175
176
  .map(([code, name]) => ({
176
177
  title: name,
177
178
  type: 'dropdown',
178
179
  path: code
179
180
  }));
180
181
 
181
- const navigation = Object.keys(this.values).map(code => ({
182
+ const visibleTabs = Object.keys(this.values);
183
+ if (!visibleTabs.includes('en')) {
184
+ visibleTabs.unshift('en');
185
+ }
186
+
187
+ const navigation = visibleTabs.map(code => ({
182
188
  title: this.languages[code] || code,
183
189
  active: code === this._activeLanguage,
184
190
  tab: code
185
191
  }));
186
192
 
187
193
  const currentTranslation = this.values[this._activeLanguage];
188
- const useInlineEdit = currentTranslation && currentTranslation.length > 0;
189
194
 
190
195
  const hasLabelSlot = this.hasSlotController.test('label');
191
196
  const hasLabel = this.label ? true : hasLabelSlot;
@@ -208,30 +213,21 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
208
213
  .navigation="${navigation}"
209
214
  .dropdown="${availableLanguages}"
210
215
  name="${this.name}-translations-navbar"
211
- isolated
212
216
  @zn-select="${this.handleNavbarClick}"
213
217
  @zn-menu-select="${this.handleLanguageAdd}"
218
+ flush=${this.flush || nothing}
219
+ isolated
214
220
  manual-add-items
215
221
  ></zn-navbar>
216
222
  <div class="input-container">
217
- ${this._activeLanguage ? html`
218
- ${useInlineEdit ? html`
219
- <zn-inline-edit
220
- .value=${currentTranslation}
221
- name="${this.name}"
222
- @zn-change="${this.handleValueUpdate}"
223
- @zn-input="${this.handleValueUpdate}"
224
- @zn-submit="${this.handleSubmit}"
225
- ></zn-inline-edit>
226
- ` : html`
227
- <zn-input
228
- .value="${currentTranslation || ''}"
229
- name="${this.name}"
230
- placeholder="Enter translation..."
231
- @zn-change="${this.handleValueUpdate}"
232
- ></zn-input>
233
- `}
234
- ` : ''}
223
+ <zn-inline-edit
224
+ .value=${currentTranslation}
225
+ name="${this.name}"
226
+ placeholder="Enter translation..."
227
+ @zn-change="${this.handleValueUpdate}"
228
+ @zn-input="${this.handleValueUpdate}"
229
+ @zn-submit="${this.handleSubmit}"
230
+ ></zn-inline-edit>
235
231
  </div>
236
232
  </div>
237
233
  `;
@@ -7,6 +7,7 @@
7
7
  .translations {
8
8
  display: flex;
9
9
  flex-direction: column;
10
+ padding: 0 var(--zn-spacing-medium);
10
11
  gap: var(--zn-spacing-small);
11
12
  }
12
13