@dloizides/ui-layout 1.25.0 → 1.26.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.mjs CHANGED
@@ -39,7 +39,9 @@ var LAYOUT_TEST_IDS = {
39
39
  modal: "modal",
40
40
  /** Default base testID for `ConfirmDialog`; Confirm/Cancel are `confirm-dialog-{confirm,cancel}`. */
41
41
  confirmDialog: "confirm-dialog",
42
- accordion: "accordion"
42
+ accordion: "accordion",
43
+ /** Default testID for the `BuildInfoFooter` caption (`v<version>`). */
44
+ buildInfoFooter: "build-info-footer"
43
45
  };
44
46
  var DEFAULT_BILLING_ROUTE = "/settings/billing";
45
47
  var LAYOUT_I18N = {
@@ -93,7 +95,9 @@ var LAYOUT_I18N = {
93
95
  */
94
96
  copyFailed: "common.copyFailed",
95
97
  /** `CopyableId`: hint on the value itself, explaining it is shortened for display. */
96
- copyableIdHint: "common.copyableIdHint"
98
+ copyableIdHint: "common.copyableIdHint",
99
+ /** `BuildInfoFooter`: accessible hint on the version caption (the visible `v<version>` is the label). */
100
+ buildInfoHint: "common.buildInfoHint"
97
101
  };
98
102
  var styles2 = StyleSheet.create({
99
103
  heading: {
@@ -1961,6 +1965,94 @@ var CopyableId = ({
1961
1965
  ] });
1962
1966
  };
1963
1967
 
1964
- export { Accordion, AccordionItem, COPY_FEEDBACK_MS, ConfirmDialog, CopyStatus, CopyableId, DEFAULT_BILLING_ROUTE, DropdownVariant, ELLIPSIS, Heading, LAYOUT_I18N, LAYOUT_TEST_IDS, Modal3 as Modal, ModalDropdown, ModalShell, Section, SegmentedControl, StatusBadge, Tabs, TabsCollapsedTrigger, TruncatedText, UpgradePrompt, copyText, formatUrlForDisplay, truncateMiddle, useCopyToClipboard, useFocusTrap };
1968
+ // src/BuildInfoFooter/formatBuildInfo.ts
1969
+ var BUILD_INFO_PREFIX = "v";
1970
+ var API_COMMIT_SEPARATOR = " \xB7 api ";
1971
+ var SHORT_COMMIT_LENGTH = 7;
1972
+ function shortenCommit(commit) {
1973
+ return commit.trim().slice(0, SHORT_COMMIT_LENGTH);
1974
+ }
1975
+ function trimTrailingSlash(url) {
1976
+ return url.endsWith("/") ? url.slice(0, -1) : url;
1977
+ }
1978
+ function formatBuildInfo(buildVersion, apiCommit) {
1979
+ const base = `${BUILD_INFO_PREFIX}${buildVersion.trim()}`;
1980
+ const commit = apiCommit?.trim();
1981
+ if (commit === void 0 || commit === "") return base;
1982
+ return `${base}${API_COMMIT_SEPARATOR}${shortenCommit(commit)}`;
1983
+ }
1984
+ function useApiCommit(apiBaseUrl, fetchImpl) {
1985
+ const [commit, setCommit] = useState(void 0);
1986
+ const mountedRef = useRef(true);
1987
+ useEffect(() => {
1988
+ mountedRef.current = true;
1989
+ return () => {
1990
+ mountedRef.current = false;
1991
+ };
1992
+ }, []);
1993
+ useEffect(() => {
1994
+ if (apiBaseUrl === void 0 || apiBaseUrl === "") return;
1995
+ const doFetch = fetchImpl ?? (typeof fetch !== "undefined" ? fetch : void 0);
1996
+ if (doFetch === void 0) return;
1997
+ void (async () => {
1998
+ try {
1999
+ const res = await doFetch(`${trimTrailingSlash(apiBaseUrl)}/version`);
2000
+ if (!res.ok) return;
2001
+ const body = await res.json();
2002
+ const value = body.commit;
2003
+ if (mountedRef.current && value !== void 0 && value !== "") setCommit(value);
2004
+ } catch {
2005
+ return;
2006
+ }
2007
+ })();
2008
+ }, [apiBaseUrl, fetchImpl]);
2009
+ return commit;
2010
+ }
2011
+ var FOOTER_PADDING_V = 6;
2012
+ var FOOTER_PADDING_H = 12;
2013
+ var FOOTER_FONT_SIZE = 11;
2014
+ var FOOTER_OPACITY = 0.75;
2015
+ var styles17 = StyleSheet.create({
2016
+ footer: {
2017
+ paddingVertical: FOOTER_PADDING_V,
2018
+ paddingHorizontal: FOOTER_PADDING_H,
2019
+ alignItems: "center"
2020
+ },
2021
+ text: {
2022
+ fontSize: FOOTER_FONT_SIZE,
2023
+ opacity: FOOTER_OPACITY
2024
+ }
2025
+ });
2026
+ var BuildInfoFooter = ({
2027
+ buildVersion,
2028
+ apiBaseUrl,
2029
+ apiCommit,
2030
+ fetchImpl,
2031
+ testID = LAYOUT_TEST_IDS.buildInfoFooter,
2032
+ accessibilityLabel,
2033
+ accessibilityHint,
2034
+ style
2035
+ }) => {
2036
+ const { theme, t } = useUi();
2037
+ const fetchedCommit = useApiCommit(apiCommit === void 0 ? apiBaseUrl : void 0, fetchImpl);
2038
+ const commit = apiCommit ?? fetchedCommit;
2039
+ const label = formatBuildInfo(buildVersion, commit);
2040
+ const textStyle = useMemo(
2041
+ () => [styles17.text, { color: theme.colors.textSecondary }],
2042
+ [theme.colors.textSecondary]
2043
+ );
2044
+ return /* @__PURE__ */ jsx(
2045
+ View,
2046
+ {
2047
+ accessibilityLabel: accessibilityLabel ?? label,
2048
+ accessibilityHint: accessibilityHint ?? t(LAYOUT_I18N.buildInfoHint),
2049
+ style: [styles17.footer, style],
2050
+ testID,
2051
+ children: /* @__PURE__ */ jsx(Text, { style: textStyle, children: label })
2052
+ }
2053
+ );
2054
+ };
2055
+
2056
+ export { API_COMMIT_SEPARATOR, Accordion, AccordionItem, BUILD_INFO_PREFIX, BuildInfoFooter, COPY_FEEDBACK_MS, ConfirmDialog, CopyStatus, CopyableId, DEFAULT_BILLING_ROUTE, DropdownVariant, ELLIPSIS, Heading, LAYOUT_I18N, LAYOUT_TEST_IDS, Modal3 as Modal, ModalDropdown, ModalShell, Section, SegmentedControl, StatusBadge, Tabs, TabsCollapsedTrigger, TruncatedText, UpgradePrompt, copyText, formatBuildInfo, formatUrlForDisplay, shortenCommit, trimTrailingSlash, truncateMiddle, useApiCommit, useCopyToClipboard, useFocusTrap };
1965
2057
  //# sourceMappingURL=index.mjs.map
1966
2058
  //# sourceMappingURL=index.mjs.map