@planningcenter/topbar 11.0.1 → 11.0.2
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/topbar.js +75 -20
- package/dist/topbar.js.map +1 -1
- package/dist/topbar.modern.js +76 -21
- package/dist/topbar.modern.js.map +1 -1
- package/dist/topbar.module.js +76 -21
- package/dist/topbar.module.js.map +1 -1
- package/dist/topbar.umd.js +75 -20
- package/dist/topbar.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/topbar.module.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Link } from '@planningcenter/tapestry';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import React__default, { useState, useEffect, useMemo, useCallback, useRef } from 'react';
|
|
3
|
+
import React__default, { useState, useEffect, useMemo, useLayoutEffect, useCallback, useRef } from 'react';
|
|
4
4
|
import pcoUrl from '@planningcenter/url';
|
|
5
5
|
import * as general from '@planningcenter/icons/paths/general';
|
|
6
6
|
import Jolt from '@planningcenter/jolt-client';
|
|
@@ -675,6 +675,13 @@ const useJoltEffect = (channelSubscription, eventName, callback) => {
|
|
|
675
675
|
};
|
|
676
676
|
|
|
677
677
|
const capitalize = s => s.charAt(0).toUpperCase() + s.slice(1);
|
|
678
|
+
const RESOLVED_COLOR_MODE_ATTRIBUTE = "data-resolved-color-mode";
|
|
679
|
+
function resolveColorMode(colorMode) {
|
|
680
|
+
if (colorMode === "system") {
|
|
681
|
+
return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light";
|
|
682
|
+
}
|
|
683
|
+
return colorMode;
|
|
684
|
+
}
|
|
678
685
|
const debounce = (func, wait) => {
|
|
679
686
|
let timeout;
|
|
680
687
|
return function (...args) {
|
|
@@ -755,6 +762,58 @@ const useNotificationsHasUnread = ({
|
|
|
755
762
|
return storedValue;
|
|
756
763
|
};
|
|
757
764
|
|
|
765
|
+
function useMediaQuery(query) {
|
|
766
|
+
const getMatches = query => {
|
|
767
|
+
// Prevents SSR issues
|
|
768
|
+
if (typeof window !== "undefined") {
|
|
769
|
+
return window.matchMedia(query).matches;
|
|
770
|
+
}
|
|
771
|
+
return false;
|
|
772
|
+
};
|
|
773
|
+
const [matches, setMatches] = useState(getMatches(query));
|
|
774
|
+
function handleChange() {
|
|
775
|
+
setMatches(getMatches(query));
|
|
776
|
+
}
|
|
777
|
+
useEffect(() => {
|
|
778
|
+
const matchMedia = window.matchMedia(query);
|
|
779
|
+
// Triggered at the first client-side load and if query changes
|
|
780
|
+
handleChange();
|
|
781
|
+
// Listen matchMedia
|
|
782
|
+
if (matchMedia.addListener) {
|
|
783
|
+
matchMedia.addListener(handleChange);
|
|
784
|
+
} else {
|
|
785
|
+
matchMedia.addEventListener("change", handleChange);
|
|
786
|
+
}
|
|
787
|
+
return () => {
|
|
788
|
+
if (matchMedia.removeListener) {
|
|
789
|
+
matchMedia.removeListener(handleChange);
|
|
790
|
+
} else {
|
|
791
|
+
matchMedia.removeEventListener("change", handleChange);
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
}, [query]);
|
|
795
|
+
return matches;
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
function createStore(initialState) {
|
|
799
|
+
let currentState = initialState;
|
|
800
|
+
const listeners = new Set();
|
|
801
|
+
return {
|
|
802
|
+
getState: () => currentState,
|
|
803
|
+
setState: newState => {
|
|
804
|
+
currentState = newState;
|
|
805
|
+
listeners.forEach(listener => listener(currentState));
|
|
806
|
+
},
|
|
807
|
+
subscribe: listener => {
|
|
808
|
+
listeners.add(listener);
|
|
809
|
+
return () => listeners.delete(listener);
|
|
810
|
+
}
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
const store$1 = createStore({});
|
|
814
|
+
|
|
815
|
+
const useStore = (selector = state => state) => useSyncExternalStore(store$1.subscribe, () => selector(store$1.getState()));
|
|
816
|
+
|
|
758
817
|
const useTopbarAPI = ({
|
|
759
818
|
configuredFetch,
|
|
760
819
|
env
|
|
@@ -781,23 +840,6 @@ const useTopbarAPI = ({
|
|
|
781
840
|
return resp;
|
|
782
841
|
};
|
|
783
842
|
|
|
784
|
-
function createStore(initialState) {
|
|
785
|
-
let currentState = initialState;
|
|
786
|
-
const listeners = new Set();
|
|
787
|
-
return {
|
|
788
|
-
getState: () => currentState,
|
|
789
|
-
setState: newState => {
|
|
790
|
-
currentState = newState;
|
|
791
|
-
listeners.forEach(listener => listener(currentState));
|
|
792
|
-
},
|
|
793
|
-
subscribe: listener => {
|
|
794
|
-
listeners.add(listener);
|
|
795
|
-
return () => listeners.delete(listener);
|
|
796
|
-
}
|
|
797
|
-
};
|
|
798
|
-
}
|
|
799
|
-
const store$1 = createStore({});
|
|
800
|
-
|
|
801
843
|
const AppsProvider = ({
|
|
802
844
|
configuredFetch = defaultFetch,
|
|
803
845
|
enableJoltLogging,
|
|
@@ -817,6 +859,10 @@ const AppsProvider = ({
|
|
|
817
859
|
const hasConnectedPeople = (_b = (_a = topbarResponse === null || topbarResponse === void 0 ? void 0 : topbarResponse.data) === null || _a === void 0 ? void 0 : _a.attributes) === null || _b === void 0 ? void 0 : _b.has_connected_people;
|
|
818
860
|
const mfaConfigured = !!((_d = (_c = topbarResponse === null || topbarResponse === void 0 ? void 0 : topbarResponse.data) === null || _c === void 0 ? void 0 : _c.attributes) === null || _d === void 0 ? void 0 : _d.mfa_configured);
|
|
819
861
|
const colorMode = (_f = (_e = topbarResponse === null || topbarResponse === void 0 ? void 0 : topbarResponse.data) === null || _e === void 0 ? void 0 : _e.attributes) === null || _f === void 0 ? void 0 : _f.color_mode;
|
|
862
|
+
const {
|
|
863
|
+
colorMode: currentColorMode
|
|
864
|
+
} = useStore();
|
|
865
|
+
const prefersDark = useMediaQuery("(prefers-color-scheme: dark)");
|
|
820
866
|
const name = (_h = (_g = topbarResponse === null || topbarResponse === void 0 ? void 0 : topbarResponse.data) === null || _g === void 0 ? void 0 : _g.attributes) === null || _h === void 0 ? void 0 : _h.name;
|
|
821
867
|
const notificationsEnabled = !window.notificationsDisabled;
|
|
822
868
|
const organizationTimeZone = ((_k = (_j = topbarResponse === null || topbarResponse === void 0 ? void 0 : topbarResponse.data) === null || _j === void 0 ? void 0 : _j.attributes) === null || _k === void 0 ? void 0 : _k.org_time_zone) || "America/Los_Angeles";
|
|
@@ -868,6 +914,16 @@ const AppsProvider = ({
|
|
|
868
914
|
enabled: true,
|
|
869
915
|
joltChannel: notificationsJoltChannel
|
|
870
916
|
});
|
|
917
|
+
useLayoutEffect(() => {
|
|
918
|
+
if (colorMode) {
|
|
919
|
+
document.documentElement.setAttribute(RESOLVED_COLOR_MODE_ATTRIBUTE, resolveColorMode(colorMode));
|
|
920
|
+
}
|
|
921
|
+
}, [colorMode]);
|
|
922
|
+
useEffect(() => {
|
|
923
|
+
if (currentColorMode === "system") {
|
|
924
|
+
document.documentElement.setAttribute(RESOLVED_COLOR_MODE_ATTRIBUTE, prefersDark ? "dark" : "light");
|
|
925
|
+
}
|
|
926
|
+
}, [currentColorMode, prefersDark]);
|
|
871
927
|
useEffect(() => {
|
|
872
928
|
const state = store$1.getState();
|
|
873
929
|
store$1.setState({
|
|
@@ -2036,8 +2092,6 @@ const useSetCurrentRouteInfo = ({
|
|
|
2036
2092
|
}, [routes, app]);
|
|
2037
2093
|
};
|
|
2038
2094
|
|
|
2039
|
-
const useStore = (selector = state => state) => useSyncExternalStore(store$1.subscribe, () => selector(store$1.getState()));
|
|
2040
|
-
|
|
2041
2095
|
const useUpdateStore = () => useCallback(updates => {
|
|
2042
2096
|
const currentState = store$1.getState();
|
|
2043
2097
|
store$1.setState({
|
|
@@ -2945,6 +2999,7 @@ function ColorModeSwitcher() {
|
|
|
2945
2999
|
colorMode
|
|
2946
3000
|
});
|
|
2947
3001
|
document.documentElement.setAttribute("data-color-mode", colorMode);
|
|
3002
|
+
document.documentElement.setAttribute(RESOLVED_COLOR_MODE_ATTRIBUTE, resolveColorMode(colorMode));
|
|
2948
3003
|
updateColorMode(colorMode);
|
|
2949
3004
|
}
|
|
2950
3005
|
}), /*#__PURE__*/React__default.createElement(ColorModeIcon, {
|
|
@@ -4379,7 +4434,7 @@ function Toolbar({
|
|
|
4379
4434
|
document.body.style.overflow = "hidden";
|
|
4380
4435
|
window.scrollTo(0, 0);
|
|
4381
4436
|
} else {
|
|
4382
|
-
document.body.style.overflow = "
|
|
4437
|
+
document.body.style.overflow = "";
|
|
4383
4438
|
}
|
|
4384
4439
|
}, [open]);
|
|
4385
4440
|
// Listen for external close requests from store
|