@kubex/zinc 1.0.107 → 1.0.109

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.
@@ -37,6 +37,7 @@ export default class ZnTabs extends ZincElement {
37
37
  @property({attribute: 'primary-caption', reflect: true}) primaryCaption = 'Navigation';
38
38
  @property({attribute: 'secondary-caption', reflect: true}) secondaryCaption = 'Content';
39
39
  @property({attribute: 'no-prefetch', type: Boolean, reflect: true}) noPrefetch = false;
40
+ @property({attribute: 'no-cache', type: Boolean, reflect: true}) noCache = false;
40
41
  // session storage if not local
41
42
  @property({attribute: 'local-storage', type: Boolean, reflect: true}) localStorage: boolean;
42
43
  @property({attribute: 'store-key'}) storeKey: string;
@@ -72,7 +73,7 @@ export default class ZnTabs extends ZincElement {
72
73
  this.masterId = this.storeKey || Math.floor(Math.random() * 1000000).toString();
73
74
  }
74
75
 
75
- this.preload = !this.noPrefetch;
76
+ this.preload = !this.noPrefetch && !this.noCache;
76
77
 
77
78
  await this.updateComplete;
78
79
  this._panel = this.shadowRoot?.querySelector('#content');
@@ -272,11 +273,14 @@ export default class ZnTabs extends ZincElement {
272
273
  }
273
274
 
274
275
  clickTab(target: HTMLElement, refresh: boolean) {
276
+ const tabUri = target.getAttribute('tab-uri');
277
+ const wasCached = !!tabUri && this._panels.has(this._uriToId(tabUri));
275
278
  this.fetchUriTab(target);
276
279
 
277
280
  if (target.hasAttribute('tab')) {
281
+ const forceRefresh = refresh || (this.noCache && wasCached);
278
282
  setTimeout(() => {
279
- this.setActiveTab(target.getAttribute('tab') || '', true, refresh, this.getRefTab(target));
283
+ this.setActiveTab(target.getAttribute('tab') || '', true, forceRefresh, this.getRefTab(target));
280
284
  }, 10);
281
285
  }
282
286
  }
@@ -233,6 +233,13 @@ export default class ZnTextarea extends ZincElement implements ZincFormControl {
233
233
  this.formControlController.emitInvalidEvent(event);
234
234
  }
235
235
 
236
+ private handleKeyDown(event: KeyboardEvent) {
237
+ if (event.key === 'Escape') {
238
+ this.input.blur();
239
+ event.stopPropagation();
240
+ }
241
+ }
242
+
236
243
  private setTextareaHeight() {
237
244
  if (this.resize === 'auto') {
238
245
  this.input.style.height = 'auto';
@@ -436,6 +443,7 @@ export default class ZnTextarea extends ZincElement implements ZincFormControl {
436
443
  @change=${this.handleChange}
437
444
  @input=${this.handleInput}
438
445
  @invalid=${this.handleInvalid}
446
+ @keydown=${this.handleKeyDown}
439
447
  @focus=${this.handleFocus}
440
448
  @blur=${this.handleBlur}
441
449
  ></textarea>
@@ -1,10 +1,43 @@
1
1
  import '../../../dist/zn.min.js';
2
- import { expect, fixture, html } from '@open-wc/testing';
2
+ import {expect, fixture, html} from '@open-wc/testing';
3
+ import type ZnTextarea from './textarea.component';
3
4
 
4
- describe('<zn-text-area>', () => {
5
+ describe('<zn-textarea>', () => {
5
6
  it('should render a component', async () => {
6
- const el = await fixture(html` <zn-text-area></zn-text-area> `);
7
+ const el = await fixture(html` <zn-textarea></zn-textarea> `);
7
8
 
8
9
  expect(el).to.exist;
9
10
  });
11
+
12
+ describe('Escape key', () => {
13
+ it('blurs the inner textarea and stops propagation when focused', async () => {
14
+ const wrapper = await fixture<HTMLDivElement>(html`
15
+ <div>
16
+ <zn-textarea></zn-textarea>
17
+ </div>
18
+ `);
19
+ const el = wrapper.querySelector('zn-textarea') as ZnTextarea;
20
+ await el.updateComplete;
21
+
22
+ let wrapperEscapes = 0;
23
+ wrapper.addEventListener('keydown', (e) => {
24
+ if ((e as KeyboardEvent).key === 'Escape') wrapperEscapes++;
25
+ });
26
+
27
+ el.focus();
28
+ await el.updateComplete;
29
+ expect(el.shadowRoot!.activeElement).to.equal(el.input);
30
+
31
+ el.input.dispatchEvent(new KeyboardEvent('keydown', {
32
+ key: 'Escape',
33
+ bubbles: true,
34
+ composed: true,
35
+ cancelable: true
36
+ }));
37
+ await el.updateComplete;
38
+
39
+ expect(el.shadowRoot!.activeElement, 'inner textarea should be blurred').to.not.equal(el.input);
40
+ expect(wrapperEscapes, 'wrapper should not see Escape on press 1').to.equal(0);
41
+ });
42
+ });
10
43
  });
@@ -1,24 +1,28 @@
1
1
  @use "../../wc";
2
2
 
3
+ :host {
4
+ display: flex;
5
+ min-width: 0;
6
+ max-width: 240px;
7
+ }
3
8
 
4
9
  .tile__property {
5
10
  display: flex;
6
11
  align-items: center;
7
12
  flex-direction: row;
8
- width: 150px;
9
- flex-basis: 150px;
10
- max-width: 200px;
13
+ min-width: 0;
14
+ width: 100%;
11
15
 
12
16
  .tile__property_container {
13
17
  display: flex;
14
18
  flex-direction: column;
15
19
  overflow: hidden;
16
- white-space: nowrap;
17
- text-overflow: ellipsis;
20
+ min-width: 0;
18
21
  }
19
22
 
20
23
  .tile__icon {
21
24
  margin-right: 15px;
25
+ flex-shrink: 0;
22
26
  }
23
27
 
24
28
  .tile__caption {
@@ -29,6 +33,7 @@
29
33
  color: rgb(var(--zn-text-heading));
30
34
  text-overflow: ellipsis;
31
35
  overflow: hidden;
36
+ white-space: nowrap;
32
37
  }
33
38
 
34
39
  .tile__description {
@@ -39,5 +44,6 @@
39
44
  color: rgb(var(--zn-text-color));
40
45
  text-overflow: ellipsis;
41
46
  overflow: hidden;
47
+ white-space: nowrap;
42
48
  }
43
49
  }
@@ -0,0 +1,114 @@
1
+ /* eslint-disable */
2
+ export function sha256(input: string): string {
3
+ function rightRotate(value: number, amount: number) {
4
+ return (value >>> amount) | (value << (32 - amount));
5
+ }
6
+
7
+ function utf8Encode(string: string) {
8
+ string = string.replace(/\r\n/g, '\n');
9
+ let utfText = '';
10
+
11
+ for (let index = 0; index < string.length; index++) {
12
+ const charCode = string.charCodeAt(index);
13
+
14
+ if (charCode < 128) {
15
+ utfText += String.fromCharCode(charCode);
16
+ } else if (charCode < 2048) {
17
+ utfText += String.fromCharCode((charCode >> 6) | 192);
18
+ utfText += String.fromCharCode((charCode & 63) | 128);
19
+ } else {
20
+ utfText += String.fromCharCode((charCode >> 12) | 224);
21
+ utfText += String.fromCharCode(((charCode >> 6) & 63) | 128);
22
+ utfText += String.fromCharCode((charCode & 63) | 128);
23
+ }
24
+ }
25
+
26
+ return utfText;
27
+ }
28
+
29
+ const mathPow = Math.pow;
30
+ const maxWord = mathPow(2, 32);
31
+ const words: number[] = [];
32
+ const hash: number[] = [];
33
+ const roundConstants: number[] = [];
34
+ const isComposite: Record<number, boolean> = {};
35
+ let primeCounter = 0;
36
+ let message = utf8Encode(input);
37
+ const messageBitLength = message.length * 8;
38
+
39
+ for (let candidate = 2; primeCounter < 64; candidate++) {
40
+ if (!isComposite[candidate]) {
41
+ for (let index = 0; index < 313; index += candidate) {
42
+ isComposite[index] = true;
43
+ }
44
+
45
+ if (primeCounter < 8) {
46
+ hash[primeCounter] = (mathPow(candidate, 0.5) * maxWord) | 0;
47
+ }
48
+
49
+ roundConstants[primeCounter] = (mathPow(candidate, 1 / 3) * maxWord) | 0;
50
+ primeCounter++;
51
+ }
52
+ }
53
+
54
+ message += '\x80';
55
+
56
+ while (message.length % 64 !== 56) {
57
+ message += '\x00';
58
+ }
59
+
60
+ for (let index = 0; index < message.length; index++) {
61
+ words[index >> 2] |= message.charCodeAt(index) << ((3 - (index % 4)) * 8);
62
+ }
63
+
64
+ words[words.length] = (messageBitLength / maxWord) | 0;
65
+ words[words.length] = messageBitLength;
66
+
67
+ for (let chunkStart = 0; chunkStart < words.length; chunkStart += 16) {
68
+ const workingHash = hash.slice(0, 8);
69
+ const schedule = words.slice(chunkStart, chunkStart + 16);
70
+
71
+ for (let round = 16; round < 64; round++) {
72
+ const word15 = schedule[round - 15];
73
+ const word2 = schedule[round - 2];
74
+ const sigma0 = rightRotate(word15, 7) ^ rightRotate(word15, 18) ^ (word15 >>> 3);
75
+ const sigma1 = rightRotate(word2, 17) ^ rightRotate(word2, 19) ^ (word2 >>> 10);
76
+
77
+ schedule[round] = (schedule[round - 16] + sigma0 + schedule[round - 7] + sigma1) | 0;
78
+ }
79
+
80
+ for (let round = 0; round < 64; round++) {
81
+ const a = workingHash[0];
82
+ const b = workingHash[1];
83
+ const c = workingHash[2];
84
+ const d = workingHash[3];
85
+ const e = workingHash[4];
86
+ const f = workingHash[5];
87
+ const g = workingHash[6];
88
+ const h = workingHash[7];
89
+ const sigma1 = rightRotate(e, 6) ^ rightRotate(e, 11) ^ rightRotate(e, 25);
90
+ const choose = (e & f) ^ (~e & g);
91
+ const temp1 = (h + sigma1 + choose + roundConstants[round] + schedule[round]) | 0;
92
+ const sigma0 = rightRotate(a, 2) ^ rightRotate(a, 13) ^ rightRotate(a, 22);
93
+ const majority = (a & b) ^ (a & c) ^ (b & c);
94
+ const temp2 = (sigma0 + majority) | 0;
95
+
96
+ workingHash[7] = g;
97
+ workingHash[6] = f;
98
+ workingHash[5] = e;
99
+ workingHash[4] = (d + temp1) | 0;
100
+ workingHash[3] = c;
101
+ workingHash[2] = b;
102
+ workingHash[1] = a;
103
+ workingHash[0] = (temp1 + temp2) | 0;
104
+ }
105
+
106
+ for (let index = 0; index < 8; index++) {
107
+ hash[index] = (hash[index] + workingHash[index]) | 0;
108
+ }
109
+ }
110
+
111
+ return hash
112
+ .map(value => (value >>> 0).toString(16).padStart(8, '0'))
113
+ .join('');
114
+ }