@thednp/color-picker 2.0.0-alpha2 → 2.0.0-alpha3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/js/color-picker.cjs +3 -3
- package/dist/js/color-picker.cjs.map +1 -1
- package/dist/js/color-picker.d.ts +21 -19
- package/dist/js/color-picker.js +3 -3
- package/dist/js/color-picker.js.map +1 -1
- package/dist/js/color-picker.mjs +394 -392
- package/dist/js/color-picker.mjs.map +1 -1
- package/package.json +1 -1
- package/src/ts/index.ts +30 -44
package/package.json
CHANGED
package/src/ts/index.ts
CHANGED
@@ -208,6 +208,8 @@ export default class ColorPicker {
|
|
208
208
|
public static setAttribute = setAttribute;
|
209
209
|
public static getBoundingClientRect = getBoundingClientRect;
|
210
210
|
public static version = version;
|
211
|
+
public static colorNames = colorNames;
|
212
|
+
public static colorPickerLabels = colorPickerLabels;
|
211
213
|
|
212
214
|
id: number;
|
213
215
|
input: HTMLInputElement;
|
@@ -318,22 +320,6 @@ export default class ColorPicker {
|
|
318
320
|
this.colorPresets = colorPresets.split(',').map((x: string) => x.trim());
|
319
321
|
}
|
320
322
|
|
321
|
-
// bind events
|
322
|
-
this.showPicker = this.showPicker.bind(this);
|
323
|
-
this.togglePicker = this.togglePicker.bind(this);
|
324
|
-
this.toggleMenu = this.toggleMenu.bind(this);
|
325
|
-
this.menuClickHandler = this.menuClickHandler.bind(this);
|
326
|
-
this.menuKeyHandler = this.menuKeyHandler.bind(this);
|
327
|
-
this.pointerDown = this.pointerDown.bind(this);
|
328
|
-
this.pointerMove = this.pointerMove.bind(this);
|
329
|
-
this.pointerUp = this.pointerUp.bind(this);
|
330
|
-
this.update = this.update.bind(this);
|
331
|
-
this.handleScroll = this.handleScroll.bind(this);
|
332
|
-
this.handleFocusOut = this.handleFocusOut.bind(this);
|
333
|
-
this.changeHandler = this.changeHandler.bind(this);
|
334
|
-
this.handleDismiss = this.handleDismiss.bind(this);
|
335
|
-
this.handleKnobs = this.handleKnobs.bind(this);
|
336
|
-
|
337
323
|
// generate markup
|
338
324
|
setMarkup(this);
|
339
325
|
|
@@ -513,11 +499,11 @@ export default class ColorPicker {
|
|
513
499
|
* @param e
|
514
500
|
* @this {ColorPicker}
|
515
501
|
*/
|
516
|
-
handleFocusOut({ relatedTarget }: FocusEvent & { relatedTarget: HTMLElement }): void {
|
502
|
+
handleFocusOut = ({ relatedTarget }: FocusEvent & { relatedTarget: HTMLElement }): void => {
|
517
503
|
if (relatedTarget && !this.parent.contains(relatedTarget)) {
|
518
504
|
this.hide(true);
|
519
505
|
}
|
520
|
-
}
|
506
|
+
};
|
521
507
|
|
522
508
|
/**
|
523
509
|
* The `ColorPicker` *keyup* event listener when open.
|
@@ -525,11 +511,11 @@ export default class ColorPicker {
|
|
525
511
|
* @param e
|
526
512
|
* @this {ColorPicker}
|
527
513
|
*/
|
528
|
-
handleDismiss({ code }: KeyboardEvent): void {
|
514
|
+
handleDismiss = ({ code }: KeyboardEvent): void => {
|
529
515
|
if (this.isOpen && code === keyEscape) {
|
530
516
|
this.hide();
|
531
517
|
}
|
532
|
-
}
|
518
|
+
};
|
533
519
|
|
534
520
|
/**
|
535
521
|
* The `ColorPicker` *scroll* event listener when open.
|
@@ -537,7 +523,7 @@ export default class ColorPicker {
|
|
537
523
|
* @param e
|
538
524
|
* @this {ColorPicker}
|
539
525
|
*/
|
540
|
-
handleScroll(e: Event): void {
|
526
|
+
handleScroll = (e: Event): void => {
|
541
527
|
const { activeElement } = getDocument(this.input);
|
542
528
|
|
543
529
|
this.updateDropdownPosition();
|
@@ -550,14 +536,14 @@ export default class ColorPicker {
|
|
550
536
|
e.stopPropagation();
|
551
537
|
e.preventDefault();
|
552
538
|
}
|
553
|
-
}
|
539
|
+
};
|
554
540
|
|
555
541
|
/**
|
556
542
|
* The `ColorPicker` keyboard event listener for menu navigation.
|
557
543
|
*
|
558
544
|
* @param e
|
559
545
|
*/
|
560
|
-
menuKeyHandler(e: Event & { target: HTMLElement; code: string }) {
|
546
|
+
menuKeyHandler = (e: Event & { target: HTMLElement; code: string }) => {
|
561
547
|
const { target, code } = e;
|
562
548
|
const { previousElementSibling, nextElementSibling, parentElement } = target;
|
563
549
|
const isColorOptionsMenu = parentElement && hasClass(parentElement, 'color-options');
|
@@ -591,7 +577,7 @@ export default class ColorPicker {
|
|
591
577
|
if ([keyEnter, keySpace].includes(code)) {
|
592
578
|
this.menuClickHandler(e);
|
593
579
|
}
|
594
|
-
}
|
580
|
+
};
|
595
581
|
|
596
582
|
/**
|
597
583
|
* The `ColorPicker` click event listener for the colour menu presets / defaults.
|
@@ -599,7 +585,7 @@ export default class ColorPicker {
|
|
599
585
|
* @param e
|
600
586
|
* @this {ColorPicker}
|
601
587
|
*/
|
602
|
-
menuClickHandler(e: Event): void {
|
588
|
+
menuClickHandler = (e: Event): void => {
|
603
589
|
const { target } = e;
|
604
590
|
const { colorMenu } = this;
|
605
591
|
const newOption = (getAttribute(target as HTMLElement, 'data-value') || '').trim();
|
@@ -637,14 +623,14 @@ export default class ColorPicker {
|
|
637
623
|
}
|
638
624
|
firePickerChange(this);
|
639
625
|
}
|
640
|
-
}
|
626
|
+
};
|
641
627
|
|
642
628
|
/**
|
643
629
|
* The `ColorPicker` *touchstart* / *mousedown* events listener for control knobs.
|
644
630
|
*
|
645
631
|
* @param e
|
646
632
|
*/
|
647
|
-
pointerDown(e: Event & { target: HTMLElement; pageX: number; pageY: number }) {
|
633
|
+
pointerDown = (e: Event & { target: HTMLElement; pageX: number; pageY: number }) => {
|
648
634
|
const { target, pageX, pageY } = e;
|
649
635
|
const { colorMenu, visuals, controlKnobs } = this;
|
650
636
|
const [v1, v2, v3] = visuals;
|
@@ -675,7 +661,7 @@ export default class ColorPicker {
|
|
675
661
|
}
|
676
662
|
}
|
677
663
|
e.preventDefault();
|
678
|
-
}
|
664
|
+
};
|
679
665
|
|
680
666
|
/**
|
681
667
|
* The `ColorPicker` *touchend* / *mouseup* events listener for control knobs.
|
@@ -683,7 +669,7 @@ export default class ColorPicker {
|
|
683
669
|
* @param e
|
684
670
|
* @this
|
685
671
|
*/
|
686
|
-
pointerUp({ target }: PointerEvent & { target: HTMLElement }) {
|
672
|
+
pointerUp = ({ target }: PointerEvent & { target: HTMLElement }) => {
|
687
673
|
const { parent } = this;
|
688
674
|
const doc = getDocument(parent);
|
689
675
|
const currentOpen = querySelector(`${colorPickerParentSelector}.open`, doc) !== null;
|
@@ -694,14 +680,14 @@ export default class ColorPicker {
|
|
694
680
|
}
|
695
681
|
|
696
682
|
this.dragElement = undefined;
|
697
|
-
}
|
683
|
+
};
|
698
684
|
|
699
685
|
/**
|
700
686
|
* The `ColorPicker` *touchmove* / *mousemove* events listener for control knobs.
|
701
687
|
*
|
702
688
|
* @param {PointerEvent} e
|
703
689
|
*/
|
704
|
-
pointerMove(e: PointerEvent): void {
|
690
|
+
pointerMove = (e: PointerEvent): void => {
|
705
691
|
const { dragElement, visuals } = this;
|
706
692
|
const [v1, v2, v3] = visuals;
|
707
693
|
const { pageX, pageY } = e;
|
@@ -724,14 +710,14 @@ export default class ColorPicker {
|
|
724
710
|
if (dragElement === v3) {
|
725
711
|
this.changeAlpha(offsetY);
|
726
712
|
}
|
727
|
-
}
|
713
|
+
};
|
728
714
|
|
729
715
|
/**
|
730
716
|
* The `ColorPicker` *keydown* event listener for control knobs.
|
731
717
|
*
|
732
718
|
* @param e
|
733
719
|
*/
|
734
|
-
handleKnobs(e: Event & { code: string }) {
|
720
|
+
handleKnobs = (e: Event & { code: string }) => {
|
735
721
|
const { target, code } = e;
|
736
722
|
|
737
723
|
// only react to arrow buttons
|
@@ -777,10 +763,10 @@ export default class ColorPicker {
|
|
777
763
|
}
|
778
764
|
this.handleScroll(e);
|
779
765
|
}
|
780
|
-
}
|
766
|
+
};
|
781
767
|
|
782
768
|
/** The event listener of the colour form inputs. */
|
783
|
-
changeHandler(): void {
|
769
|
+
changeHandler = (): void => {
|
784
770
|
let colorSource;
|
785
771
|
const { inputs, format, value: currentValue, input, controlPositions, visuals } = this;
|
786
772
|
const { activeElement } = getDocument(input);
|
@@ -845,7 +831,7 @@ export default class ColorPicker {
|
|
845
831
|
this.value = currentValue;
|
846
832
|
}
|
847
833
|
}
|
848
|
-
}
|
834
|
+
};
|
849
835
|
|
850
836
|
/**
|
851
837
|
* Updates `ColorPicker` first control:
|
@@ -975,14 +961,14 @@ export default class ColorPicker {
|
|
975
961
|
* * initialization
|
976
962
|
* * window resize
|
977
963
|
*/
|
978
|
-
update() {
|
964
|
+
update = () => {
|
979
965
|
this.updateDropdownPosition();
|
980
966
|
this.updateAppearance();
|
981
967
|
this.setControlPositions();
|
982
968
|
this.updateInputs(true);
|
983
969
|
this.updateControls();
|
984
970
|
this.updateVisuals();
|
985
|
-
}
|
971
|
+
};
|
986
972
|
|
987
973
|
/** Updates the open dropdown position on *scroll* event. */
|
988
974
|
updateDropdownPosition() {
|
@@ -1155,7 +1141,7 @@ export default class ColorPicker {
|
|
1155
1141
|
*
|
1156
1142
|
* @param e
|
1157
1143
|
*/
|
1158
|
-
togglePicker(e?: Event) {
|
1144
|
+
togglePicker = (e?: Event) => {
|
1159
1145
|
if (e) e.preventDefault();
|
1160
1146
|
const { colorPicker } = this;
|
1161
1147
|
|
@@ -1164,16 +1150,16 @@ export default class ColorPicker {
|
|
1164
1150
|
} else {
|
1165
1151
|
showDropdown(this, colorPicker);
|
1166
1152
|
}
|
1167
|
-
}
|
1153
|
+
};
|
1168
1154
|
|
1169
1155
|
/** Shows the `ColorPicker` dropdown. */
|
1170
|
-
showPicker() {
|
1156
|
+
showPicker = () => {
|
1171
1157
|
const { colorPicker } = this;
|
1172
1158
|
|
1173
1159
|
if (!['top', 'bottom'].some(c => hasClass(colorPicker, c))) {
|
1174
1160
|
showDropdown(this, colorPicker);
|
1175
1161
|
}
|
1176
|
-
}
|
1162
|
+
};
|
1177
1163
|
|
1178
1164
|
/**
|
1179
1165
|
* Toggles the visibility of the `ColorPicker` presets menu.
|
@@ -1181,7 +1167,7 @@ export default class ColorPicker {
|
|
1181
1167
|
* @param e
|
1182
1168
|
* @this {ColorPicker}
|
1183
1169
|
*/
|
1184
|
-
toggleMenu(e?: Event) {
|
1170
|
+
toggleMenu = (e?: Event) => {
|
1185
1171
|
if (e) e.preventDefault();
|
1186
1172
|
const { colorMenu } = this;
|
1187
1173
|
|
@@ -1190,7 +1176,7 @@ export default class ColorPicker {
|
|
1190
1176
|
} else {
|
1191
1177
|
showDropdown(this, colorMenu);
|
1192
1178
|
}
|
1193
|
-
}
|
1179
|
+
};
|
1194
1180
|
|
1195
1181
|
/**
|
1196
1182
|
* Hides the currently open `ColorPicker` dropdown.
|