@cambly/syntax-core 4.1.0 → 4.2.0
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/dist/index.css +47 -50
- package/dist/index.css.map +1 -1
- package/dist/index.js +105 -93
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +106 -94
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -643,11 +643,98 @@ var IconButton = ({
|
|
|
643
643
|
var IconButton_default = IconButton;
|
|
644
644
|
|
|
645
645
|
// src/Checkbox/Checkbox.tsx
|
|
646
|
-
var
|
|
646
|
+
var import_react2 = require("react");
|
|
647
647
|
var import_classnames7 = __toESM(require_classnames());
|
|
648
648
|
|
|
649
|
+
// src/useFocusVisible.tsx
|
|
650
|
+
var import_react = require("react");
|
|
651
|
+
var hasSetupGlobalListeners = false;
|
|
652
|
+
var currentModality = null;
|
|
653
|
+
var changeHandlers = /* @__PURE__ */ new Set();
|
|
654
|
+
var hasEventBeforeFocus = false;
|
|
655
|
+
var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
|
|
656
|
+
function isValidKey(e) {
|
|
657
|
+
return !(e.metaKey || !isMac && e.altKey || e.ctrlKey);
|
|
658
|
+
}
|
|
659
|
+
function triggerChangeHandlers(modality, e) {
|
|
660
|
+
changeHandlers.forEach((handler) => {
|
|
661
|
+
handler(modality, e);
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
function handleKeyboardEvent(e) {
|
|
665
|
+
hasEventBeforeFocus = true;
|
|
666
|
+
if (isValidKey(e)) {
|
|
667
|
+
currentModality = "keyboard";
|
|
668
|
+
triggerChangeHandlers("keyboard", e);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
function handlePointerEvent(e) {
|
|
672
|
+
currentModality = "pointer";
|
|
673
|
+
if (e.type === "mousedown" || e.type === "pointerdown") {
|
|
674
|
+
hasEventBeforeFocus = true;
|
|
675
|
+
triggerChangeHandlers("pointer", e);
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
function handleFocusEvent(e) {
|
|
679
|
+
if (e.target === window || e.target === document) {
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
if (!hasEventBeforeFocus) {
|
|
683
|
+
currentModality = "keyboard";
|
|
684
|
+
triggerChangeHandlers("keyboard", e);
|
|
685
|
+
}
|
|
686
|
+
hasEventBeforeFocus = false;
|
|
687
|
+
}
|
|
688
|
+
function handleWindowBlur() {
|
|
689
|
+
hasEventBeforeFocus = false;
|
|
690
|
+
}
|
|
691
|
+
function isFocusVisible() {
|
|
692
|
+
return currentModality !== "pointer";
|
|
693
|
+
}
|
|
694
|
+
function setupGlobalFocusEvents() {
|
|
695
|
+
if (typeof window === "undefined" || hasSetupGlobalListeners) {
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
const { focus } = HTMLElement.prototype;
|
|
699
|
+
HTMLElement.prototype.focus = function focusElement(...args) {
|
|
700
|
+
hasEventBeforeFocus = true;
|
|
701
|
+
focus.apply(this, args);
|
|
702
|
+
};
|
|
703
|
+
document.addEventListener("keydown", handleKeyboardEvent, true);
|
|
704
|
+
document.addEventListener("keyup", handleKeyboardEvent, true);
|
|
705
|
+
window.addEventListener("focus", handleFocusEvent, true);
|
|
706
|
+
window.addEventListener("blur", handleWindowBlur, false);
|
|
707
|
+
if (typeof PointerEvent !== "undefined") {
|
|
708
|
+
document.addEventListener("pointerdown", handlePointerEvent, true);
|
|
709
|
+
document.addEventListener("pointermove", handlePointerEvent, true);
|
|
710
|
+
document.addEventListener("pointerup", handlePointerEvent, true);
|
|
711
|
+
} else {
|
|
712
|
+
document.addEventListener("mousedown", handlePointerEvent, true);
|
|
713
|
+
document.addEventListener("mousemove", handlePointerEvent, true);
|
|
714
|
+
document.addEventListener("mouseup", handlePointerEvent, true);
|
|
715
|
+
}
|
|
716
|
+
hasSetupGlobalListeners = true;
|
|
717
|
+
}
|
|
718
|
+
function useFocusVisible() {
|
|
719
|
+
setupGlobalFocusEvents();
|
|
720
|
+
const [isFocusVisibleState, setFocusVisible] = (0, import_react.useState)(isFocusVisible());
|
|
721
|
+
(0, import_react.useEffect)(() => {
|
|
722
|
+
const handler = () => {
|
|
723
|
+
setFocusVisible(isFocusVisible());
|
|
724
|
+
};
|
|
725
|
+
changeHandlers.add(handler);
|
|
726
|
+
return () => {
|
|
727
|
+
changeHandlers.delete(handler);
|
|
728
|
+
};
|
|
729
|
+
}, []);
|
|
730
|
+
return { isFocusVisible: isFocusVisibleState };
|
|
731
|
+
}
|
|
732
|
+
|
|
649
733
|
// css-module:./Checkbox.module.css#css-module
|
|
650
|
-
var Checkbox_module_default = { "mainContainer": "
|
|
734
|
+
var Checkbox_module_default = { "mainContainer": "_mainContainer_1jq7b_1", "checkboxContainer": "_checkboxContainer_1jq7b_8", "inputOverlay": "_inputOverlay_1jq7b_13", "checkbox": "_checkbox_1jq7b_8", "uncheckedBox": "_uncheckedBox_1jq7b_30", "uncheckedBorder": "_uncheckedBorder_1jq7b_34", "uncheckedErrorBorder": "_uncheckedErrorBorder_1jq7b_38", "checkedBox": "_checkedBox_1jq7b_42", "checkedNonError": "_checkedNonError_1jq7b_46", "checkedError": "_checkedError_1jq7b_50", "sm": "_sm_1jq7b_54", "md": "_md_1jq7b_60" };
|
|
735
|
+
|
|
736
|
+
// css-module:../Focus.module.css#css-module
|
|
737
|
+
var Focus_module_default = { "accessibilityOutlineFocus": "_accessibilityOutlineFocus_1h8bq_1" };
|
|
651
738
|
|
|
652
739
|
// src/Checkbox/Checkbox.tsx
|
|
653
740
|
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
@@ -667,17 +754,18 @@ var Checkbox = ({
|
|
|
667
754
|
error = false,
|
|
668
755
|
onChange
|
|
669
756
|
}) => {
|
|
670
|
-
const [isFocused, setIsFocused] = (0,
|
|
757
|
+
const [isFocused, setIsFocused] = (0, import_react2.useState)(false);
|
|
758
|
+
const { isFocusVisible: isFocusVisible2 } = useFocusVisible();
|
|
671
759
|
const checkboxStyling = (0, import_classnames7.default)(Checkbox_module_default.checkbox, Checkbox_module_default[size]);
|
|
672
760
|
const uncheckedStyling = (0, import_classnames7.default)(checkboxStyling, Checkbox_module_default.uncheckedBox, {
|
|
673
761
|
[Checkbox_module_default.uncheckedBorder]: !error,
|
|
674
762
|
[Checkbox_module_default.uncheckedErrorBorder]: error,
|
|
675
|
-
[
|
|
763
|
+
[Focus_module_default.accessibilityOutlineFocus]: isFocused && isFocusVisible2
|
|
676
764
|
});
|
|
677
765
|
const checkedStyling = (0, import_classnames7.default)(checkboxStyling, Checkbox_module_default.checkedBox, {
|
|
678
766
|
[Checkbox_module_default.checkedNonError]: !error,
|
|
679
767
|
[Checkbox_module_default.checkedError]: error,
|
|
680
|
-
[
|
|
768
|
+
[Focus_module_default.accessibilityOutlineFocus]: isFocused && isFocusVisible2
|
|
681
769
|
});
|
|
682
770
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("label", { className: (0, import_classnames7.default)(Checkbox_module_default.mainContainer), children: [
|
|
683
771
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: Checkbox_module_default.checkboxContainer, children: [
|
|
@@ -732,91 +820,7 @@ var import_react3 = require("react");
|
|
|
732
820
|
var import_classnames8 = __toESM(require_classnames());
|
|
733
821
|
|
|
734
822
|
// css-module:./RadioButton.module.css#css-module
|
|
735
|
-
var RadioButton_module_default = { "radioBaseContainer": "
|
|
736
|
-
|
|
737
|
-
// src/useFocusVisible.tsx
|
|
738
|
-
var import_react2 = require("react");
|
|
739
|
-
var hasSetupGlobalListeners = false;
|
|
740
|
-
var currentModality = null;
|
|
741
|
-
var changeHandlers = /* @__PURE__ */ new Set();
|
|
742
|
-
var hasEventBeforeFocus = false;
|
|
743
|
-
var isMac = typeof window !== "undefined" && window.navigator != null ? /^Mac/.test(window.navigator.platform) : false;
|
|
744
|
-
function isValidKey(e) {
|
|
745
|
-
return !(e.metaKey || !isMac && e.altKey || e.ctrlKey);
|
|
746
|
-
}
|
|
747
|
-
function triggerChangeHandlers(modality, e) {
|
|
748
|
-
changeHandlers.forEach((handler) => {
|
|
749
|
-
handler(modality, e);
|
|
750
|
-
});
|
|
751
|
-
}
|
|
752
|
-
function handleKeyboardEvent(e) {
|
|
753
|
-
hasEventBeforeFocus = true;
|
|
754
|
-
if (isValidKey(e)) {
|
|
755
|
-
currentModality = "keyboard";
|
|
756
|
-
triggerChangeHandlers("keyboard", e);
|
|
757
|
-
}
|
|
758
|
-
}
|
|
759
|
-
function handlePointerEvent(e) {
|
|
760
|
-
currentModality = "pointer";
|
|
761
|
-
if (e.type === "mousedown" || e.type === "pointerdown") {
|
|
762
|
-
hasEventBeforeFocus = true;
|
|
763
|
-
triggerChangeHandlers("pointer", e);
|
|
764
|
-
}
|
|
765
|
-
}
|
|
766
|
-
function handleFocusEvent(e) {
|
|
767
|
-
if (e.target === window || e.target === document) {
|
|
768
|
-
return;
|
|
769
|
-
}
|
|
770
|
-
if (!hasEventBeforeFocus) {
|
|
771
|
-
currentModality = "keyboard";
|
|
772
|
-
triggerChangeHandlers("keyboard", e);
|
|
773
|
-
}
|
|
774
|
-
hasEventBeforeFocus = false;
|
|
775
|
-
}
|
|
776
|
-
function handleWindowBlur() {
|
|
777
|
-
hasEventBeforeFocus = false;
|
|
778
|
-
}
|
|
779
|
-
function isFocusVisible() {
|
|
780
|
-
return currentModality !== "pointer";
|
|
781
|
-
}
|
|
782
|
-
function setupGlobalFocusEvents() {
|
|
783
|
-
if (typeof window === "undefined" || hasSetupGlobalListeners) {
|
|
784
|
-
return;
|
|
785
|
-
}
|
|
786
|
-
const { focus } = HTMLElement.prototype;
|
|
787
|
-
HTMLElement.prototype.focus = function focusElement(...args) {
|
|
788
|
-
hasEventBeforeFocus = true;
|
|
789
|
-
focus.apply(this, args);
|
|
790
|
-
};
|
|
791
|
-
document.addEventListener("keydown", handleKeyboardEvent, true);
|
|
792
|
-
document.addEventListener("keyup", handleKeyboardEvent, true);
|
|
793
|
-
window.addEventListener("focus", handleFocusEvent, true);
|
|
794
|
-
window.addEventListener("blur", handleWindowBlur, false);
|
|
795
|
-
if (typeof PointerEvent !== "undefined") {
|
|
796
|
-
document.addEventListener("pointerdown", handlePointerEvent, true);
|
|
797
|
-
document.addEventListener("pointermove", handlePointerEvent, true);
|
|
798
|
-
document.addEventListener("pointerup", handlePointerEvent, true);
|
|
799
|
-
} else {
|
|
800
|
-
document.addEventListener("mousedown", handlePointerEvent, true);
|
|
801
|
-
document.addEventListener("mousemove", handlePointerEvent, true);
|
|
802
|
-
document.addEventListener("mouseup", handlePointerEvent, true);
|
|
803
|
-
}
|
|
804
|
-
hasSetupGlobalListeners = true;
|
|
805
|
-
}
|
|
806
|
-
function useFocusVisible() {
|
|
807
|
-
setupGlobalFocusEvents();
|
|
808
|
-
const [isFocusVisibleState, setFocusVisible] = (0, import_react2.useState)(isFocusVisible());
|
|
809
|
-
(0, import_react2.useEffect)(() => {
|
|
810
|
-
const handler = () => {
|
|
811
|
-
setFocusVisible(isFocusVisible());
|
|
812
|
-
};
|
|
813
|
-
changeHandlers.add(handler);
|
|
814
|
-
return () => {
|
|
815
|
-
changeHandlers.delete(handler);
|
|
816
|
-
};
|
|
817
|
-
}, []);
|
|
818
|
-
return { isFocusVisible: isFocusVisibleState };
|
|
819
|
-
}
|
|
823
|
+
var RadioButton_module_default = { "radioBaseContainer": "_radioBaseContainer_144ms_1", "smBase": "_smBase_144ms_8", "mdBase": "_mdBase_144ms_13", "radioStyleOverride": "_radioStyleOverride_144ms_18", "smOverride": "_smOverride_144ms_23", "mdOverride": "_mdOverride_144ms_28", "background": "_background_144ms_33", "sm": "_sm_144ms_8", "md": "_md_144ms_13", "neutralBorder": "_neutralBorder_144ms_50", "smCheckedBorder": "_smCheckedBorder_144ms_54", "mdCheckedBorder": "_mdCheckedBorder_144ms_58", "errorBorderColor": "_errorBorderColor_144ms_62", "borderColor": "_borderColor_144ms_66" };
|
|
820
824
|
|
|
821
825
|
// src/RadioButton/RadioButton.tsx
|
|
822
826
|
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
@@ -835,7 +839,7 @@ var RadioButton = ({
|
|
|
835
839
|
const sharedStyles = (0, import_classnames8.default)(RadioButton_module_default.background, RadioButton_module_default[size], {
|
|
836
840
|
[RadioButton_module_default.errorBorderColor]: error,
|
|
837
841
|
[RadioButton_module_default.borderColor]: !error,
|
|
838
|
-
[
|
|
842
|
+
[Focus_module_default.accessibilityOutlineFocus]: isFocused && isFocusVisible2
|
|
839
843
|
});
|
|
840
844
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
|
|
841
845
|
"label",
|
|
@@ -898,7 +902,7 @@ var ColorBaseDestructive700 = "#d32a4b";
|
|
|
898
902
|
var ColorBaseGray800 = "#353535";
|
|
899
903
|
|
|
900
904
|
// css-module:./SelectList.module.css#css-module
|
|
901
|
-
var SelectList_module_default = { "selectContainer": "
|
|
905
|
+
var SelectList_module_default = { "selectContainer": "_selectContainer_1e7f9_1", "opacityOverlay": "_opacityOverlay_1e7f9_7", "outerTextContainer": "_outerTextContainer_1e7f9_11", "selectWrapper": "_selectWrapper_1e7f9_16", "selectBox": "_selectBox_1e7f9_21", "seletBoxMouseFocusStyling": "_seletBoxMouseFocusStyling_1e7f9_35", "unselected": "_unselected_1e7f9_40", "selected": "_selected_1e7f9_44", "arrowIcon": "_arrowIcon_1e7f9_48", "sm": "_sm_1e7f9_62", "md": "_md_1e7f9_67", "lg": "_lg_1e7f9_72", "selectError": "_selectError_1e7f9_77" };
|
|
902
906
|
|
|
903
907
|
// src/SelectList/SelectOption.tsx
|
|
904
908
|
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
@@ -936,6 +940,8 @@ var SelectList = ({
|
|
|
936
940
|
size = "md"
|
|
937
941
|
}) => {
|
|
938
942
|
const id = (0, import_react4.useId)();
|
|
943
|
+
const { isFocusVisible: isFocusVisible2 } = useFocusVisible();
|
|
944
|
+
const [isFocused, setIsFocused] = (0, import_react4.useState)(false);
|
|
939
945
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(
|
|
940
946
|
"div",
|
|
941
947
|
{
|
|
@@ -954,10 +960,16 @@ var SelectList = ({
|
|
|
954
960
|
className: (0, import_classnames9.default)(SelectList_module_default.selectBox, SelectList_module_default[size], {
|
|
955
961
|
[SelectList_module_default.unselected]: !selectedValue && !errorText,
|
|
956
962
|
[SelectList_module_default.selected]: selectedValue && !errorText,
|
|
957
|
-
[SelectList_module_default.selectError]: errorText
|
|
963
|
+
[SelectList_module_default.selectError]: errorText,
|
|
964
|
+
[Focus_module_default.accessibilityOutlineFocus]: isFocused && isFocusVisible2,
|
|
965
|
+
// for focus keyboard
|
|
966
|
+
[SelectList_module_default.seletBoxMouseFocusStyling]: isFocused && !isFocusVisible2
|
|
967
|
+
// for focus mouse
|
|
958
968
|
}),
|
|
959
969
|
onChange,
|
|
960
970
|
value: placeholderText && !selectedValue ? placeholderText : selectedValue,
|
|
971
|
+
onFocus: () => setIsFocused(true),
|
|
972
|
+
onBlur: () => setIsFocused(false),
|
|
961
973
|
children: [
|
|
962
974
|
placeholderText && /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("option", { disabled: true, value: placeholderText, children: placeholderText }),
|
|
963
975
|
children
|