@edx/frontend-platform 3.4.0 → 3.4.1
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/package.json +1 -1
- package/react/hooks.js +12 -4
- package/react/hooks.js.map +1 -1
package/package.json
CHANGED
package/react/hooks.js
CHANGED
|
@@ -30,6 +30,8 @@ export var useAppEvent = function useAppEvent(type, callback) {
|
|
|
30
30
|
|
|
31
31
|
export var useTrackColorSchemeChoice = function useTrackColorSchemeChoice() {
|
|
32
32
|
useEffect(function () {
|
|
33
|
+
var _window$matchMedia, _window;
|
|
34
|
+
|
|
33
35
|
var trackColorSchemeChoice = function trackColorSchemeChoice(_ref) {
|
|
34
36
|
var matches = _ref.matches;
|
|
35
37
|
var preferredColorScheme = matches ? 'dark' : 'light';
|
|
@@ -38,12 +40,18 @@ export var useTrackColorSchemeChoice = function useTrackColorSchemeChoice() {
|
|
|
38
40
|
});
|
|
39
41
|
};
|
|
40
42
|
|
|
41
|
-
var colorSchemeQuery = window.matchMedia('(prefers-color-scheme: dark)');
|
|
43
|
+
var colorSchemeQuery = (_window$matchMedia = (_window = window).matchMedia) === null || _window$matchMedia === void 0 ? void 0 : _window$matchMedia.call(_window, '(prefers-color-scheme: dark)');
|
|
44
|
+
|
|
45
|
+
if (colorSchemeQuery) {
|
|
46
|
+
// send user's initial choice
|
|
47
|
+
trackColorSchemeChoice(colorSchemeQuery);
|
|
48
|
+
colorSchemeQuery.addEventListener('change', trackColorSchemeChoice);
|
|
49
|
+
}
|
|
42
50
|
|
|
43
|
-
trackColorSchemeChoice(colorSchemeQuery);
|
|
44
|
-
colorSchemeQuery.addEventListener('change', trackColorSchemeChoice);
|
|
45
51
|
return function () {
|
|
46
|
-
|
|
52
|
+
if (colorSchemeQuery) {
|
|
53
|
+
colorSchemeQuery.removeEventListener('change', trackColorSchemeChoice);
|
|
54
|
+
}
|
|
47
55
|
};
|
|
48
56
|
}, []);
|
|
49
57
|
};
|
package/react/hooks.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","names":["useEffect","subscribe","unsubscribe","sendTrackEvent","useAppEvent","type","callback","subscriptionToken","cleanup","useTrackColorSchemeChoice","trackColorSchemeChoice","matches","preferredColorScheme","colorSchemeQuery","window","matchMedia","addEventListener","removeEventListener"],"sources":["../../src/react/hooks.js"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\nimport { useEffect } from 'react';\nimport { subscribe, unsubscribe } from '../pubSub';\nimport { sendTrackEvent } from '../analytics';\n\n/**\n * A React hook that allows functional components to subscribe to application events. This should\n * be used sparingly - for the most part, Context should be used higher-up in the application to\n * provide necessary data to a given component, rather than utilizing a non-React-like Pub/Sub\n * mechanism.\n *\n * @memberof module:React\n * @param {string} type\n * @param {function} callback\n */\nexport const useAppEvent = (type, callback) => {\n useEffect(() => {\n const subscriptionToken = subscribe(type, callback);\n\n return function cleanup() {\n unsubscribe(subscriptionToken);\n };\n }, [callback, type]);\n};\n\n/**\n * A React hook that tracks user's preferred color scheme (light or dark) and sends respective\n * event to the tracking service.\n *\n * @memberof module:React\n */\nexport const useTrackColorSchemeChoice = () => {\n useEffect(() => {\n const trackColorSchemeChoice = ({ matches }) => {\n const preferredColorScheme = matches ? 'dark' : 'light';\n
|
|
1
|
+
{"version":3,"file":"hooks.js","names":["useEffect","subscribe","unsubscribe","sendTrackEvent","useAppEvent","type","callback","subscriptionToken","cleanup","useTrackColorSchemeChoice","trackColorSchemeChoice","matches","preferredColorScheme","colorSchemeQuery","window","matchMedia","addEventListener","removeEventListener"],"sources":["../../src/react/hooks.js"],"sourcesContent":["/* eslint-disable import/prefer-default-export */\nimport { useEffect } from 'react';\nimport { subscribe, unsubscribe } from '../pubSub';\nimport { sendTrackEvent } from '../analytics';\n\n/**\n * A React hook that allows functional components to subscribe to application events. This should\n * be used sparingly - for the most part, Context should be used higher-up in the application to\n * provide necessary data to a given component, rather than utilizing a non-React-like Pub/Sub\n * mechanism.\n *\n * @memberof module:React\n * @param {string} type\n * @param {function} callback\n */\nexport const useAppEvent = (type, callback) => {\n useEffect(() => {\n const subscriptionToken = subscribe(type, callback);\n\n return function cleanup() {\n unsubscribe(subscriptionToken);\n };\n }, [callback, type]);\n};\n\n/**\n * A React hook that tracks user's preferred color scheme (light or dark) and sends respective\n * event to the tracking service.\n *\n * @memberof module:React\n */\nexport const useTrackColorSchemeChoice = () => {\n useEffect(() => {\n const trackColorSchemeChoice = ({ matches }) => {\n const preferredColorScheme = matches ? 'dark' : 'light';\n sendTrackEvent('openedx.ui.frontend-platform.prefers-color-scheme.selected', { preferredColorScheme });\n };\n const colorSchemeQuery = window.matchMedia?.('(prefers-color-scheme: dark)');\n if (colorSchemeQuery) {\n // send user's initial choice\n trackColorSchemeChoice(colorSchemeQuery);\n colorSchemeQuery.addEventListener('change', trackColorSchemeChoice);\n }\n return () => {\n if (colorSchemeQuery) {\n colorSchemeQuery.removeEventListener('change', trackColorSchemeChoice);\n }\n };\n }, []);\n};\n"],"mappings":"AAAA;AACA,SAASA,SAAT,QAA0B,OAA1B;AACA,SAASC,SAAT,EAAoBC,WAApB,QAAuC,WAAvC;AACA,SAASC,cAAT,QAA+B,cAA/B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMC,WAAW,GAAG,SAAdA,WAAc,CAACC,IAAD,EAAOC,QAAP,EAAoB;EAC7CN,SAAS,CAAC,YAAM;IACd,IAAMO,iBAAiB,GAAGN,SAAS,CAACI,IAAD,EAAOC,QAAP,CAAnC;IAEA,OAAO,SAASE,OAAT,GAAmB;MACxBN,WAAW,CAACK,iBAAD,CAAX;IACD,CAFD;EAGD,CANQ,EAMN,CAACD,QAAD,EAAWD,IAAX,CANM,CAAT;AAOD,CARM;AAUP;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,IAAMI,yBAAyB,GAAG,SAA5BA,yBAA4B,GAAM;EAC7CT,SAAS,CAAC,YAAM;IAAA;;IACd,IAA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