@blaze-cms/react-page-builder 0.146.0-tooltips.0 → 0.146.0-tooltips.3
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 +22 -0
- package/lib/components/MenuItem/MenuItemRender.js +8 -8
- package/lib/components/MenuItem/MenuItemRender.js.map +1 -1
- package/lib/components/MenuItem/helpers/isUrlPathMatch.js +1 -1
- package/lib/components/MenuItem/helpers/isUrlPathMatch.js.map +1 -1
- package/lib-es/components/MenuItem/MenuItemRender.js +5 -5
- package/lib-es/components/MenuItem/MenuItemRender.js.map +1 -1
- package/lib-es/components/MenuItem/helpers/isUrlPathMatch.js +1 -1
- package/lib-es/components/MenuItem/helpers/isUrlPathMatch.js.map +1 -1
- package/package.json +2 -2
- package/src/components/MenuItem/MenuItemRender.js +8 -7
- package/src/components/MenuItem/helpers/isUrlPathMatch.js +1 -1
- package/tests/unit/src/components/MenuItem/helpers/is-url-path-match.test.js +7 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [0.146.0-tooltips.3](https://github.com/thebyte9/blaze/compare/v0.146.0-tooltips.2...v0.146.0-tooltips.3) (2025-02-19)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* extended regex for #s in urls ([#4648](https://github.com/thebyte9/blaze/issues/4648)) ([089b19a](https://github.com/thebyte9/blaze/commit/089b19afaf503477429df3415fcd382e8b55745a))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [0.146.0-tooltips.1](https://github.com/thebyte9/blaze/compare/v0.146.0-tooltips.0...v0.146.0-tooltips.1) (2025-02-06)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Bug Fixes
|
|
21
|
+
|
|
22
|
+
* menu setdisplaychildren logic ([#4629](https://github.com/thebyte9/blaze/issues/4629)) ([16c5c67](https://github.com/thebyte9/blaze/commit/16c5c674f4db1505131a8557d34f5349cf33fc42))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
# [0.146.0-tooltips.0](https://github.com/thebyte9/blaze/compare/v0.145.0...v0.146.0-tooltips.0) (2025-02-06)
|
|
7
29
|
|
|
8
30
|
|
|
@@ -42,12 +42,6 @@ var MenuItemRender = function MenuItemRender(_ref) {
|
|
|
42
42
|
openActiveSubmenus = _useContext.openActiveSubmenus;
|
|
43
43
|
var isHoverEvent = eventType === _constants.HOVER;
|
|
44
44
|
var isClickEvent = eventType === _constants.CLICK;
|
|
45
|
-
var isActiveParent = router ? (0, _helpers2.hasActiveChild)(router.asPath, children) : false;
|
|
46
|
-
var shouldPreOpen = openActiveSubmenus && isActiveParent && isClickEvent;
|
|
47
|
-
var _useState = (0, _react.useState)(shouldPreOpen),
|
|
48
|
-
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
49
|
-
displayChildren = _useState2[0],
|
|
50
|
-
setDisplayChildren = _useState2[1];
|
|
51
45
|
var _useStringTemplate = (0, _utilsHandlebars.useStringTemplate)(parent, [text]),
|
|
52
46
|
loadingText = _useStringTemplate.loading,
|
|
53
47
|
_useStringTemplate$da = (0, _slicedToArray2["default"])(_useStringTemplate.data, 1),
|
|
@@ -56,11 +50,17 @@ var MenuItemRender = function MenuItemRender(_ref) {
|
|
|
56
50
|
loadingUrl = _useStringTemplate2.loading,
|
|
57
51
|
_useStringTemplate2$d = (0, _slicedToArray2["default"])(_useStringTemplate2.data, 1),
|
|
58
52
|
urlToUse = _useStringTemplate2$d[0];
|
|
53
|
+
var isActive = router ? (0, _helpers2.isUrlPathMatch)(router.asPath, urlToUse) : false;
|
|
54
|
+
var isActiveParent = router ? (0, _helpers2.hasActiveChild)(router.asPath, children) : false;
|
|
55
|
+
var shouldPreOpen = openActiveSubmenus && isActiveParent && isClickEvent;
|
|
56
|
+
var _useState = (0, _react.useState)(shouldPreOpen),
|
|
57
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
|
58
|
+
displayChildren = _useState2[0],
|
|
59
|
+
setDisplayChildren = _useState2[1];
|
|
59
60
|
(0, _react.useEffect)(function () {
|
|
60
|
-
if (!showMobileMenu) setDisplayChildren(false);
|
|
61
|
+
if (!showMobileMenu && !shouldPreOpen) setDisplayChildren(false);
|
|
61
62
|
}, [children, isClickEvent, loadingUrl, openActiveSubmenus, router]);
|
|
62
63
|
if (loadingUrl || loadingText) return '';
|
|
63
|
-
var isActive = router ? (0, _helpers2.isUrlPathMatch)(router.asPath, urlToUse) : false;
|
|
64
64
|
var childrenDisplayClass = displayChildren ? '' : _constants.HIDDEN;
|
|
65
65
|
var handleItemEvent = function handleItemEvent(_ref2) {
|
|
66
66
|
var type = _ref2.type;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuItemRender.js","names":["_react","_interopRequireWildcard","require","_propTypes","_interopRequireDefault","_fa","_classnames","_router","_utilsHandlebars","_constants","_helpers","_BlazeLink","_MenuContext","_helpers2","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","_typeof","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","MenuItemRender","_ref","children","eventType","text","modifier","url","parent","router","useRouter","_useContext","useContext","MenuContext","showMobileMenu","openActiveSubmenus","isHoverEvent","HOVER","isClickEvent","CLICK","
|
|
1
|
+
{"version":3,"file":"MenuItemRender.js","names":["_react","_interopRequireWildcard","require","_propTypes","_interopRequireDefault","_fa","_classnames","_router","_utilsHandlebars","_constants","_helpers","_BlazeLink","_MenuContext","_helpers2","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","_typeof","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","prototype","hasOwnProperty","call","i","set","MenuItemRender","_ref","children","eventType","text","modifier","url","parent","router","useRouter","_useContext","useContext","MenuContext","showMobileMenu","openActiveSubmenus","isHoverEvent","HOVER","isClickEvent","CLICK","_useStringTemplate","useStringTemplate","loadingText","loading","_useStringTemplate$da","_slicedToArray2","data","textToUse","_useStringTemplate2","injectHelperIntoTemplate","loadingUrl","_useStringTemplate2$d","urlToUse","isActive","isUrlPathMatch","asPath","isActiveParent","hasActiveChild","shouldPreOpen","_useState","useState","_useState2","displayChildren","setDisplayChildren","useEffect","childrenDisplayClass","HIDDEN","handleItemEvent","_ref2","type","MOUSE_ENTER","MOUSE_LEAVE","hasValidChildren","hasChildren","menuItemLinkClassname","classnames","createElement","className","onMouseEnter","onMouseLeave","href","role","onClick","FaChevronUp","FaChevronDown","concat","propTypes","PropTypes","string","isRequired","object","oneOfType","arrayOf","node","defaultProps","_default","exports"],"sources":["../../../src/components/MenuItem/MenuItemRender.js"],"sourcesContent":["/* eslint-disable no-console */\nimport React, { useState, useContext, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport { FaChevronDown, FaChevronUp } from 'react-icons/fa';\nimport classnames from 'classnames';\nimport { useRouter } from 'next/router';\nimport { useStringTemplate } from '@blaze-cms/utils-handlebars';\nimport { HOVER, MOUSE_ENTER, MOUSE_LEAVE, HIDDEN, CLICK } from '../../constants';\nimport { hasChildren } from '../../helpers';\nimport BlazeLink from '../BlazeLink';\nimport MenuContext from '../Menu/MenuContext';\nimport { injectHelperIntoTemplate, isUrlPathMatch, hasActiveChild } from './helpers';\n\nconst MenuItemRender = ({ children, eventType, text, modifier, url, parent }) => {\n const router = useRouter();\n const { showMobileMenu, openActiveSubmenus } = useContext(MenuContext);\n\n const isHoverEvent = eventType === HOVER;\n const isClickEvent = eventType === CLICK;\n\n const {\n loading: loadingText,\n data: [textToUse]\n } = useStringTemplate(parent, [text]);\n\n const {\n loading: loadingUrl,\n data: [urlToUse]\n } = useStringTemplate(parent, [injectHelperIntoTemplate(url, 'url_encode')]);\n\n const isActive = router ? isUrlPathMatch(router.asPath, urlToUse) : false;\n const isActiveParent = router ? hasActiveChild(router.asPath, children) : false;\n const shouldPreOpen = openActiveSubmenus && isActiveParent && isClickEvent;\n\n const [displayChildren, setDisplayChildren] = useState(shouldPreOpen);\n\n useEffect(\n () => {\n if (!showMobileMenu && !shouldPreOpen) setDisplayChildren(false);\n },\n [children, isClickEvent, loadingUrl, openActiveSubmenus, router]\n );\n\n if (loadingUrl || loadingText) return '';\n\n const childrenDisplayClass = displayChildren ? '' : HIDDEN;\n\n const handleItemEvent = ({ type }) => {\n if (isHoverEvent) {\n if (type === MOUSE_ENTER) {\n setDisplayChildren(true);\n }\n if (type === MOUSE_LEAVE) {\n setDisplayChildren(false);\n }\n }\n };\n\n const hasValidChildren = hasChildren(children);\n\n const menuItemLinkClassname = classnames('menu--item--link', {\n 'menu--item--link--active': isActive,\n 'menu--item--link--active-parent': isActiveParent\n });\n\n return (\n <li className={modifier} onMouseEnter={handleItemEvent} onMouseLeave={handleItemEvent}>\n <div className={menuItemLinkClassname}>\n {urlToUse ? (\n <BlazeLink href={urlToUse}>{textToUse}</BlazeLink>\n ) : (\n <span role=\"button\" onClick={handleItemEvent}>\n {textToUse}\n </span>\n )}\n {hasValidChildren && (\n <i\n role=\"button\"\n className=\"menu--item--link--icon\"\n onClick={() => setDisplayChildren(!displayChildren)}>\n {displayChildren ? <FaChevronUp /> : <FaChevronDown />}\n </i>\n )}\n </div>\n\n {hasValidChildren && (\n <div className={`menu--item-children ${childrenDisplayClass}`}>{children}</div>\n )}\n </li>\n );\n};\n\nMenuItemRender.propTypes = {\n modifier: PropTypes.string,\n text: PropTypes.string,\n url: PropTypes.string,\n eventType: PropTypes.string.isRequired,\n parent: PropTypes.object,\n children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])\n};\n\nMenuItemRender.defaultProps = {\n url: '',\n modifier: '',\n text: '',\n children: null,\n parent: {}\n};\n\nexport default MenuItemR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,EAAE4D,qBAAS,CAACC,MAAM;EACrBhE,SAAS,EAAE+D,qBAAS,CAACC,MAAM,CAACC,UAAU;EACtC7D,MAAM,EAAE2D,qBAAS,CAACG,MAAM;EACxBnE,QAAQ,EAAEgE,qBAAS,CAACI,SAAS,CAAC,CAACJ,qBAAS,CAACK,OAAO,CAACL,qBAAS,CAACM,IAAI,CAAC,EAAEN,qBAAS,CAACM,IAAI,CAAC;AACnF,CAAC;AAEDxE,cAAc,CAACyE,YAAY,GAAG;EAC5BnE,GAAG,EAAE,EAAE;EACPD,QAAQ,EAAE,EAAE;EACZD,IAAI,EAAE,EAAE;EACRF,QAAQ,EAAE,IAAI;EACdK,MAAM,EAAE,CAAC;AACX,CAAC;AAAC,IAAAmE,QAAA,GAAAC,OAAA,cAEa3E,cAAc"}
|
|
@@ -10,7 +10,7 @@ require("core-js/modules/es.regexp.exec.js");
|
|
|
10
10
|
require("core-js/modules/es.regexp.to-string.js");
|
|
11
11
|
var isUrlPathMatch = function isUrlPathMatch(path, itemUrl) {
|
|
12
12
|
if (!itemUrl || !path) return false;
|
|
13
|
-
var reg = new RegExp(/^[
|
|
13
|
+
var reg = new RegExp(/^[^#?]+/);
|
|
14
14
|
var _path = reg.exec(path)[0];
|
|
15
15
|
return _path === itemUrl || _path === "/".concat(itemUrl);
|
|
16
16
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isUrlPathMatch.js","names":["isUrlPathMatch","path","itemUrl","reg","RegExp","_path","exec","concat","_default","exports"],"sources":["../../../../src/components/MenuItem/helpers/isUrlPathMatch.js"],"sourcesContent":["const isUrlPathMatch = (path, itemUrl) => {\n if (!itemUrl || !path) return false;\n\n const reg = new RegExp(/^[
|
|
1
|
+
{"version":3,"file":"isUrlPathMatch.js","names":["isUrlPathMatch","path","itemUrl","reg","RegExp","_path","exec","concat","_default","exports"],"sources":["../../../../src/components/MenuItem/helpers/isUrlPathMatch.js"],"sourcesContent":["const isUrlPathMatch = (path, itemUrl) => {\n if (!itemUrl || !path) return false;\n\n const reg = new RegExp(/^[^#?]+/);\n const _path = reg.exec(path)[0];\n\n return _path === itemUrl || _path === `/${itemUrl}`;\n};\n\nexport default isUrlPathMatch;\n"],"mappings":";;;;;;;;;;AAAA,IAAMA,cAAc,GAAG,SAAjBA,cAAcA,CAAIC,IAAI,EAAEC,OAAO,EAAK;EACxC,IAAI,CAACA,OAAO,IAAI,CAACD,IAAI,EAAE,OAAO,KAAK;EAEnC,IAAME,GAAG,GAAG,IAAIC,MAAM,CAAC,SAAS,CAAC;EACjC,IAAMC,KAAK,GAAGF,GAAG,CAACG,IAAI,CAACL,IAAI,CAAC,CAAC,CAAC,CAAC;EAE/B,OAAOI,KAAK,KAAKH,OAAO,IAAIG,KAAK,SAAAE,MAAA,CAASL,OAAO,CAAE;AACrD,CAAC;AAAC,IAAAM,QAAA,GAAAC,OAAA,cAEaT,cAAc"}
|
|
@@ -25,9 +25,6 @@ const MenuItemRender = ({
|
|
|
25
25
|
} = useContext(MenuContext);
|
|
26
26
|
const isHoverEvent = eventType === HOVER;
|
|
27
27
|
const isClickEvent = eventType === CLICK;
|
|
28
|
-
const isActiveParent = router ? hasActiveChild(router.asPath, children) : false;
|
|
29
|
-
const shouldPreOpen = openActiveSubmenus && isActiveParent && isClickEvent;
|
|
30
|
-
const [displayChildren, setDisplayChildren] = useState(shouldPreOpen);
|
|
31
28
|
const {
|
|
32
29
|
loading: loadingText,
|
|
33
30
|
data: [textToUse]
|
|
@@ -36,11 +33,14 @@ const MenuItemRender = ({
|
|
|
36
33
|
loading: loadingUrl,
|
|
37
34
|
data: [urlToUse]
|
|
38
35
|
} = useStringTemplate(parent, [injectHelperIntoTemplate(url, 'url_encode')]);
|
|
36
|
+
const isActive = router ? isUrlPathMatch(router.asPath, urlToUse) : false;
|
|
37
|
+
const isActiveParent = router ? hasActiveChild(router.asPath, children) : false;
|
|
38
|
+
const shouldPreOpen = openActiveSubmenus && isActiveParent && isClickEvent;
|
|
39
|
+
const [displayChildren, setDisplayChildren] = useState(shouldPreOpen);
|
|
39
40
|
useEffect(() => {
|
|
40
|
-
if (!showMobileMenu) setDisplayChildren(false);
|
|
41
|
+
if (!showMobileMenu && !shouldPreOpen) setDisplayChildren(false);
|
|
41
42
|
}, [children, isClickEvent, loadingUrl, openActiveSubmenus, router]);
|
|
42
43
|
if (loadingUrl || loadingText) return '';
|
|
43
|
-
const isActive = router ? isUrlPathMatch(router.asPath, urlToUse) : false;
|
|
44
44
|
const childrenDisplayClass = displayChildren ? '' : HIDDEN;
|
|
45
45
|
const handleItemEvent = ({
|
|
46
46
|
type
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuItemRender.js","names":["React","useState","useContext","useEffect","PropTypes","FaChevronDown","FaChevronUp","classnames","useRouter","useStringTemplate","HOVER","MOUSE_ENTER","MOUSE_LEAVE","HIDDEN","CLICK","hasChildren","BlazeLink","MenuContext","injectHelperIntoTemplate","isUrlPathMatch","hasActiveChild","MenuItemRender","children","eventType","text","modifier","url","parent","router","showMobileMenu","openActiveSubmenus","isHoverEvent","isClickEvent","
|
|
1
|
+
{"version":3,"file":"MenuItemRender.js","names":["React","useState","useContext","useEffect","PropTypes","FaChevronDown","FaChevronUp","classnames","useRouter","useStringTemplate","HOVER","MOUSE_ENTER","MOUSE_LEAVE","HIDDEN","CLICK","hasChildren","BlazeLink","MenuContext","injectHelperIntoTemplate","isUrlPathMatch","hasActiveChild","MenuItemRender","children","eventType","text","modifier","url","parent","router","showMobileMenu","openActiveSubmenus","isHoverEvent","isClickEvent","loading","loadingText","data","textToUse","loadingUrl","urlToUse","isActive","asPath","isActiveParent","shouldPreOpen","displayChildren","setDisplayChildren","childrenDisplayClass","handleItemEvent","type","hasValidChildren","menuItemLinkClassname","createElement","className","onMouseEnter","onMouseLeave","href","role","onClick","propTypes","string","isRequired","object","oneOfType","arrayOf","node","defaultProps"],"sources":["../../../src/components/MenuItem/MenuItemRender.js"],"sourcesContent":["/* eslint-disable no-console */\nimport React, { useState, useContext, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport { FaChevronDown, FaChevronUp } from 'react-icons/fa';\nimport classnames from 'classnames';\nimport { useRouter } from 'next/router';\nimport { useStringTemplate } from '@blaze-cms/utils-handlebars';\nimport { HOVER, MOUSE_ENTER, MOUSE_LEAVE, HIDDEN, CLICK } from '../../constants';\nimport { hasChildren } from '../../helpers';\nimport BlazeLink from '../BlazeLink';\nimport MenuContext from '../Menu/MenuContext';\nimport { injectHelperIntoTemplate, isUrlPathMatch, hasActiveChild } from './helpers';\n\nconst MenuItemRender = ({ children, eventType, text, modifier, url, parent }) => {\n const router = useRouter();\n const { showMobileMenu, openActiveSubmenus } = useContext(MenuContext);\n\n const isHoverEvent = eventType === HOVER;\n const isClickEvent = eventType === CLICK;\n\n const {\n loading: loadingText,\n data: [textToUse]\n } = useStringTemplate(parent, [text]);\n\n const {\n loading: loadingUrl,\n data: [urlToUse]\n } = useStringTemplate(parent, [injectHelperIntoTemplate(url, 'url_encode')]);\n\n const isActive = router ? isUrlPathMatch(router.asPath, urlToUse) : false;\n const isActiveParent = router ? hasActiveChild(router.asPath, children) : false;\n const shouldPreOpen = openActiveSubmenus && isActiveParent && isClickEvent;\n\n const [displayChildren, setDisplayChildren] = useState(shouldPreOpen);\n\n useEffect(\n () => {\n if (!showMobileMenu && !shouldPreOpen) setDisplayChildren(false);\n },\n [children, isClickEvent, loadingUrl, openActiveSubmenus, router]\n );\n\n if (loadingUrl || loadingText) return '';\n\n const childrenDisplayClass = displayChildren ? '' : HIDDEN;\n\n const handleItemEvent = ({ type }) => {\n if (isHoverEvent) {\n if (type === MOUSE_ENTER) {\n setDisplayChildren(true);\n }\n if (type === MOUSE_LEAVE) {\n setDisplayChildren(false);\n }\n }\n };\n\n const hasValidChildren = hasChildren(children);\n\n const menuItemLinkClassname = classnames('menu--item--link', {\n 'menu--item--link--active': isActive,\n 'menu--item--link--active-parent': isActiveParent\n });\n\n return (\n <li className={modifier} onMouseEnter={handleItemEvent} onMouseLeave={handleItemEvent}>\n <div className={menuItemLinkClassname}>\n {urlToUse ? (\n <BlazeLink href={urlToUse}>{textToUse}</BlazeLink>\n ) : (\n <span role=\"button\" onClick={handleItemEvent}>\n {textToUse}\n </span>\n )}\n {hasValidChildren && (\n <i\n role=\"button\"\n className=\"menu--item--link--icon\"\n onClick={() => setDisplayChildren(!displayChildren)}>\n {displayChildren ? <FaChevronUp /> : <FaChevronDown />}\n </i>\n )}\n </div>\n\n {hasValidChildren && (\n <div className={`menu--item-children ${childrenDisplayClass}`}>{children}</div>\n )}\n </li>\n );\n};\n\nMenuItemRender.propTypes = {\n modifier: PropTypes.string,\n text: PropTypes.string,\n url: PropTypes.string,\n eventType: PropTypes.string.isRequired,\n parent: PropTypes.object,\n children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])\n};\n\nMenuItemRender.defaultProps = {\n url: '',\n modifier: '',\n text: '',\n children: null,\n parent: {}\n};\n\nexport default MenuItemRender;\n"],"mappings":"AAAA;AACA,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,UAAU,EAAEC,SAAS,QAAQ,OAAO;AAC9D,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,aAAa,EAAEC,WAAW,QAAQ,gBAAgB;AAC3D,OAAOC,UAAU,MAAM,YAAY;AACnC,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,iBAAiB,QAAQ,6BAA6B;AAC/D,SAASC,KAAK,EAAEC,WAAW,EAAEC,WAAW,EAAEC,MAAM,EAAEC,KAAK,QAAQ,iBAAiB;AAChF,SAASC,WAAW,QAAQ,eAAe;AAC3C,OAAOC,SAAS,MAAM,cAAc;AACpC,OAAOC,WAAW,MAAM,qBAAqB;AAC7C,SAASC,wBAAwB,EAAEC,cAAc,EAAEC,cAAc,QAAQ,WAAW;AAEpF,MAAMC,cAAc,GAAGA,CAAC;EAAEC,QAAQ;EAAEC,SAAS;EAAEC,IAAI;EAAEC,QAAQ;EAA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AAEvB,QAAc,CAE9E,CAAC;AAET,CAAC;AAEDD,cAAc,CAACoC,SAAS,GAAG;EACzBhC,QAAQ,EAAErB,SAAS,CAACsD,MAAM;EAC1BlC,IAAI,EAAEpB,SAAS,CAACsD,MAAM;EACtBhC,GAAG,EAAEtB,SAAS,CAACsD,MAAM;EACrBnC,SAAS,EAAEnB,SAAS,CAACsD,MAAM,CAACC,UAAU;EACtChC,MAAM,EAAEvB,SAAS,CAACwD,MAAM;EACxBtC,QAAQ,EAAElB,SAAS,CAACyD,SAAS,CAAC,CAACzD,SAAS,CAAC0D,OAAO,CAAC1D,SAAS,CAAC2D,IAAI,CAAC,EAAE3D,SAAS,CAAC2D,IAAI,CAAC;AACnF,CAAC;AAED1C,cAAc,CAAC2C,YAAY,GAAG;EAC5BtC,GAAG,EAAE,EAAE;EACPD,QAAQ,EAAE,EAAE;EACZD,IAAI,EAAE,EAAE;EACRF,QAAQ,EAAE,IAAI;EACdK,MAAM,EAAE,CAAC;AACX,CAAC;AAED,eAAeN,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isUrlPathMatch.js","names":["isUrlPathMatch","path","itemUrl","reg","RegExp","_path","exec"],"sources":["../../../../src/components/MenuItem/helpers/isUrlPathMatch.js"],"sourcesContent":["const isUrlPathMatch = (path, itemUrl) => {\n if (!itemUrl || !path) return false;\n\n const reg = new RegExp(/^[
|
|
1
|
+
{"version":3,"file":"isUrlPathMatch.js","names":["isUrlPathMatch","path","itemUrl","reg","RegExp","_path","exec"],"sources":["../../../../src/components/MenuItem/helpers/isUrlPathMatch.js"],"sourcesContent":["const isUrlPathMatch = (path, itemUrl) => {\n if (!itemUrl || !path) return false;\n\n const reg = new RegExp(/^[^#?]+/);\n const _path = reg.exec(path)[0];\n\n return _path === itemUrl || _path === `/${itemUrl}`;\n};\n\nexport default isUrlPathMatch;\n"],"mappings":"AAAA,MAAMA,cAAc,GAAGA,CAACC,IAAI,EAAEC,OAAO,KAAK;EACxC,IAAI,CAACA,OAAO,IAAI,CAACD,IAAI,EAAE,OAAO,KAAK;EAEnC,MAAME,GAAG,GAAG,IAAIC,MAAM,CAAC,SAAS,CAAC;EACjC,MAAMC,KAAK,GAAGF,GAAG,CAACG,IAAI,CAACL,IAAI,CAAC,CAAC,CAAC,CAAC;EAE/B,OAAOI,KAAK,KAAKH,OAAO,IAAIG,KAAK,KAAM,IAAGH,OAAQ,EAAC;AACrD,CAAC;AAED,eAAeF,cAAc"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaze-cms/react-page-builder",
|
|
3
|
-
"version": "0.146.0-tooltips.
|
|
3
|
+
"version": "0.146.0-tooltips.3",
|
|
4
4
|
"description": "Blaze react page builder",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "lib-es/index.js",
|
|
@@ -90,5 +90,5 @@
|
|
|
90
90
|
"lib/*",
|
|
91
91
|
"lib-es/*"
|
|
92
92
|
],
|
|
93
|
-
"gitHead": "
|
|
93
|
+
"gitHead": "c6a7b0dcaf52b88093d305565a084a26714faa13"
|
|
94
94
|
}
|
|
@@ -18,11 +18,6 @@ const MenuItemRender = ({ children, eventType, text, modifier, url, parent }) =>
|
|
|
18
18
|
const isHoverEvent = eventType === HOVER;
|
|
19
19
|
const isClickEvent = eventType === CLICK;
|
|
20
20
|
|
|
21
|
-
const isActiveParent = router ? hasActiveChild(router.asPath, children) : false;
|
|
22
|
-
const shouldPreOpen = openActiveSubmenus && isActiveParent && isClickEvent;
|
|
23
|
-
|
|
24
|
-
const [displayChildren, setDisplayChildren] = useState(shouldPreOpen);
|
|
25
|
-
|
|
26
21
|
const {
|
|
27
22
|
loading: loadingText,
|
|
28
23
|
data: [textToUse]
|
|
@@ -33,15 +28,21 @@ const MenuItemRender = ({ children, eventType, text, modifier, url, parent }) =>
|
|
|
33
28
|
data: [urlToUse]
|
|
34
29
|
} = useStringTemplate(parent, [injectHelperIntoTemplate(url, 'url_encode')]);
|
|
35
30
|
|
|
31
|
+
const isActive = router ? isUrlPathMatch(router.asPath, urlToUse) : false;
|
|
32
|
+
const isActiveParent = router ? hasActiveChild(router.asPath, children) : false;
|
|
33
|
+
const shouldPreOpen = openActiveSubmenus && isActiveParent && isClickEvent;
|
|
34
|
+
|
|
35
|
+
const [displayChildren, setDisplayChildren] = useState(shouldPreOpen);
|
|
36
|
+
|
|
36
37
|
useEffect(
|
|
37
38
|
() => {
|
|
38
|
-
if (!showMobileMenu) setDisplayChildren(false);
|
|
39
|
+
if (!showMobileMenu && !shouldPreOpen) setDisplayChildren(false);
|
|
39
40
|
},
|
|
40
41
|
[children, isClickEvent, loadingUrl, openActiveSubmenus, router]
|
|
41
42
|
);
|
|
42
43
|
|
|
43
44
|
if (loadingUrl || loadingText) return '';
|
|
44
|
-
|
|
45
|
+
|
|
45
46
|
const childrenDisplayClass = displayChildren ? '' : HIDDEN;
|
|
46
47
|
|
|
47
48
|
const handleItemEvent = ({ type }) => {
|
|
@@ -30,6 +30,13 @@ describe('isUrlPathMatch', () => {
|
|
|
30
30
|
expect(result).toBeFalsy();
|
|
31
31
|
});
|
|
32
32
|
|
|
33
|
+
it('should match with uri-with-fragment', () => {
|
|
34
|
+
const path = '/button#dark';
|
|
35
|
+
const itemUrl = 'button';
|
|
36
|
+
const result = isUrlPathMatch(path, itemUrl);
|
|
37
|
+
expect(result).toBeTruthy();
|
|
38
|
+
});
|
|
39
|
+
|
|
33
40
|
it('should match with uri-with-parameters', () => {
|
|
34
41
|
const path = '/button?paramater=value';
|
|
35
42
|
const itemUrl = 'button';
|