@creative-web-solution/front-library 7.1.8 → 7.1.11
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 +15 -1
- package/Modules/SkinSelect.ts +62 -28
- package/Modules/Validator/Tools/IsDate.ts +29 -11
- package/README.md +1 -1
- package/Types/SkinSelect.d.ts +12 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,21 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
## 7.1.
|
|
4
|
+
## 7.1.11
|
|
5
|
+
|
|
6
|
+
* Validator: Update `date` validator
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## 7.1.10
|
|
10
|
+
|
|
11
|
+
* SelectSkin: Change selection feature, add:
|
|
12
|
+
* select( param: number | string | HTMLElement )
|
|
13
|
+
* selectByIndex( index: number )
|
|
14
|
+
* selectByOption( optionOrItem: HTMLElement )
|
|
15
|
+
* selectByValue( value: string | number )
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## 7.1.9
|
|
5
19
|
|
|
6
20
|
* SelectSkin: Fix templating
|
|
7
21
|
|
package/Modules/SkinSelect.ts
CHANGED
|
@@ -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
|
|
286
|
+
const IDX = Array.from( this.#$select.options ).findIndex( option => option.value === String( value ) );
|
|
293
287
|
|
|
294
|
-
if (
|
|
295
|
-
|
|
288
|
+
if ( IDX < 0 ) {
|
|
289
|
+
return this;
|
|
296
290
|
}
|
|
297
|
-
|
|
298
|
-
|
|
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
|
-
|
|
301
|
+
const IDX = index( optionOrItem ) ;
|
|
302
|
+
|
|
303
|
+
if ( IDX < 0 ) {
|
|
302
304
|
return this;
|
|
303
305
|
}
|
|
304
306
|
|
|
305
|
-
this
|
|
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
|
-
|
|
311
|
-
|
|
312
|
-
|
|
311
|
+
/**
|
|
312
|
+
* Select an option
|
|
313
|
+
*/
|
|
314
|
+
selectByIndex( index: number ): this {
|
|
313
315
|
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
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
|
|
|
@@ -392,14 +426,14 @@ export default class SkinSelect implements FLib.SkinSelect.SkinSelect {
|
|
|
392
426
|
"onClass": opt.selected ? " on" : "",
|
|
393
427
|
"text": opt.text,
|
|
394
428
|
"value": opt.value,
|
|
395
|
-
"
|
|
396
|
-
"listClassName": this.#options.listClassName
|
|
429
|
+
"itemClassName": this.#options.itemClassName
|
|
397
430
|
} ) );
|
|
398
431
|
}
|
|
399
432
|
|
|
400
433
|
this.#$parent.appendChild( strToDOM( quickTemplate( this.#options.listTpl.wrapper, {
|
|
401
|
-
"items":
|
|
402
|
-
"
|
|
434
|
+
"items": HTML_LIST.join( '' ),
|
|
435
|
+
"layerClassName": this.#options.layerClassName,
|
|
436
|
+
"listClassName": this.#options.listClassName
|
|
403
437
|
} ) ) );
|
|
404
438
|
|
|
405
439
|
|
|
@@ -422,7 +456,7 @@ export default class SkinSelect implements FLib.SkinSelect.SkinSelect {
|
|
|
422
456
|
if ( !(e.target as HTMLElement).matches( '.' + this.#options.itemClassName ) ) {
|
|
423
457
|
return;
|
|
424
458
|
}
|
|
425
|
-
this.
|
|
459
|
+
this.selectByOption( e.target as HTMLElement );
|
|
426
460
|
}
|
|
427
461
|
|
|
428
462
|
|
|
@@ -5,7 +5,9 @@
|
|
|
5
5
|
*
|
|
6
6
|
* @see extra/modules/validator.md for details
|
|
7
7
|
*/
|
|
8
|
-
export default function isDate( value: string, format = 'd/m/y' ): boolean {
|
|
8
|
+
export default function isDate( value: string, format = 'd/m/y' ): boolean {
|
|
9
|
+
format = format.toLocaleLowerCase();
|
|
10
|
+
|
|
9
11
|
const RE_SEPARATOR = ( /[^dmy]/ ).exec( format );
|
|
10
12
|
|
|
11
13
|
if ( !RE_SEPARATOR ) {
|
|
@@ -18,22 +20,38 @@ export default function isDate( value: string, format = 'd/m/y' ): boolean {
|
|
|
18
20
|
return false;
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
+
const ARR_FORMAT = format.split( SEPARATOR );
|
|
24
|
+
const ARR_VALUE = value.split( SEPARATOR );
|
|
23
25
|
|
|
24
|
-
if (
|
|
26
|
+
if ( ARR_FORMAT.length !== ARR_VALUE.length ) {
|
|
25
27
|
return false;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
const PARSED_DATE = {
|
|
31
|
+
"d": -1,
|
|
32
|
+
"m": -1,
|
|
33
|
+
"y": -1
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
ARR_FORMAT.forEach( ( format, index ) => {
|
|
37
|
+
const VALUE = Number( ARR_VALUE[ index ] );
|
|
38
|
+
|
|
39
|
+
if ( format.indexOf( 'y' ) > -1 ) {
|
|
40
|
+
PARSED_DATE.y = VALUE;
|
|
41
|
+
}
|
|
42
|
+
else if ( format.indexOf( 'm' ) > -1 ) {
|
|
43
|
+
PARSED_DATE.m = VALUE - 1;
|
|
44
|
+
}
|
|
45
|
+
else if ( format.indexOf( 'd' ) > -1 ) {
|
|
46
|
+
PARSED_DATE.d = VALUE;
|
|
47
|
+
}
|
|
48
|
+
} )
|
|
31
49
|
|
|
32
|
-
const date = new Date( y, m, d );
|
|
50
|
+
const date = new Date( PARSED_DATE.y, PARSED_DATE.m, PARSED_DATE.d );
|
|
33
51
|
|
|
34
52
|
return (
|
|
35
|
-
date.getDate() === d &&
|
|
36
|
-
date.getMonth() === m &&
|
|
37
|
-
date.getFullYear() === y
|
|
53
|
+
date.getDate() === PARSED_DATE.d &&
|
|
54
|
+
date.getMonth() === PARSED_DATE.m &&
|
|
55
|
+
date.getFullYear() === PARSED_DATE.y
|
|
38
56
|
);
|
|
39
57
|
}
|
package/README.md
CHANGED
package/Types/SkinSelect.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
declare declare namespace FLib {
|
|
2
2
|
namespace SkinSelect {
|
|
3
3
|
interface SkinSelect {
|
|
4
|
-
enable():
|
|
5
|
-
disable():
|
|
6
|
-
setInvalid():
|
|
7
|
-
setValid():
|
|
8
|
-
setLoading():
|
|
9
|
-
unsetLoading():
|
|
10
|
-
updateTitle():
|
|
11
|
-
select(
|
|
12
|
-
|
|
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.
|
|
5
|
+
"version": "7.1.11",
|
|
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": [],
|