sas-ui 0.8.281 → 0.8.283

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 (35) hide show
  1. package/dist/cjs/loader.cjs.js +1 -1
  2. package/dist/cjs/sas-avatar.cjs.entry.js +1 -1
  3. package/dist/cjs/{sas-button_19.cjs.entry.js → sas-button_13.cjs.entry.js} +373 -3837
  4. package/dist/cjs/sas-form-input-template_4.cjs.entry.js +2286 -0
  5. package/dist/cjs/sas-select.cjs.entry.js +606 -0
  6. package/dist/cjs/sas-ui.cjs.js +1 -1
  7. package/dist/collection/collection-manifest.json +0 -1
  8. package/dist/collection/components/sas-avatar/sas-avatar.css +4 -2
  9. package/dist/custom-elements/index.d.ts +0 -6
  10. package/dist/custom-elements/index.js +2 -591
  11. package/dist/esm/loader.js +1 -1
  12. package/dist/esm/sas-avatar.entry.js +1 -1
  13. package/dist/esm/{sas-button_19.entry.js → sas-button_13.entry.js} +374 -3832
  14. package/dist/esm/sas-form-input-template_4.entry.js +2279 -0
  15. package/dist/esm/sas-select.entry.js +602 -0
  16. package/dist/esm/sas-ui.js +1 -1
  17. package/dist/sas-ui/p-6adeec3b.entry.js +1 -0
  18. package/dist/sas-ui/p-8fd52963.entry.js +1 -0
  19. package/dist/sas-ui/p-d0a00973.entry.js +1 -0
  20. package/dist/sas-ui/p-fc9e5304.entry.js +1 -0
  21. package/dist/sas-ui/sas-ui.esm.js +1 -1
  22. package/dist/types/components.d.ts +0 -174
  23. package/package.json +1 -1
  24. package/dist/collection/components/sas-timezone-select/sas-timezone-select.css +0 -3
  25. package/dist/collection/components/sas-timezone-select/sas-timezone-select.js +0 -653
  26. package/dist/collection/components/sas-timezone-select/sas-timezone-select.stories.js +0 -115
  27. package/dist/collection/components/sas-timezone-select/timezones/timezone-data.js +0 -259
  28. package/dist/collection/components/sas-timezone-select/timezones/timezone-format.js +0 -104
  29. package/dist/collection/components/sas-timezone-select/type.js +0 -9
  30. package/dist/sas-ui/p-04b19ab3.entry.js +0 -1
  31. package/dist/sas-ui/p-45bf5b72.entry.js +0 -1
  32. package/dist/types/components/sas-timezone-select/sas-timezone-select.d.ts +0 -120
  33. package/dist/types/components/sas-timezone-select/timezones/timezone-data.d.ts +0 -60
  34. package/dist/types/components/sas-timezone-select/timezones/timezone-format.d.ts +0 -30
  35. package/dist/types/components/sas-timezone-select/type.d.ts +0 -85
@@ -0,0 +1,606 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const index = require('./index-cd75521b.js');
6
+ const global = require('./global-fcd219ac.js');
7
+
8
+ const sasSelectCss = ":host{display:block}:host sas-form-input-template{flex-shrink:var(--select-flex-shrink);margin-right:var(--select-margin-right, 0);--input-height:var(--select-height, 40px);--sublist-title-padding:0 10px;--list-item-padding:12px 10px;--list-item-default-color:var(--s-500);--form-input-template-container-max-width:var(--select-option-max-width, 300px)}:host sas-list{max-height:200px;overflow-y:auto}:host #no-match-tip{pointer-events:none}:host .hide{display:none}";
9
+
10
+ let SasSelect = class {
11
+ constructor(hostRef) {
12
+ index.registerInstance(this, hostRef);
13
+ this.selectUpdate = index.createEvent(this, "selectUpdate", 7);
14
+ this.selectupdate = index.createEvent(this, "selectupdate", 7);
15
+ this.selectUpdateEventUsedInternal = index.createEvent(this, "selectUpdateEventUsedInternal", 7);
16
+ this.inputText = '';
17
+ this.error = false;
18
+ this.decodeOptions = [];
19
+ this.defaultPlaceholder = '';
20
+ /**
21
+ * Label
22
+ */
23
+ this.label = '';
24
+ /**
25
+ * Shows an icon next to the label - mainly for help icons
26
+ */
27
+ this.iconLabel = '';
28
+ /**
29
+ * Label position
30
+ */
31
+ this.outside = false;
32
+ /**
33
+ * Shows a star symbol behind label
34
+ */
35
+ this.required = false;
36
+ /**
37
+ * Search
38
+ */
39
+ this.type = 'default';
40
+ /**
41
+ * No match tip
42
+ */
43
+ this.noMatchTip = 'No data available';
44
+ /**
45
+ * Placeholder
46
+ */
47
+ this.placeholder = 'Please select';
48
+ /**
49
+ * disabled
50
+ */
51
+ this.disabled = false;
52
+ /**
53
+ * Clear
54
+ */
55
+ this.clear = false;
56
+ /**
57
+ * Options
58
+ */
59
+ this.options = [];
60
+ /**
61
+ * alwaysShownOptions (flags that the option should be always shown on the dropdown after a search instead of the default noMatchTip)
62
+ */
63
+ this.alwaysShownOptions = [];
64
+ /**
65
+ * default value, used for the case options might be updated
66
+ */
67
+ this.defaultValue = null;
68
+ /**
69
+ * name
70
+ */
71
+ this.name = '';
72
+ /**
73
+ * Selected value
74
+ */
75
+ this.value = null;
76
+ /**
77
+ * Complete selected data
78
+ */
79
+ this.rawData = null;
80
+ /**
81
+ * Selected text
82
+ */
83
+ this.text = null;
84
+ /**
85
+ * If options have subtext, set options subtext position
86
+ */
87
+ this.subtextPosition = 'bottom';
88
+ /**
89
+ * Default container position
90
+ */
91
+ this.position = null;
92
+ /**
93
+ * Validity
94
+ */
95
+ this.validity = {
96
+ valid: true,
97
+ valueMissing: false,
98
+ };
99
+ /**
100
+ * Only shows when input is invalid, auto generated
101
+ */
102
+ this.message = '';
103
+ this.createElement = () => {
104
+ const hasShadowDom = this.checkShadowDom();
105
+ if (hasShadowDom) {
106
+ const obj = {
107
+ value: this.inputText,
108
+ text: this.inputText,
109
+ };
110
+ this.options = [...this.options, obj];
111
+ }
112
+ else {
113
+ const element = document.createElement('SAS-LIST-ITEM');
114
+ element.value = this.inputText;
115
+ element.text = this.inputText;
116
+ const list = this.el.querySelector('sas-list');
117
+ list.append(element);
118
+ }
119
+ this.value = this.inputText;
120
+ this.update();
121
+ };
122
+ }
123
+ watchValueHandler() {
124
+ const listItems = this.getListItemElements();
125
+ // not validate when no options and list items, as in this case, options are not loaded
126
+ if (this.decodeOptions.length !== 0 || listItems.length !== 0) {
127
+ const isValid = this.validateValue();
128
+ if (!isValid) {
129
+ this.value = this.defaultValue;
130
+ }
131
+ }
132
+ const hasShadowDom = this.checkShadowDom();
133
+ if (!hasShadowDom) {
134
+ // update select status in light dom
135
+ this.updateSelectStatus();
136
+ }
137
+ this.text = this.getText();
138
+ this.rawData = this.updateRawData();
139
+ // in type search, placeholder will be updated
140
+ // so need to reset when no value
141
+ if (this.value === null) {
142
+ this.placeholder = this.defaultPlaceholder;
143
+ }
144
+ // this.validity = this.getValidity();
145
+ this.resetErrorStatus();
146
+ const obj = {
147
+ value: this.value,
148
+ text: this.text,
149
+ };
150
+ this.selectUpdateEventUsedInternal.emit(obj);
151
+ }
152
+ watchOptionsHandler() {
153
+ this.decodeOptions = this.getDecodeOptions();
154
+ if (this.decodeOptions.length > 0) {
155
+ const isValid = this.validateValue();
156
+ if (!isValid) {
157
+ this.value = this.defaultValue;
158
+ }
159
+ }
160
+ else {
161
+ this.value = null;
162
+ }
163
+ // in type search, placeholder will be updated
164
+ // so need to reset when no value
165
+ if (this.value === null) {
166
+ this.placeholder = this.defaultPlaceholder;
167
+ }
168
+ this.text = this.getText();
169
+ }
170
+ componentWillLoad() {
171
+ const hasShadowDom = this.checkShadowDom();
172
+ if (!hasShadowDom) {
173
+ const listElement = this.el.querySelector('sas-list');
174
+ if (listElement !== null) {
175
+ listElement.style.maxHeight = '200px';
176
+ listElement.style.overflowY = 'auto';
177
+ listElement.subtextPosition = this.subtextPosition;
178
+ // prevents dropdown container from closing when user clicks/holds
179
+ // scroll bar with cursor
180
+ listElement.addEventListener("mousedown", function (event) {
181
+ if (event.target.tagName === "SAS-LIST") {
182
+ event.preventDefault();
183
+ }
184
+ });
185
+ }
186
+ // has pre select element
187
+ const selectedElement = this.getSelectedElement();
188
+ if (selectedElement) {
189
+ this.value = selectedElement.value;
190
+ this.text = selectedElement.text;
191
+ this.rawData = this.updateRawData();
192
+ }
193
+ }
194
+ else {
195
+ this.decodeOptions = this.getDecodeOptions();
196
+ // has pre select value
197
+ if (this.value !== null) {
198
+ const isValid = this.validateValue();
199
+ if (!isValid) {
200
+ this.value = this.defaultValue;
201
+ }
202
+ this.text = this.getText();
203
+ this.rawData = this.updateRawData();
204
+ }
205
+ }
206
+ this.defaultPlaceholder = this.placeholder;
207
+ // this.validity = this.getValidity();
208
+ // this.resetErrorStatus();
209
+ }
210
+ listItemClickedHandler(event) {
211
+ if (this.value !== event.detail.value
212
+ && event.detail.value !== 'createElementListItemOnlyUsedInternal') {
213
+ // update value
214
+ this.value = event.detail.value;
215
+ // update text
216
+ this.text = event.detail.text;
217
+ // update raw data
218
+ this.rawData = this.updateRawData();
219
+ // emit event
220
+ this.selectUpdate.emit(event.detail);
221
+ this.selectupdate.emit(event.detail);
222
+ }
223
+ // hide list
224
+ const inputTemplate = this.el.shadowRoot.querySelector('sas-form-input-template');
225
+ inputTemplate.show = false;
226
+ }
227
+ listItemClickEventUsedInternalHandler(event) {
228
+ event.stopPropagation();
229
+ }
230
+ inputUpdateHandler(event) {
231
+ this.inputText = event.detail;
232
+ this.filter(this.inputText);
233
+ const formInputTemplate = this.el.shadowRoot.querySelector('sas-form-input-template');
234
+ formInputTemplate.show = true;
235
+ }
236
+ inputClearHandler() {
237
+ this.value = null;
238
+ this.update();
239
+ }
240
+ inputFocusHandler() {
241
+ if (this.type !== 'default') {
242
+ this.inputText = '';
243
+ this.filter(this.inputText);
244
+ if (this.text) {
245
+ this.placeholder = this.text;
246
+ this.text = '';
247
+ }
248
+ }
249
+ }
250
+ inputBlurHandler() {
251
+ if (this.type !== 'default') {
252
+ // triggered by click outside or click list item
253
+ // if click outside, only need reset text
254
+ // if click list item, as inputBlur event is faster than listUpdate event
255
+ // so text will be reset to placeholder, and then set to clicked list item text
256
+ if (this.value === null) {
257
+ this.text = '';
258
+ }
259
+ else {
260
+ this.text = this.placeholder;
261
+ }
262
+ }
263
+ }
264
+ inputContainerClickHandler() {
265
+ const selectedElement = this.getSelectedElement();
266
+ if (selectedElement) {
267
+ selectedElement.parentElement.scrollTop = selectedElement.offsetTop;
268
+ }
269
+ }
270
+ /**
271
+ * Trigger selectupdate event programmatically
272
+ */
273
+ async update() {
274
+ const value = this.value;
275
+ const text = this.text;
276
+ const eventObj = {
277
+ value: value,
278
+ text: text,
279
+ };
280
+ this.selectUpdate.emit(eventObj);
281
+ this.selectupdate.emit(eventObj);
282
+ }
283
+ /**
284
+ * Validate
285
+ */
286
+ async validate() {
287
+ let valueMissing = false;
288
+ if (this.required && this.value === null) {
289
+ valueMissing = true;
290
+ }
291
+ this.validity = {
292
+ valid: !valueMissing,
293
+ valueMissing: valueMissing,
294
+ };
295
+ }
296
+ /**
297
+ * Show error status if value is not valid (only for components internal use)
298
+ */
299
+ async updateErrorStatus() {
300
+ await this.validate();
301
+ const formInputTemplate = this.el.shadowRoot.querySelector('sas-form-input-template');
302
+ if (formInputTemplate !== null) {
303
+ formInputTemplate.error = !this.validity.valid;
304
+ }
305
+ if (!this.validity.valid) {
306
+ this.message = this.getErrorMessage();
307
+ }
308
+ }
309
+ /**
310
+ * Clear error status (only for components internal use)
311
+ */
312
+ async resetErrorStatus() {
313
+ const formInputTemplate = this.el.shadowRoot.querySelector('sas-form-input-template');
314
+ if (formInputTemplate !== null) {
315
+ formInputTemplate.error = false;
316
+ }
317
+ this.message = '';
318
+ }
319
+ getDecodeOptions() {
320
+ const decodeOptions = this.options.concat(this.alwaysShownOptions).map(option => {
321
+ if ('sub' in option) {
322
+ const decodeSubOptions = option.sub.map((subOption) => {
323
+ return Object.assign(Object.assign({}, subOption), { text: global.HTMLDecodeString(subOption.text), subtext: global.HTMLDecodeString(subOption.subtext) });
324
+ });
325
+ return Object.assign(Object.assign({}, option), { text: global.HTMLDecodeString(option.text), subtext: global.HTMLDecodeString(option.subtext), sub: decodeSubOptions });
326
+ }
327
+ else {
328
+ return Object.assign(Object.assign({}, option), { text: global.HTMLDecodeString(option.text), subtext: global.HTMLDecodeString(option.subtext) });
329
+ }
330
+ });
331
+ return decodeOptions;
332
+ }
333
+ validateValue() {
334
+ const hasShadowDom = this.checkShadowDom();
335
+ let isFound = false;
336
+ if (hasShadowDom) {
337
+ this.decodeOptions.forEach((option) => {
338
+ if ('sub' in option) {
339
+ option.sub.forEach((sub) => {
340
+ if (sub.value === this.value) {
341
+ isFound = true;
342
+ }
343
+ });
344
+ }
345
+ else {
346
+ if (option.value === this.value) {
347
+ isFound = true;
348
+ }
349
+ }
350
+ });
351
+ }
352
+ else {
353
+ const listItems = this.getListItemElements();
354
+ listItems.forEach((listItem) => {
355
+ if (listItem.value === this.value) {
356
+ isFound = true;
357
+ }
358
+ });
359
+ }
360
+ return isFound;
361
+ }
362
+ getErrorMessage() {
363
+ const validity = this.validity;
364
+ if (validity.valueMissing) {
365
+ const prefix = Boolean(this.label) ? this.label : 'Field';
366
+ return `${prefix} is required`;
367
+ }
368
+ }
369
+ checkShadowDom() {
370
+ if (this.options.length > 0) {
371
+ return true;
372
+ }
373
+ else {
374
+ return false;
375
+ }
376
+ }
377
+ getListElement() {
378
+ const hasShadowDom = this.checkShadowDom();
379
+ if (hasShadowDom) {
380
+ return this.el.shadowRoot.querySelector('sas-list');
381
+ }
382
+ else {
383
+ return this.el.querySelector('sas-list');
384
+ }
385
+ }
386
+ updateSelectStatus() {
387
+ const listItems = this.getListItemElements();
388
+ listItems.forEach((listItem) => {
389
+ if (listItem.value === this.value) {
390
+ listItem.selected = true;
391
+ }
392
+ else {
393
+ listItem.selected = false;
394
+ }
395
+ });
396
+ }
397
+ updateRawData() {
398
+ const value = this.value;
399
+ const text = this.getText();
400
+ let rawData = null;
401
+ const hasShadowDom = this.checkShadowDom();
402
+ if (hasShadowDom) {
403
+ this.decodeOptions.forEach((option) => {
404
+ if ('sub' in option) {
405
+ option.sub.forEach((sub) => {
406
+ if (this.value === sub.value) {
407
+ rawData = {
408
+ value: option.value,
409
+ text: option.text,
410
+ sub: {
411
+ value: value,
412
+ text: text,
413
+ },
414
+ };
415
+ }
416
+ });
417
+ }
418
+ else {
419
+ if (this.value === option.value) {
420
+ rawData = {
421
+ value: value,
422
+ text: text,
423
+ };
424
+ }
425
+ }
426
+ });
427
+ }
428
+ else {
429
+ const selectedElement = this.getSelectedElement();
430
+ if (selectedElement) {
431
+ const parentNode = selectedElement.parentNode;
432
+ if (parentNode.nodeName === 'SAS-SUBLIST') {
433
+ rawData = {
434
+ value: parentNode.value,
435
+ text: parentNode.text,
436
+ sub: {
437
+ value: value,
438
+ text: text,
439
+ },
440
+ };
441
+ }
442
+ else {
443
+ rawData = {
444
+ value: value,
445
+ text: text,
446
+ };
447
+ }
448
+ }
449
+ }
450
+ return rawData;
451
+ }
452
+ getText() {
453
+ const hasShadowDom = this.checkShadowDom();
454
+ if (this.value === null) {
455
+ return null;
456
+ }
457
+ else {
458
+ if (hasShadowDom) {
459
+ let result;
460
+ this.decodeOptions.forEach((option) => {
461
+ if ('sub' in option) {
462
+ option.sub.forEach((sub) => {
463
+ if (this.value === sub.value) {
464
+ result = sub;
465
+ }
466
+ });
467
+ }
468
+ else {
469
+ if (this.value === option.value) {
470
+ result = option;
471
+ }
472
+ }
473
+ });
474
+ return result.text;
475
+ }
476
+ else {
477
+ const selectedElement = this.getSelectedElement();
478
+ return selectedElement.text;
479
+ }
480
+ }
481
+ }
482
+ getSelectedElement() {
483
+ const listItems = this.getListItemElements();
484
+ let selectedElement = null;
485
+ listItems.forEach((listItem) => {
486
+ if (listItem.value === this.value || listItem.selected) {
487
+ selectedElement = listItem;
488
+ }
489
+ });
490
+ return selectedElement;
491
+ }
492
+ getListItemElements() {
493
+ const hasShadowDom = this.checkShadowDom();
494
+ if (hasShadowDom) {
495
+ const list = this.el.shadowRoot.querySelector('sas-form-input-template').querySelector('sas-list');
496
+ if (list !== null) {
497
+ return list.shadowRoot.querySelectorAll('sas-list-item');
498
+ }
499
+ else {
500
+ return [];
501
+ }
502
+ }
503
+ else {
504
+ return this.el.querySelectorAll('sas-list-item');
505
+ }
506
+ }
507
+ filter(text) {
508
+ let listItems;
509
+ let sublists;
510
+ let count = 0;
511
+ const hasShadowDom = this.checkShadowDom();
512
+ if (hasShadowDom) {
513
+ const listElement = this.getListElement();
514
+ if (listElement !== null) {
515
+ listItems = listElement.shadowRoot.querySelectorAll('sas-list-item');
516
+ sublists = listElement.shadowRoot.querySelectorAll('sas-sublist');
517
+ }
518
+ else {
519
+ listItems = [];
520
+ sublists = [];
521
+ }
522
+ }
523
+ else {
524
+ listItems = this.el.querySelectorAll('sas-list-item');
525
+ sublists = this.el.querySelectorAll('sas-sublist');
526
+ }
527
+ listItems.forEach((listItem) => {
528
+ let textLowerCase;
529
+ if (text) {
530
+ textLowerCase = text.toLowerCase();
531
+ }
532
+ else {
533
+ textLowerCase = '';
534
+ }
535
+ const listItemTextLowserCase = listItem.text.toLowerCase();
536
+ let isMatch = false;
537
+ if (listItemTextLowserCase) {
538
+ isMatch = listItemTextLowserCase.includes(textLowerCase);
539
+ }
540
+ if (isMatch || listItem.alwaysShown) {
541
+ console.log('listItem.alwaysShown: ' + listItem.alwaysShown);
542
+ count += 1;
543
+ if (hasShadowDom) {
544
+ listItem.classList.remove('hide');
545
+ }
546
+ else {
547
+ listItem.classList.remove('d-none');
548
+ }
549
+ }
550
+ else {
551
+ if (hasShadowDom) {
552
+ listItem.classList.add('hide');
553
+ }
554
+ else {
555
+ listItem.classList.add('d-none');
556
+ }
557
+ }
558
+ if (this.type === 'search' || this.type === 'create') {
559
+ const tip = this.el.shadowRoot.querySelector('.tip');
560
+ if (count !== 0) {
561
+ tip.classList.add('hide');
562
+ }
563
+ else {
564
+ if (this.type === 'create') {
565
+ tip.text = `Create "${text}"`;
566
+ }
567
+ tip.classList.remove('hide');
568
+ }
569
+ }
570
+ });
571
+ // hide sub list if need
572
+ sublists.forEach(sublist => {
573
+ const children = sublist.querySelectorAll('sas-list-item');
574
+ let isAllHide = true;
575
+ for (let i = 0; i < children.length; i++) {
576
+ if (!children[i].classList.contains('hide') && !children[i].classList.contains('d-none')) {
577
+ isAllHide = false;
578
+ break;
579
+ }
580
+ }
581
+ if (isAllHide) {
582
+ sublist.classList.add('d-none');
583
+ }
584
+ else {
585
+ sublist.classList.remove('d-none');
586
+ }
587
+ });
588
+ }
589
+ render() {
590
+ return (index.h(index.Host, { tabindex: "0" }, index.h("sas-form-input-template", { label: this.label, outside: this.outside, required: this.required, placeholder: this.placeholder, "icon-right": "far fa-chevron-down", value: this.text, readonly: this.type === 'default', disabled: this.disabled, clear: this.clear, error: this.error, "data-message": this.message, position: this.position, iconLabel: this.iconLabel, minimumPixelsAboveComponentRequired: 230 }, this.decodeOptions.length > 0
591
+ ? index.h("sas-list", { slot: "container", options: this.decodeOptions, value: this.value, defaultValue: this.defaultValue, subtextPosition: this.subtextPosition })
592
+ : index.h("slot", { slot: "container" }), this.type === 'search'
593
+ ? index.h("sas-list-item", { slot: "container", class: "tip hide", id: "no-match-tip", text: this.noMatchTip })
594
+ : null, this.type === 'create'
595
+ ? index.h("sas-list-item", { slot: "container", class: "tip hide", value: "createElementListItemOnlyUsedInternal", onClick: this.createElement })
596
+ : null)));
597
+ }
598
+ get el() { return index.getElement(this); }
599
+ static get watchers() { return {
600
+ "value": ["watchValueHandler"],
601
+ "options": ["watchOptionsHandler"]
602
+ }; }
603
+ };
604
+ SasSelect.style = sasSelectCss;
605
+
606
+ exports.sas_select = SasSelect;