@bigbinary/neeto-commons-frontend 3.2.0 → 3.2.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.
|
@@ -6,7 +6,14 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.isMetaKeyPressed = exports.handleMetaClick = void 0;
|
|
7
7
|
var _ramda = require("ramda");
|
|
8
8
|
var handleMetaClick = (0, _ramda.curry)(function (history, params, event) {
|
|
9
|
-
|
|
9
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
10
|
+
if (isMetaKeyPressed(event)) {
|
|
11
|
+
return window.open(params.pathname || params, "_blank");
|
|
12
|
+
}
|
|
13
|
+
var _options$isHistoryRep = options.isHistoryReplace,
|
|
14
|
+
isHistoryReplace = _options$isHistoryRep === void 0 ? false : _options$isHistoryRep;
|
|
15
|
+
var historyMethod = isHistoryReplace ? history.replace : history.push;
|
|
16
|
+
return historyMethod(params);
|
|
10
17
|
});
|
|
11
18
|
exports.handleMetaClick = handleMetaClick;
|
|
12
19
|
var isMetaKeyPressed = function isMetaKeyPressed(event) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metaClick.js","names":["_ramda","require","handleMetaClick","curry","history","params","event","isMetaKeyPressed","window","open","pathname","push","exports","ctrlKey","metaKey"],"sources":["../../../../src/react-utils/metaClick/metaClick.js"],"sourcesContent":["import { curry } from \"ramda\";\n\nexport const handleMetaClick = curry((history, params, event)
|
|
1
|
+
{"version":3,"file":"metaClick.js","names":["_ramda","require","handleMetaClick","curry","history","params","event","options","arguments","length","undefined","isMetaKeyPressed","window","open","pathname","_options$isHistoryRep","isHistoryReplace","historyMethod","replace","push","exports","ctrlKey","metaKey"],"sources":["../../../../src/react-utils/metaClick/metaClick.js"],"sourcesContent":["import { curry } from \"ramda\";\n\nexport const handleMetaClick = curry((history, params, event, options = {}) => {\n if (isMetaKeyPressed(event)) {\n return window.open(params.pathname || params, \"_blank\");\n }\n\n const { isHistoryReplace = false } = options;\n const historyMethod = isHistoryReplace ? history.replace : history.push;\n\n return historyMethod(params);\n});\n\nexport const isMetaKeyPressed = event => !!(event?.ctrlKey || event?.metaKey);\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEO,IAAMC,eAAe,GAAG,IAAAC,YAAK,EAAC,UAACC,OAAO,EAAEC,MAAM,EAAEC,KAAK,EAAmB;EAAA,IAAjBC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EACxE,IAAIG,gBAAgB,CAACL,KAAK,CAAC,EAAE;IAC3B,OAAOM,MAAM,CAACC,IAAI,CAACR,MAAM,CAACS,QAAQ,IAAIT,MAAM,EAAE,QAAQ,CAAC;EACzD;EAEA,IAAAU,qBAAA,GAAqCR,OAAO,CAApCS,gBAAgB;IAAhBA,gBAAgB,GAAAD,qBAAA,cAAG,KAAK,GAAAA,qBAAA;EAChC,IAAME,aAAa,GAAGD,gBAAgB,GAAGZ,OAAO,CAACc,OAAO,GAAGd,OAAO,CAACe,IAAI;EAEvE,OAAOF,aAAa,CAACZ,MAAM,CAAC;AAC9B,CAAC,CAAC;AAACe,OAAA,CAAAlB,eAAA,GAAAA,eAAA;AAEI,IAAMS,gBAAgB,GAAG,SAAnBA,gBAAgBA,CAAGL,KAAK;EAAA,OAAI,CAAC,EAAEA,KAAK,aAALA,KAAK,eAALA,KAAK,CAAEe,OAAO,IAAIf,KAAK,aAALA,KAAK,eAALA,KAAK,CAAEgB,OAAO,CAAC;AAAA;AAACF,OAAA,CAAAT,gBAAA,GAAAA,gBAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bigbinary/neeto-commons-frontend",
|
|
3
|
-
"version": "3.2.
|
|
3
|
+
"version": "3.2.1",
|
|
4
4
|
"description": "A package encapsulating common code across neeto projects including initializers, utility functions, common components and hooks and so on.",
|
|
5
5
|
"repository": "git@github.com:bigbinary/neeto-commons-frontend.git",
|
|
6
6
|
"author": "Amaljith K <amaljith.k@bigbinary.com>",
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import { curry } from "ramda";
|
|
2
2
|
export var handleMetaClick = curry(function (history, params, event) {
|
|
3
|
-
|
|
3
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
4
|
+
if (isMetaKeyPressed(event)) {
|
|
5
|
+
return window.open(params.pathname || params, "_blank");
|
|
6
|
+
}
|
|
7
|
+
var _options$isHistoryRep = options.isHistoryReplace,
|
|
8
|
+
isHistoryReplace = _options$isHistoryRep === void 0 ? false : _options$isHistoryRep;
|
|
9
|
+
var historyMethod = isHistoryReplace ? history.replace : history.push;
|
|
10
|
+
return historyMethod(params);
|
|
4
11
|
});
|
|
5
12
|
export var isMetaKeyPressed = function isMetaKeyPressed(event) {
|
|
6
13
|
return !!(event !== null && event !== void 0 && event.ctrlKey || event !== null && event !== void 0 && event.metaKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metaClick.js","names":["curry","handleMetaClick","history","params","event","isMetaKeyPressed","window","open","pathname","push","ctrlKey","metaKey"],"sources":["../../../src/react-utils/metaClick/metaClick.js"],"sourcesContent":["import { curry } from \"ramda\";\n\nexport const handleMetaClick = curry((history, params, event)
|
|
1
|
+
{"version":3,"file":"metaClick.js","names":["curry","handleMetaClick","history","params","event","options","arguments","length","undefined","isMetaKeyPressed","window","open","pathname","_options$isHistoryRep","isHistoryReplace","historyMethod","replace","push","ctrlKey","metaKey"],"sources":["../../../src/react-utils/metaClick/metaClick.js"],"sourcesContent":["import { curry } from \"ramda\";\n\nexport const handleMetaClick = curry((history, params, event, options = {}) => {\n if (isMetaKeyPressed(event)) {\n return window.open(params.pathname || params, \"_blank\");\n }\n\n const { isHistoryReplace = false } = options;\n const historyMethod = isHistoryReplace ? history.replace : history.push;\n\n return historyMethod(params);\n});\n\nexport const isMetaKeyPressed = event => !!(event?.ctrlKey || event?.metaKey);\n"],"mappings":"AAAA,SAASA,KAAK,QAAQ,OAAO;AAE7B,OAAO,IAAMC,eAAe,GAAGD,KAAK,CAAC,UAACE,OAAO,EAAEC,MAAM,EAAEC,KAAK,EAAmB;EAAA,IAAjBC,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EACxE,IAAIG,gBAAgB,CAACL,KAAK,CAAC,EAAE;IAC3B,OAAOM,MAAM,CAACC,IAAI,CAACR,MAAM,CAACS,QAAQ,IAAIT,MAAM,EAAE,QAAQ,CAAC;EACzD;EAEA,IAAAU,qBAAA,GAAqCR,OAAO,CAApCS,gBAAgB;IAAhBA,gBAAgB,GAAAD,qBAAA,cAAG,KAAK,GAAAA,qBAAA;EAChC,IAAME,aAAa,GAAGD,gBAAgB,GAAGZ,OAAO,CAACc,OAAO,GAAGd,OAAO,CAACe,IAAI;EAEvE,OAAOF,aAAa,CAACZ,MAAM,CAAC;AAC9B,CAAC,CAAC;AAEF,OAAO,IAAMM,gBAAgB,GAAG,SAAnBA,gBAAgBA,CAAGL,KAAK;EAAA,OAAI,CAAC,EAAEA,KAAK,aAALA,KAAK,eAALA,KAAK,CAAEc,OAAO,IAAId,KAAK,aAALA,KAAK,eAALA,KAAK,CAAEe,OAAO,CAAC;AAAA"}
|
package/react-utils.d.ts
CHANGED
|
@@ -777,6 +777,57 @@ export async function registerBrowserNotifications(): Promise<void>;
|
|
|
777
777
|
*
|
|
778
778
|
*/
|
|
779
779
|
export async function destroyBrowserSubscription(): Promise<void>;
|
|
780
|
+
type handleMetaClickOptions = {
|
|
781
|
+
isHistoryReplace?: boolean;
|
|
782
|
+
};
|
|
783
|
+
/**
|
|
784
|
+
*
|
|
785
|
+
* The handleMetaClick function can be used to handle onClick actions that
|
|
786
|
+
*
|
|
787
|
+
* redirects to a URL. It opens up the URL in a new tab if ctrl/cmd + click event
|
|
788
|
+
*
|
|
789
|
+
* is received. Otherwise, simply redirects to the provided URL in the same tab.
|
|
790
|
+
*
|
|
791
|
+
* URL can be passed as string or a history location object can be passed instead.
|
|
792
|
+
*
|
|
793
|
+
* Let's say you have a navigation menu with several links, and you want to allow
|
|
794
|
+
*
|
|
795
|
+
* users to open these links in a new tab if they hold down the Ctrl (or Cmd on
|
|
796
|
+
*
|
|
797
|
+
* macOS) key while clicking, and if they click without holding down the Ctrl key,
|
|
798
|
+
*
|
|
799
|
+
* the link should open in the same tab. You can use handleMetaClick to achieve
|
|
800
|
+
*
|
|
801
|
+
* this behavior.
|
|
802
|
+
*
|
|
803
|
+
* @example
|
|
804
|
+
*
|
|
805
|
+
* const NavigationMenu = () => {
|
|
806
|
+
* const history = useHistory();
|
|
807
|
+
*
|
|
808
|
+
* const handleLinkClick = (url, event) => {
|
|
809
|
+
* // Opens url in a new tab if metaKey/CtrlKey is pressed.
|
|
810
|
+
* // Otherwise simply redirects to url.
|
|
811
|
+
* handleMetaClick(history, url, event);
|
|
812
|
+
* };
|
|
813
|
+
*
|
|
814
|
+
* return (
|
|
815
|
+
* <div>
|
|
816
|
+
* <a href="/home" onClick={e => handleLinkClick("/home", e)}>
|
|
817
|
+
* Home
|
|
818
|
+
* </a>
|
|
819
|
+
* <a href="/dashboard" onClick={e => handleLinkClick("/dashboard", e)}>
|
|
820
|
+
* Dashboard
|
|
821
|
+
* </a>
|
|
822
|
+
* <a href="/profile" onClick={e => handleLinkClick("/profile", e)}>
|
|
823
|
+
* Profile
|
|
824
|
+
* </a>
|
|
825
|
+
* </div>
|
|
826
|
+
* );
|
|
827
|
+
* };
|
|
828
|
+
* @endexample
|
|
829
|
+
*/
|
|
830
|
+
export function handleMetaClick(history: History, params: string | object, event: React.MouseEvent<HTMLElement, MouseEvent>, options?: handleMetaClickOptions): void;
|
|
780
831
|
/**
|
|
781
832
|
*
|
|
782
833
|
* The handleMetaClick function can be used to handle onClick actions that
|
|
@@ -824,7 +875,7 @@ export async function destroyBrowserSubscription(): Promise<void>;
|
|
|
824
875
|
* };
|
|
825
876
|
* @endexample
|
|
826
877
|
*/
|
|
827
|
-
export function handleMetaClick(history: History, params: string | object, event: React.MouseEvent<HTMLElement, MouseEvent>): void;
|
|
878
|
+
export function handleMetaClick(history: History, params: string | object, event: React.MouseEvent<HTMLElement, MouseEvent>): (options?: handleMetaClickOptions) => void;
|
|
828
879
|
/**
|
|
829
880
|
*
|
|
830
881
|
* The handleMetaClick function can be used to handle onClick actions that
|
|
@@ -872,7 +923,7 @@ export function handleMetaClick(history: History, params: string | object, event
|
|
|
872
923
|
* };
|
|
873
924
|
* @endexample
|
|
874
925
|
*/
|
|
875
|
-
export function handleMetaClick(history: History, params: string | object): (event: React.MouseEvent<HTMLElement, MouseEvent
|
|
926
|
+
export function handleMetaClick(history: History, params: string | object): (event: React.MouseEvent<HTMLElement, MouseEvent>, options?: handleMetaClickOptions) => void;
|
|
876
927
|
/**
|
|
877
928
|
*
|
|
878
929
|
* The handleMetaClick function can be used to handle onClick actions that
|
|
@@ -920,7 +971,7 @@ export function handleMetaClick(history: History, params: string | object): (eve
|
|
|
920
971
|
* };
|
|
921
972
|
* @endexample
|
|
922
973
|
*/
|
|
923
|
-
export function handleMetaClick(history: History): (params: string | object, event: React.MouseEvent<HTMLElement, MouseEvent
|
|
974
|
+
export function handleMetaClick(history: History): (params: string | object, event: React.MouseEvent<HTMLElement, MouseEvent>, options?: handleMetaClickOptions) => void;
|
|
924
975
|
/**
|
|
925
976
|
*
|
|
926
977
|
* The isMetaKeyPressed function can be used to check whether an onClick event
|