@dloizides/ui-feedback 1.5.0 → 1.7.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/CHANGELOG.md +88 -0
- package/README.md +73 -1
- package/dist/index.d.mts +184 -2
- package/dist/index.d.ts +184 -2
- package/dist/index.js +267 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +266 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React3, { createContext, useMemo, useContext, useCallback, useState, useEffect, useSyncExternalStore, useRef } from 'react';
|
|
1
|
+
import React3, { createContext, useMemo, useContext, useCallback, useState, useEffect, useSyncExternalStore, Component, useRef } from 'react';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { StyleSheet, Platform, View, Text, TouchableOpacity, ActivityIndicator, Animated, Easing, Modal } from 'react-native';
|
|
4
4
|
|
|
@@ -54,7 +54,8 @@ var FEEDBACK_TEST_IDS = {
|
|
|
54
54
|
confirmButton: "confirm-button",
|
|
55
55
|
cancelConfirmButton: "cancel-confirm-button",
|
|
56
56
|
notificationToast: "notification-toast",
|
|
57
|
-
warmingOverlay: "warming-overlay"
|
|
57
|
+
warmingOverlay: "warming-overlay",
|
|
58
|
+
errorBoundary: "error-boundary"
|
|
58
59
|
};
|
|
59
60
|
var MESSAGE_FONT_SIZE = 16;
|
|
60
61
|
var CONTAINER_PADDING = 20;
|
|
@@ -727,6 +728,268 @@ var WarmingOverlay = ({
|
|
|
727
728
|
);
|
|
728
729
|
};
|
|
729
730
|
|
|
730
|
-
|
|
731
|
+
// src/toastBus/createToastBus.ts
|
|
732
|
+
var DEFAULT_TOAST_TYPE = "info";
|
|
733
|
+
function createToastBus() {
|
|
734
|
+
const listeners2 = /* @__PURE__ */ new Set();
|
|
735
|
+
const emit2 = (text, type = DEFAULT_TOAST_TYPE) => {
|
|
736
|
+
for (const push of [...listeners2]) push({ text, type });
|
|
737
|
+
};
|
|
738
|
+
return {
|
|
739
|
+
subscribe(push) {
|
|
740
|
+
listeners2.add(push);
|
|
741
|
+
return () => {
|
|
742
|
+
listeners2.delete(push);
|
|
743
|
+
};
|
|
744
|
+
},
|
|
745
|
+
emit: emit2,
|
|
746
|
+
success(text) {
|
|
747
|
+
emit2(text, "success");
|
|
748
|
+
},
|
|
749
|
+
error(text) {
|
|
750
|
+
emit2(text, "error");
|
|
751
|
+
},
|
|
752
|
+
info(text) {
|
|
753
|
+
emit2(text, "info");
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
var CONTAINER_PADDING3 = 20;
|
|
758
|
+
var CONTENT_MAX_WIDTH = 400;
|
|
759
|
+
var TITLE_FONT_SIZE2 = 24;
|
|
760
|
+
var TITLE_MARGIN_BOTTOM = 12;
|
|
761
|
+
var DETAILS_PADDING = 12;
|
|
762
|
+
var DETAILS_BORDER_RADIUS = 8;
|
|
763
|
+
var DETAILS_BORDER_WIDTH = 1;
|
|
764
|
+
var DETAILS_MARGIN_VERTICAL = 16;
|
|
765
|
+
var DETAILS_TITLE_FONT_SIZE = 14;
|
|
766
|
+
var DETAILS_TITLE_MARGIN_BOTTOM = 4;
|
|
767
|
+
var DETAILS_TEXT_FONT_SIZE = 12;
|
|
768
|
+
var BUTTON_PADDING_H2 = 24;
|
|
769
|
+
var BUTTON_PADDING_V2 = 12;
|
|
770
|
+
var BUTTON_BORDER_RADIUS2 = 8;
|
|
771
|
+
var BUTTON_MARGIN_TOP2 = 12;
|
|
772
|
+
var BUTTON_FONT_SIZE2 = 16;
|
|
773
|
+
var styles8 = StyleSheet.create({
|
|
774
|
+
container: {
|
|
775
|
+
flex: 1,
|
|
776
|
+
justifyContent: "center",
|
|
777
|
+
alignItems: "center",
|
|
778
|
+
padding: CONTAINER_PADDING3
|
|
779
|
+
},
|
|
780
|
+
content: {
|
|
781
|
+
maxWidth: CONTENT_MAX_WIDTH,
|
|
782
|
+
alignItems: "center"
|
|
783
|
+
},
|
|
784
|
+
title: {
|
|
785
|
+
fontSize: TITLE_FONT_SIZE2,
|
|
786
|
+
fontWeight: "bold",
|
|
787
|
+
marginBottom: TITLE_MARGIN_BOTTOM,
|
|
788
|
+
textAlign: "center"
|
|
789
|
+
},
|
|
790
|
+
details: {
|
|
791
|
+
padding: DETAILS_PADDING,
|
|
792
|
+
borderRadius: DETAILS_BORDER_RADIUS,
|
|
793
|
+
borderWidth: DETAILS_BORDER_WIDTH,
|
|
794
|
+
marginVertical: DETAILS_MARGIN_VERTICAL,
|
|
795
|
+
width: "100%"
|
|
796
|
+
},
|
|
797
|
+
detailsTitle: {
|
|
798
|
+
fontSize: DETAILS_TITLE_FONT_SIZE,
|
|
799
|
+
fontWeight: "bold",
|
|
800
|
+
marginBottom: DETAILS_TITLE_MARGIN_BOTTOM
|
|
801
|
+
},
|
|
802
|
+
detailsText: {
|
|
803
|
+
fontSize: DETAILS_TEXT_FONT_SIZE,
|
|
804
|
+
fontFamily: "monospace"
|
|
805
|
+
},
|
|
806
|
+
button: {
|
|
807
|
+
paddingHorizontal: BUTTON_PADDING_H2,
|
|
808
|
+
paddingVertical: BUTTON_PADDING_V2,
|
|
809
|
+
borderRadius: BUTTON_BORDER_RADIUS2,
|
|
810
|
+
marginTop: BUTTON_MARGIN_TOP2
|
|
811
|
+
},
|
|
812
|
+
buttonText: {
|
|
813
|
+
fontSize: BUTTON_FONT_SIZE2,
|
|
814
|
+
fontWeight: "600"
|
|
815
|
+
}
|
|
816
|
+
});
|
|
817
|
+
var ErrorBoundaryFallback = ({
|
|
818
|
+
labels,
|
|
819
|
+
testIDPrefix,
|
|
820
|
+
error,
|
|
821
|
+
showDetails,
|
|
822
|
+
showRetry,
|
|
823
|
+
reloadIsPrimary,
|
|
824
|
+
onRetry,
|
|
825
|
+
onReload
|
|
826
|
+
}) => {
|
|
827
|
+
const { theme } = useFeedbackUi();
|
|
828
|
+
const warningColor = (theme.semantic.warning ?? theme.semantic.error)["500"];
|
|
829
|
+
const primaryColor = theme.palette.primary["500"];
|
|
830
|
+
const hasDetails = showDetails && error !== null;
|
|
831
|
+
const primaryFill = { backgroundColor: primaryColor };
|
|
832
|
+
const primaryInk = { color: theme.colors.surfaceElevated };
|
|
833
|
+
const secondaryFill = { backgroundColor: theme.colors.surface };
|
|
834
|
+
const secondaryInk = { color: theme.colors.text };
|
|
835
|
+
const retryButton = showRetry ? /* @__PURE__ */ jsx(
|
|
836
|
+
TouchableOpacity,
|
|
837
|
+
{
|
|
838
|
+
accessibilityHint: labels.tryAgainHint,
|
|
839
|
+
accessibilityLabel: labels.tryAgain,
|
|
840
|
+
accessibilityRole: "button",
|
|
841
|
+
style: [styles8.button, reloadIsPrimary ? secondaryFill : primaryFill],
|
|
842
|
+
testID: `${testIDPrefix}-retry-button`,
|
|
843
|
+
onPress: onRetry,
|
|
844
|
+
children: /* @__PURE__ */ jsx(Text, { style: [styles8.buttonText, reloadIsPrimary ? secondaryInk : primaryInk], children: labels.tryAgain })
|
|
845
|
+
}
|
|
846
|
+
) : null;
|
|
847
|
+
const reloadButton = typeof onReload === "function" ? /* @__PURE__ */ jsx(
|
|
848
|
+
TouchableOpacity,
|
|
849
|
+
{
|
|
850
|
+
accessibilityHint: labels.reloadHint,
|
|
851
|
+
accessibilityLabel: labels.reload,
|
|
852
|
+
accessibilityRole: "button",
|
|
853
|
+
style: [styles8.button, reloadIsPrimary ? primaryFill : secondaryFill],
|
|
854
|
+
testID: `${testIDPrefix}-reload-button`,
|
|
855
|
+
onPress: onReload,
|
|
856
|
+
children: /* @__PURE__ */ jsx(Text, { style: [styles8.buttonText, reloadIsPrimary ? primaryInk : secondaryInk], children: labels.reload })
|
|
857
|
+
}
|
|
858
|
+
) : null;
|
|
859
|
+
return /* @__PURE__ */ jsx(
|
|
860
|
+
View,
|
|
861
|
+
{
|
|
862
|
+
accessibilityLiveRegion: "assertive",
|
|
863
|
+
role: "alert",
|
|
864
|
+
style: [styles8.container, { backgroundColor: theme.colors.background }],
|
|
865
|
+
testID: testIDPrefix,
|
|
866
|
+
children: /* @__PURE__ */ jsxs(View, { style: styles8.content, children: [
|
|
867
|
+
/* @__PURE__ */ jsx(Text, { style: [styles8.title, { color: theme.colors.text }], children: labels.title }),
|
|
868
|
+
/* @__PURE__ */ jsx(ErrorState, { message: labels.message, testID: `${testIDPrefix}-message` }),
|
|
869
|
+
hasDetails ? /* @__PURE__ */ jsxs(
|
|
870
|
+
View,
|
|
871
|
+
{
|
|
872
|
+
style: [styles8.details, { backgroundColor: theme.colors.surface, borderColor: warningColor }],
|
|
873
|
+
testID: `${testIDPrefix}-details`,
|
|
874
|
+
children: [
|
|
875
|
+
/* @__PURE__ */ jsx(Text, { style: [styles8.detailsTitle, { color: warningColor }], children: labels.errorDetails }),
|
|
876
|
+
/* @__PURE__ */ jsx(Text, { style: [styles8.detailsText, { color: theme.colors.textSecondary }], children: error.message })
|
|
877
|
+
]
|
|
878
|
+
}
|
|
879
|
+
) : null,
|
|
880
|
+
reloadIsPrimary ? reloadButton : retryButton,
|
|
881
|
+
reloadIsPrimary ? retryButton : reloadButton
|
|
882
|
+
] })
|
|
883
|
+
}
|
|
884
|
+
);
|
|
885
|
+
};
|
|
886
|
+
var CONTAINER_PADDING4 = 20;
|
|
887
|
+
var MESSAGE_FONT_SIZE3 = 16;
|
|
888
|
+
var MESSAGE_MARGIN_TOP = 12;
|
|
889
|
+
var styles9 = StyleSheet.create({
|
|
890
|
+
container: {
|
|
891
|
+
flex: 1,
|
|
892
|
+
justifyContent: "center",
|
|
893
|
+
alignItems: "center",
|
|
894
|
+
padding: CONTAINER_PADDING4
|
|
895
|
+
},
|
|
896
|
+
message: {
|
|
897
|
+
fontSize: MESSAGE_FONT_SIZE3,
|
|
898
|
+
marginTop: MESSAGE_MARGIN_TOP,
|
|
899
|
+
textAlign: "center"
|
|
900
|
+
}
|
|
901
|
+
});
|
|
902
|
+
var ErrorBoundaryRecovering = ({
|
|
903
|
+
message,
|
|
904
|
+
testID
|
|
905
|
+
}) => {
|
|
906
|
+
const { theme } = useFeedbackUi();
|
|
907
|
+
return /* @__PURE__ */ jsxs(
|
|
908
|
+
View,
|
|
909
|
+
{
|
|
910
|
+
accessibilityLiveRegion: "polite",
|
|
911
|
+
role: "status",
|
|
912
|
+
style: [styles9.container, { backgroundColor: theme.colors.background }],
|
|
913
|
+
testID,
|
|
914
|
+
children: [
|
|
915
|
+
/* @__PURE__ */ jsx(ActivityIndicator, { color: theme.palette.primary["500"], size: "large" }),
|
|
916
|
+
/* @__PURE__ */ jsx(Text, { style: [styles9.message, { color: theme.colors.textSecondary }], children: message })
|
|
917
|
+
]
|
|
918
|
+
}
|
|
919
|
+
);
|
|
920
|
+
};
|
|
921
|
+
|
|
922
|
+
// src/AppErrorBoundary/labels.ts
|
|
923
|
+
var DEFAULT_ERROR_BOUNDARY_LABELS = {
|
|
924
|
+
title: "Something went wrong",
|
|
925
|
+
message: "An unexpected error occurred. Please try again.",
|
|
926
|
+
tryAgain: "Try again",
|
|
927
|
+
tryAgainHint: "Retries rendering this screen",
|
|
928
|
+
reload: "Reload",
|
|
929
|
+
reloadHint: "Reloads the application",
|
|
930
|
+
updating: "Updating\u2026",
|
|
931
|
+
errorDetails: "Error details"
|
|
932
|
+
};
|
|
933
|
+
|
|
934
|
+
// src/AppErrorBoundary/resolve.ts
|
|
935
|
+
function resolveLabels(labels, labelsFor, error) {
|
|
936
|
+
const perError = typeof labelsFor === "function" && error !== null ? labelsFor(error) : {};
|
|
937
|
+
return { ...DEFAULT_ERROR_BOUNDARY_LABELS, ...labels, ...perError };
|
|
938
|
+
}
|
|
939
|
+
function resolveShowDetails(showDetails, error) {
|
|
940
|
+
if (typeof showDetails === "function") return error !== null && showDetails(error);
|
|
941
|
+
return showDetails === true;
|
|
942
|
+
}
|
|
943
|
+
function resolveRetryable(retryable, error) {
|
|
944
|
+
if (typeof retryable !== "function" || error === null) return true;
|
|
945
|
+
return retryable(error);
|
|
946
|
+
}
|
|
947
|
+
var INITIAL_STATE = { hasError: false, error: null, recovering: false };
|
|
948
|
+
var AppErrorBoundary = class extends Component {
|
|
949
|
+
constructor(props) {
|
|
950
|
+
super(props);
|
|
951
|
+
this.handleRetry = () => {
|
|
952
|
+
this.setState(INITIAL_STATE);
|
|
953
|
+
};
|
|
954
|
+
this.state = INITIAL_STATE;
|
|
955
|
+
}
|
|
956
|
+
static getDerivedStateFromError(error) {
|
|
957
|
+
return { hasError: true, error };
|
|
958
|
+
}
|
|
959
|
+
componentDidMount() {
|
|
960
|
+
const isCleanMount = !this.state.hasError;
|
|
961
|
+
if (isCleanMount && typeof this.props.onMount === "function") this.props.onMount();
|
|
962
|
+
}
|
|
963
|
+
componentDidCatch(error, info) {
|
|
964
|
+
if (typeof this.props.onError === "function") this.props.onError(error, info);
|
|
965
|
+
const isHandled = typeof this.props.recover === "function" && this.props.recover(error);
|
|
966
|
+
if (isHandled) this.setState({ recovering: true });
|
|
967
|
+
}
|
|
968
|
+
render() {
|
|
969
|
+
const { children, fallback, labels, labelsFor, showDetails, onReload } = this.props;
|
|
970
|
+
const { hasError, error, recovering } = this.state;
|
|
971
|
+
const testIDPrefix = this.props.testIDPrefix ?? FEEDBACK_TEST_IDS.errorBoundary;
|
|
972
|
+
const resolvedLabels = resolveLabels(labels, labelsFor, error);
|
|
973
|
+
if (!hasError) return children;
|
|
974
|
+
if (typeof fallback === "function") return fallback({ error, recovering, retry: this.handleRetry });
|
|
975
|
+
if (recovering)
|
|
976
|
+
return /* @__PURE__ */ jsx(ErrorBoundaryRecovering, { message: resolvedLabels.updating, testID: `${testIDPrefix}-updating` });
|
|
977
|
+
return /* @__PURE__ */ jsx(
|
|
978
|
+
ErrorBoundaryFallback,
|
|
979
|
+
{
|
|
980
|
+
error,
|
|
981
|
+
labels: resolvedLabels,
|
|
982
|
+
reloadIsPrimary: this.props.reloadIsPrimary === true,
|
|
983
|
+
showDetails: resolveShowDetails(showDetails, error),
|
|
984
|
+
showRetry: resolveRetryable(this.props.retryable, error),
|
|
985
|
+
testIDPrefix,
|
|
986
|
+
onReload,
|
|
987
|
+
onRetry: this.handleRetry
|
|
988
|
+
}
|
|
989
|
+
);
|
|
990
|
+
}
|
|
991
|
+
};
|
|
992
|
+
|
|
993
|
+
export { AppErrorBoundary, ConfirmDialog, DEFAULT_ERROR_BOUNDARY_LABELS, DISABLED_OPACITY, EmptyListState, ErrorState, FEEDBACK_TEST_IDS, FeedbackUiProvider, LoadingFallback, MODAL_OVERLAY_COLOR, PageSkeleton, ToastHost, FeedbackUiProvider as UiProvider, WARMING_QUIET_PERIOD_MS, WarmingOverlay, createToastBus, getWarmingSnapshot, notifyWarming, settleWarming, subscribeWarming, useFeedbackUi, useFeedbackUi as useUi };
|
|
731
994
|
//# sourceMappingURL=index.mjs.map
|
|
732
995
|
//# sourceMappingURL=index.mjs.map
|