@creative-web-solution/front-library 7.1.7 → 7.1.10

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/CHANGELOG.md CHANGED
@@ -1,6 +1,20 @@
1
1
  # CHANGELOG
2
2
 
3
3
 
4
+ ## 7.1.10
5
+
6
+ * SelectSkin: Change selection feature, add:
7
+ * select( param: number | string | HTMLElement )
8
+ * selectByIndex( index: number )
9
+ * selectByOption( optionOrItem: HTMLElement )
10
+ * selectByValue( value: string | number )
11
+
12
+
13
+ ## 7.1.9
14
+
15
+ * SelectSkin: Fix templating
16
+
17
+
4
18
  ## 7.1.7
5
19
 
6
20
  * Typescript: Fix some type
@@ -1,6 +1,5 @@
1
1
  import { fire, on, off } from '../Events/EventsManager';
2
2
  import { extend } from '../Helpers/Extend';
3
- import { isNumber } from '../Helpers/Type';
4
3
  import { wrap } from '../DOM/Wrap';
5
4
  import { strToDOM } from '../DOM/StrToDOM';
6
5
  import { index } from '../DOM/Index';
@@ -279,42 +278,60 @@ export default class SkinSelect implements FLib.SkinSelect.SkinSelect {
279
278
  }
280
279
 
281
280
 
282
- /**
283
- * Select an option
284
- */
285
- select( optionOrIndex: HTMLElement | number ): this {
286
- let _index, option;
287
-
281
+ selectByValue( value: string | number ): this {
288
282
  if ( this.#$select.disabled || this.#loading ) {
289
283
  return this;
290
284
  }
291
285
 
292
- const isParameterANumber = isNumber( optionOrIndex );
286
+ const IDX = Array.from( this.#$select.options ).findIndex( option => option.value === String( value ) );
293
287
 
294
- if ( isParameterANumber ) {
295
- _index = optionOrIndex;
288
+ if ( IDX < 0 ) {
289
+ return this;
296
290
  }
297
- else {
298
- _index = index( optionOrIndex as HTMLElement );
291
+
292
+ return this.selectByIndex( IDX );
293
+ }
294
+
295
+
296
+ selectByOption( optionOrItem: HTMLElement ): this {
297
+ if ( this.#$select.disabled || this.#loading ) {
298
+ return this;
299
299
  }
300
300
 
301
- if ( _index < 0 || _index > this.#$select.options.length ) {
301
+ const IDX = index( optionOrItem ) ;
302
+
303
+ if ( IDX < 0 ) {
302
304
  return this;
303
305
  }
304
306
 
305
- this.#$select.options[ _index ].selected = true;
307
+ return this.selectByIndex( IDX );
308
+ }
306
309
 
307
- if ( this.#options.full ) {
308
- option = this.#$parent.querySelectorAll( `.${ this.#options.itemClassName }` )[ _index ];
309
310
 
310
- if ( this.#$lastOption ) {
311
- this.#$lastOption.classList.remove( this.#options.activeOptionClass );
312
- }
311
+ /**
312
+ * Select an option
313
+ */
314
+ selectByIndex( index: number ): this {
313
315
 
314
- if ( option ) {
315
- option.classList.add( this.#options.activeOptionClass );
316
- this.#$lastOption = option;
317
- }
316
+ if ( this.#$select.disabled || this.#loading ) {
317
+ return this;
318
+ }
319
+
320
+ if ( index < 0 || index > this.#$select.options.length ) {
321
+ return this;
322
+ }
323
+
324
+ this.#$select.options[ index ].selected = true;
325
+
326
+ if ( this.#options.full ) {
327
+ ( this.#$parent.querySelectorAll( `.${ this.#options.itemClassName }` ) as NodeListOf<HTMLOptionElement>)
328
+ .forEach( ( $opt, optIdx ) => {
329
+ $opt.selected = optIdx === index;
330
+ $opt.classList.toggle( this.#options.activeOptionClass, $opt.selected );
331
+ if ( $opt.selected ) {
332
+ this.#$lastOption = $opt;
333
+ }
334
+ } );
318
335
  }
319
336
 
320
337
  fire( this.#$select, {
@@ -325,6 +342,23 @@ export default class SkinSelect implements FLib.SkinSelect.SkinSelect {
325
342
  }
326
343
 
327
344
 
345
+ /**
346
+ * If arg is a number, it is considered as an option index, not a value.
347
+ */
348
+ select( arg: number | string | HTMLElement ): this {
349
+ if ( typeof arg === 'number' ) {
350
+ return this.selectByIndex( arg );
351
+ }
352
+ else if ( typeof arg === 'string' ) {
353
+ return this.selectByValue( arg );
354
+ }
355
+ else if ( typeof arg === 'object' ) {
356
+ return this.selectByOption( arg );
357
+ }
358
+
359
+ return this;
360
+ }
361
+
328
362
  #setSelectOptions = ( data: FLib.SkinSelect.OptionArray[] ): void => {
329
363
  let hasSelectedOption;
330
364
 
@@ -389,14 +423,17 @@ export default class SkinSelect implements FLib.SkinSelect.SkinSelect {
389
423
 
390
424
  for ( const opt of Array.from( this.#$select.options ) ) {
391
425
  HTML_LIST.push( quickTemplate( this.#options.listTpl.item, {
392
- "onClass": opt.selected ? " on" : "",
393
- "text": opt.text,
394
- "value": opt.value
426
+ "onClass": opt.selected ? " on" : "",
427
+ "text": opt.text,
428
+ "value": opt.value,
429
+ "itemClassName": this.#options.itemClassName
395
430
  } ) );
396
431
  }
397
432
 
398
433
  this.#$parent.appendChild( strToDOM( quickTemplate( this.#options.listTpl.wrapper, {
399
- "items": HTML_LIST.join( '' )
434
+ "items": HTML_LIST.join( '' ),
435
+ "layerClassName": this.#options.layerClassName,
436
+ "listClassName": this.#options.listClassName
400
437
  } ) ) );
401
438
 
402
439
 
@@ -419,7 +456,7 @@ export default class SkinSelect implements FLib.SkinSelect.SkinSelect {
419
456
  if ( !(e.target as HTMLElement).matches( '.' + this.#options.itemClassName ) ) {
420
457
  return;
421
458
  }
422
- this.select( e.target as HTMLElement );
459
+ this.selectByOption( e.target as HTMLElement );
423
460
  }
424
461
 
425
462
 
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Front Library
2
2
 
3
- @version: 7.1.7
3
+ @version: 7.1.10
4
4
 
5
5
 
6
6
  ## Use
@@ -1,15 +1,18 @@
1
1
  declare declare namespace FLib {
2
2
  namespace SkinSelect {
3
3
  interface SkinSelect {
4
- enable(): this;
5
- disable(): this;
6
- setInvalid(): this;
7
- setValid(): this;
8
- setLoading(): this
9
- unsetLoading(): this
10
- updateTitle(): this
11
- select( optionOrIndex: HTMLElement | number ): this
12
- updateOptions( optionsArray?: FLib.SkinSelect.OptionArray[] ): this
4
+ enable(): this;
5
+ disable(): this;
6
+ setInvalid(): this;
7
+ setValid(): this;
8
+ setLoading(): this;
9
+ unsetLoading(): this;
10
+ updateTitle(): this;
11
+ select( param: number | string | HTMLElement ): this;
12
+ selectByIndex( index: number ): this;
13
+ selectByOption( optionOrItem: HTMLElement ): this;
14
+ selectByValue( value: string | number ): this;
15
+ updateOptions( optionsArray?: FLib.SkinSelect.OptionArray[] ): this;
13
16
  }
14
17
 
15
18
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@creative-web-solution/front-library",
3
3
  "title": "Frontend library",
4
4
  "description": "Frontend functions and modules",
5
- "version": "7.1.7",
5
+ "version": "7.1.10",
6
6
  "homepage": "https://github.com/creative-web-solution/front-library",
7
7
  "author": "Creative Web Solution <contact@cws-studio.com> (https://www.cws-studio.com)",
8
8
  "keywords": [],