@blaze-cms/react-page-builder 0.146.0-alpha.30 → 0.146.0-alpha.32
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 +19 -0
- package/lib/components/DateTime/DateTime.js +11 -5
- package/lib/components/DateTime/DateTime.js.map +1 -1
- package/lib/components/MenuItem/MenuItemRender.js +9 -2
- package/lib/components/MenuItem/MenuItemRender.js.map +1 -1
- package/lib-es/components/DateTime/DateTime.js +11 -5
- package/lib-es/components/DateTime/DateTime.js.map +1 -1
- package/lib-es/components/MenuItem/MenuItemRender.js +9 -2
- package/lib-es/components/MenuItem/MenuItemRender.js.map +1 -1
- package/package.json +2 -2
- package/src/components/DateTime/DateTime.js +9 -5
- package/src/components/MenuItem/MenuItemRender.js +15 -4
- package/tests/unit/src/components/DateTime/DateTime.test.js +29 -5
- package/tests/unit/src/components/MenuItem/MenuItem.test.js +4 -0
- package/tests/unit/src/components/MenuItem/MenuItemRender.test.js +29 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,25 @@
|
|
|
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-alpha.32](https://github.com/thebyte9/blaze/compare/v0.146.0-alpha.31...v0.146.0-alpha.32) (2025-03-17)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* close menu item on url change ([#4669](https://github.com/thebyte9/blaze/issues/4669)) ([697750a](https://github.com/thebyte9/blaze/commit/697750ac771a5ea89702e990e23d6e78b1c45a67))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [0.146.0-alpha.31](https://github.com/thebyte9/blaze/compare/v0.146.0-alpha.30...v0.146.0-alpha.31) (2025-03-05)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @blaze-cms/react-page-builder
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
6
25
|
# [0.146.0-alpha.30](https://github.com/thebyte9/blaze/compare/v0.146.0-alpha.29...v0.146.0-alpha.30) (2025-02-25)
|
|
7
26
|
|
|
8
27
|
|
|
@@ -15,23 +15,29 @@ _dayjs["default"].extend(_localizedFormat["default"]);
|
|
|
15
15
|
var DateTime = function DateTime(_ref) {
|
|
16
16
|
var format = _ref.format,
|
|
17
17
|
customFormat = _ref.customFormat,
|
|
18
|
-
modifier = _ref.modifier
|
|
18
|
+
modifier = _ref.modifier,
|
|
19
|
+
prefix = _ref.prefix,
|
|
20
|
+
suffix = _ref.suffix;
|
|
19
21
|
var dateFormat = customFormat || format;
|
|
20
22
|
if (!dateFormat) return null;
|
|
21
|
-
var
|
|
23
|
+
var formattedDate = (0, _dayjs["default"])().format(dateFormat);
|
|
22
24
|
return /*#__PURE__*/_react["default"].createElement(_Wrapper["default"], {
|
|
23
25
|
className: "date",
|
|
24
26
|
modifiers: modifier
|
|
25
|
-
},
|
|
27
|
+
}, prefix, " ", formattedDate, " ", suffix);
|
|
26
28
|
};
|
|
27
29
|
DateTime.propTypes = {
|
|
28
30
|
format: _propTypes["default"].string.isRequired,
|
|
29
31
|
customFormat: _propTypes["default"].string,
|
|
30
|
-
modifier: _propTypes["default"].string
|
|
32
|
+
modifier: _propTypes["default"].string,
|
|
33
|
+
prefix: _propTypes["default"].string,
|
|
34
|
+
suffix: _propTypes["default"].string
|
|
31
35
|
};
|
|
32
36
|
DateTime.defaultProps = {
|
|
37
|
+
customFormat: '',
|
|
33
38
|
modifier: null,
|
|
34
|
-
|
|
39
|
+
prefix: '',
|
|
40
|
+
suffix: ''
|
|
35
41
|
};
|
|
36
42
|
var _default = exports["default"] = DateTime;
|
|
37
43
|
//# sourceMappingURL=DateTime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTime.js","names":["_react","_interopRequireDefault","require","_propTypes","_dayjs","_localizedFormat","_Wrapper","dayjs","extend","LocalizedFormat","DateTime","_ref","format","customFormat","modifier","dateFormat","
|
|
1
|
+
{"version":3,"file":"DateTime.js","names":["_react","_interopRequireDefault","require","_propTypes","_dayjs","_localizedFormat","_Wrapper","dayjs","extend","LocalizedFormat","DateTime","_ref","format","customFormat","modifier","prefix","suffix","dateFormat","formattedDate","createElement","className","modifiers","propTypes","PropTypes","string","isRequired","defaultProps","_default","exports"],"sources":["../../../src/components/DateTime/DateTime.js"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport dayjs from 'dayjs';\nimport LocalizedFormat from 'dayjs/plugin/localizedFormat';\nimport Wrapper from '../Wrapper';\n\ndayjs.extend(LocalizedFormat);\n\nconst DateTime = ({ format, customFormat, modifier, prefix, suffix }) => {\n const dateFormat = customFormat || format;\n\n if (!dateFormat) return null;\n\n const formattedDate = dayjs().format(dateFormat);\n\n return (\n <Wrapper className=\"date\" modifiers={modifier}>\n {prefix} {formattedDate} {suffix}\n </Wrapper>\n );\n};\n\nDateTime.propTypes = {\n format: PropTypes.string.isRequired,\n customFormat: PropTypes.string,\n modifier: PropTypes.string,\n prefix: PropTypes.string,\n suffix: PropTypes.string\n};\n\nDateTime.defaultProps = {\n customFormat: '',\n modifier: null,\n prefix: '',\n suffix: ''\n};\n\nexport default DateTime;\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,UAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,MAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,gBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,QAAA,GAAAL,sBAAA,CAAAC,OAAA;AAEAK,iBAAK,CAACC,MAAM,CAACC,2BAAe,CAAC;AAE7B,IAAMC,QAAQ,GAAG,SAAXA,QAAQA,CAAAC,IAAA,EAA2D;EAAA,IAArDC,MAAM,GAAAD,IAAA,CAANC,MAAM;IAAEC,YAAY,GAAAF,IAAA,CAAZE,YAAY;IAAEC,QAAQ,GAAAH,IAAA,CAARG,QAAQ;IAAEC,MAAM,GAAAJ,IAAA,CAANI,MAAM;IAAEC,MAAM,GAAAL,IAAA,CAANK,MAAM;EAChE,IAAMC,UAAU,GAAGJ,YAAY,IAAID,MAAM;EAEzC,IAAI,CAACK,UAAU,EAAE,OAAO,IAAI;EAE5B,IAAMC,aAAa,GAAG,IAAAX,iBAAK,EAAC,CAAC,CAACK,MAAM,CAACK,UAAU,CAAC;EAEhD,oBACEjB,MAAA,YAAAmB,aAAA,CAACb,QAAA,WAAO;IAACc,SAAS,EAAC,MAAM;IAACC,SAAS,EAAEP;EAAS,GAC3CC,MAAM,EAAC,GAAC,EAACG,aAAa,EAAC,GAAC,EAACF,MACnB,CAAC;AAEd,CAAC;AAEDN,QAAQ,CAACY,SAAS,GAAG;EACnBV,MAAM,EAAEW,qBAAS,CAACC,MAAM,CAACC,UAAU;EACnCZ,YAAY,EAAEU,qBAAS,CAACC,MAAM;EAC9BV,QAAQ,EAAES,qBAAS,CAACC,MAAM;EAC1BT,MAAM,EAAEQ,qBAAS,CAACC,MAAM;EACxBR,MAAM,EAAEO,qBAAS,CAACC;AACpB,CAAC;AAEDd,QAAQ,CAACgB,YAAY,GAAG;EACtBb,YAAY,EAAE,EAAE;EAChBC,QAAQ,EAAE,IAAI;EACdC,MAAM,EAAE,EAAE;EACVC,MAAM,EAAE;AACV,CAAC;AAAC,IAAAW,QAAA,GAAAC,OAAA,cAEalB,QAAQ","ignoreList":[]}
|
|
@@ -17,6 +17,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
17
17
|
var _react = _interopRequireWildcard(require("react"));
|
|
18
18
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
19
19
|
var _fa = require("react-icons/fa");
|
|
20
|
+
var _router = require("next/router");
|
|
20
21
|
var _utilsHandlebars = require("@blaze-cms/utils-handlebars");
|
|
21
22
|
var _constants = require("../../constants");
|
|
22
23
|
var _helpers = require("../../helpers");
|
|
@@ -46,12 +47,18 @@ var MenuItemRender = function MenuItemRender(_ref) {
|
|
|
46
47
|
loadingUrl = _useStringTemplate2.loading,
|
|
47
48
|
_useStringTemplate2$d = (0, _slicedToArray2["default"])(_useStringTemplate2.data, 1),
|
|
48
49
|
urlToUse = _useStringTemplate2$d[0];
|
|
50
|
+
var router = (0, _router.useRouter)();
|
|
51
|
+
var isHoverEvent = eventType === _constants.HOVER;
|
|
52
|
+
var childrenDisplayClass = displayChildren ? '' : _constants.HIDDEN;
|
|
49
53
|
(0, _react.useEffect)(function () {
|
|
50
54
|
if (!showMobileMenu) setDisplayChildren(false);
|
|
51
55
|
}, [showMobileMenu]);
|
|
56
|
+
(0, _react.useEffect)(function () {
|
|
57
|
+
if (isHoverEvent) {
|
|
58
|
+
setDisplayChildren(false);
|
|
59
|
+
}
|
|
60
|
+
}, [router.asPath, isHoverEvent]);
|
|
52
61
|
if (loadingUrl || loadingText) return '';
|
|
53
|
-
var isHoverEvent = eventType === _constants.HOVER;
|
|
54
|
-
var childrenDisplayClass = displayChildren ? '' : _constants.HIDDEN;
|
|
55
62
|
var handleItemEvent = function handleItemEvent(_ref2) {
|
|
56
63
|
var type = _ref2.type;
|
|
57
64
|
if (isHoverEvent) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuItemRender.js","names":["_react","_interopRequireWildcard","require","_propTypes","_interopRequireDefault","_fa","_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","_useState","useState","_useState2","_slicedToArray2","displayChildren","setDisplayChildren","_useContext","useContext","MenuContext","showMobileMenu","_useStringTemplate","useStringTemplate","loadingText","loading","_useStringTemplate$da","data","textToUse","_useStringTemplate2","injectHelperIntoTemplate","loadingUrl","_useStringTemplate2$d","urlToUse","
|
|
1
|
+
{"version":3,"file":"MenuItemRender.js","names":["_react","_interopRequireWildcard","require","_propTypes","_interopRequireDefault","_fa","_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","_useState","useState","_useState2","_slicedToArray2","displayChildren","setDisplayChildren","_useContext","useContext","MenuContext","showMobileMenu","_useStringTemplate","useStringTemplate","loadingText","loading","_useStringTemplate$da","data","textToUse","_useStringTemplate2","injectHelperIntoTemplate","loadingUrl","_useStringTemplate2$d","urlToUse","router","useRouter","isHoverEvent","HOVER","childrenDisplayClass","HIDDEN","useEffect","asPath","handleItemEvent","_ref2","type","MOUSE_ENTER","MOUSE_LEAVE","hasValidChildren","hasChildren","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":["import React, { useState, useContext, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport { FaChevronDown, FaChevronUp } from 'react-icons/fa';\nimport { useRouter } from 'next/router';\nimport { useStringTemplate } from '@blaze-cms/utils-handlebars';\nimport { HOVER, MOUSE_ENTER, MOUSE_LEAVE, HIDDEN } from '../../constants';\nimport { hasChildren } from '../../helpers';\nimport BlazeLink from '../BlazeLink';\nimport MenuContext from '../Menu/MenuContext';\nimport { injectHelperIntoTemplate } from './helpers';\n\nconst MenuItemRender = ({ children, eventType, text, modifier, url, parent }) => {\n const [displayChildren, setDisplayChildren] = useState(false);\n const { showMobileMenu } = useContext(MenuContext);\n const {\n loading: loadingText,\n data: [textToUse]\n } = useStringTemplate(parent, [text]);\n const {\n loading: loadingUrl,\n data: [urlToUse]\n } = useStringTemplate(parent, [injectHelperIntoTemplate(url, 'url_encode')]);\n\n const router = useRouter();\n const isHoverEvent = eventType === HOVER;\n const childrenDisplayClass = displayChildren ? '' : HIDDEN;\n\n useEffect(\n () => {\n if (!showMobileMenu) setDisplayChildren(false);\n },\n [showMobileMenu]\n );\n\n useEffect(\n () => {\n if (isHoverEvent) {\n setDisplayChildren(false);\n }\n },\n [router.asPath, isHoverEvent]\n );\n\n if (loadingUrl || loadingText) return '';\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 return (\n <li className={modifier} onMouseEnter={handleItemEvent} onMouseLeave={handleItemEvent}>\n <div className=\"menu--item--link\">\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,IAAAA,MAAA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extend(LocalizedFormat);
|
|
|
7
7
|
const DateTime = ({
|
|
8
8
|
format,
|
|
9
9
|
customFormat,
|
|
10
|
-
modifier
|
|
10
|
+
modifier,
|
|
11
|
+
prefix,
|
|
12
|
+
suffix
|
|
11
13
|
}) => {
|
|
12
14
|
const dateFormat = customFormat || format;
|
|
13
15
|
if (!dateFormat) return null;
|
|
14
|
-
const
|
|
16
|
+
const formattedDate = dayjs().format(dateFormat);
|
|
15
17
|
return /*#__PURE__*/React.createElement(Wrapper, {
|
|
16
18
|
className: "date",
|
|
17
19
|
modifiers: modifier
|
|
18
|
-
},
|
|
20
|
+
}, prefix, " ", formattedDate, " ", suffix);
|
|
19
21
|
};
|
|
20
22
|
DateTime.propTypes = {
|
|
21
23
|
format: PropTypes.string.isRequired,
|
|
22
24
|
customFormat: PropTypes.string,
|
|
23
|
-
modifier: PropTypes.string
|
|
25
|
+
modifier: PropTypes.string,
|
|
26
|
+
prefix: PropTypes.string,
|
|
27
|
+
suffix: PropTypes.string
|
|
24
28
|
};
|
|
25
29
|
DateTime.defaultProps = {
|
|
30
|
+
customFormat: '',
|
|
26
31
|
modifier: null,
|
|
27
|
-
|
|
32
|
+
prefix: '',
|
|
33
|
+
suffix: ''
|
|
28
34
|
};
|
|
29
35
|
export default DateTime;
|
|
30
36
|
//# sourceMappingURL=DateTime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DateTime.js","names":["React","PropTypes","dayjs","LocalizedFormat","Wrapper","extend","DateTime","format","customFormat","modifier","dateFormat","
|
|
1
|
+
{"version":3,"file":"DateTime.js","names":["React","PropTypes","dayjs","LocalizedFormat","Wrapper","extend","DateTime","format","customFormat","modifier","prefix","suffix","dateFormat","formattedDate","createElement","className","modifiers","propTypes","string","isRequired","defaultProps"],"sources":["../../../src/components/DateTime/DateTime.js"],"sourcesContent":["import React from 'react';\nimport PropTypes from 'prop-types';\nimport dayjs from 'dayjs';\nimport LocalizedFormat from 'dayjs/plugin/localizedFormat';\nimport Wrapper from '../Wrapper';\n\ndayjs.extend(LocalizedFormat);\n\nconst DateTime = ({ format, customFormat, modifier, prefix, suffix }) => {\n const dateFormat = customFormat || format;\n\n if (!dateFormat) return null;\n\n const formattedDate = dayjs().format(dateFormat);\n\n return (\n <Wrapper className=\"date\" modifiers={modifier}>\n {prefix} {formattedDate} {suffix}\n </Wrapper>\n );\n};\n\nDateTime.propTypes = {\n format: PropTypes.string.isRequired,\n customFormat: PropTypes.string,\n modifier: PropTypes.string,\n prefix: PropTypes.string,\n suffix: PropTypes.string\n};\n\nDateTime.defaultProps = {\n customFormat: '',\n modifier: null,\n prefix: '',\n suffix: ''\n};\n\nexport default DateTime;\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,OAAOC,SAAS,MAAM,YAAY;AAClC,OAAOC,KAAK,MAAM,OAAO;AACzB,OAAOC,eAAe,MAAM,8BAA8B;AAC1D,OAAOC,OAAO,MAAM,YAAY;AAEhCF,KAAK,CAACG,MAAM,CAACF,eAAe,CAAC;AAE7B,MAAMG,QAAQ,GAAGA,CAAC;EAAEC,MAAM;EAAEC,YAAY;EAAEC,QAAQ;EAAEC,MAAM;EAAEC;AAAO,CAAC,KAAK;EACvE,MAAMC,UAAU,GAAGJ,YAAY,IAAID,MAAM;EAEzC,IAAI,CAACK,UAAU,EAAE,OAAO,IAAI;EAE5B,MAAMC,aAAa,GAAGX,KAAK,CAAC,CAAC,CAACK,MAAM,CAACK,UAAU,CAAC;EAEhD,oBACEZ,KAAA,CAAAc,aAAA,CAACV,OAAO;IAACW,SAAS,EAAC,MAAM;IAACC,SAAS,EAAEP;EAAS,GAC3CC,MAAM,EAAC,GAAC,EAACG,aAAa,EAAC,GAAC,EAACF,MACnB,CAAC;AAEd,CAAC;AAEDL,QAAQ,CAACW,SAAS,GAAG;EACnBV,MAAM,EAAEN,SAAS,CAACiB,MAAM,CAACC,UAAU;EACnCX,YAAY,EAAEP,SAAS,CAACiB,MAAM;EAC9BT,QAAQ,EAAER,SAAS,CAACiB,MAAM;EAC1BR,MAAM,EAAET,SAAS,CAACiB,MAAM;EACxBP,MAAM,EAAEV,SAAS,CAACiB;AACpB,CAAC;AAEDZ,QAAQ,CAACc,YAAY,GAAG;EACtBZ,YAAY,EAAE,EAAE;EAChBC,QAAQ,EAAE,IAAI;EACdC,MAAM,EAAE,EAAE;EACVC,MAAM,EAAE;AACV,CAAC;AAED,eAAeL,QAAQ","ignoreList":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useState, useContext, useEffect } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { FaChevronDown, FaChevronUp } from 'react-icons/fa';
|
|
4
|
+
import { useRouter } from 'next/router';
|
|
4
5
|
import { useStringTemplate } from '@blaze-cms/utils-handlebars';
|
|
5
6
|
import { HOVER, MOUSE_ENTER, MOUSE_LEAVE, HIDDEN } from '../../constants';
|
|
6
7
|
import { hasChildren } from '../../helpers';
|
|
@@ -27,12 +28,18 @@ const MenuItemRender = ({
|
|
|
27
28
|
loading: loadingUrl,
|
|
28
29
|
data: [urlToUse]
|
|
29
30
|
} = useStringTemplate(parent, [injectHelperIntoTemplate(url, 'url_encode')]);
|
|
31
|
+
const router = useRouter();
|
|
32
|
+
const isHoverEvent = eventType === HOVER;
|
|
33
|
+
const childrenDisplayClass = displayChildren ? '' : HIDDEN;
|
|
30
34
|
useEffect(() => {
|
|
31
35
|
if (!showMobileMenu) setDisplayChildren(false);
|
|
32
36
|
}, [showMobileMenu]);
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
if (isHoverEvent) {
|
|
39
|
+
setDisplayChildren(false);
|
|
40
|
+
}
|
|
41
|
+
}, [router.asPath, isHoverEvent]);
|
|
33
42
|
if (loadingUrl || loadingText) return '';
|
|
34
|
-
const isHoverEvent = eventType === HOVER;
|
|
35
|
-
const childrenDisplayClass = displayChildren ? '' : HIDDEN;
|
|
36
43
|
const handleItemEvent = ({
|
|
37
44
|
type
|
|
38
45
|
}) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MenuItemRender.js","names":["React","useState","useContext","useEffect","PropTypes","FaChevronDown","FaChevronUp","useStringTemplate","HOVER","MOUSE_ENTER","MOUSE_LEAVE","HIDDEN","hasChildren","BlazeLink","MenuContext","injectHelperIntoTemplate","MenuItemRender","children","eventType","text","modifier","url","parent","displayChildren","setDisplayChildren","showMobileMenu","loading","loadingText","data","textToUse","loadingUrl","urlToUse","isHoverEvent","childrenDisplayClass","handleItemEvent","type","hasValidChildren","createElement","className","onMouseEnter","onMouseLeave","href","role","onClick","propTypes","string","isRequired","object","oneOfType","arrayOf","node","defaultProps"],"sources":["../../../src/components/MenuItem/MenuItemRender.js"],"sourcesContent":["import React, { useState, useContext, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport { FaChevronDown, FaChevronUp } from 'react-icons/fa';\nimport { useStringTemplate } from '@blaze-cms/utils-handlebars';\nimport { HOVER, MOUSE_ENTER, MOUSE_LEAVE, HIDDEN } from '../../constants';\nimport { hasChildren } from '../../helpers';\nimport BlazeLink from '../BlazeLink';\nimport MenuContext from '../Menu/MenuContext';\nimport { injectHelperIntoTemplate } from './helpers';\n\nconst MenuItemRender = ({ children, eventType, text, modifier, url, parent }) => {\n const [displayChildren, setDisplayChildren] = useState(false);\n const { showMobileMenu } = useContext(MenuContext);\n const {\n loading: loadingText,\n data: [textToUse]\n } = useStringTemplate(parent, [text]);\n
|
|
1
|
+
{"version":3,"file":"MenuItemRender.js","names":["React","useState","useContext","useEffect","PropTypes","FaChevronDown","FaChevronUp","useRouter","useStringTemplate","HOVER","MOUSE_ENTER","MOUSE_LEAVE","HIDDEN","hasChildren","BlazeLink","MenuContext","injectHelperIntoTemplate","MenuItemRender","children","eventType","text","modifier","url","parent","displayChildren","setDisplayChildren","showMobileMenu","loading","loadingText","data","textToUse","loadingUrl","urlToUse","router","isHoverEvent","childrenDisplayClass","asPath","handleItemEvent","type","hasValidChildren","createElement","className","onMouseEnter","onMouseLeave","href","role","onClick","propTypes","string","isRequired","object","oneOfType","arrayOf","node","defaultProps"],"sources":["../../../src/components/MenuItem/MenuItemRender.js"],"sourcesContent":["import React, { useState, useContext, useEffect } from 'react';\nimport PropTypes from 'prop-types';\nimport { FaChevronDown, FaChevronUp } from 'react-icons/fa';\nimport { useRouter } from 'next/router';\nimport { useStringTemplate } from '@blaze-cms/utils-handlebars';\nimport { HOVER, MOUSE_ENTER, MOUSE_LEAVE, HIDDEN } from '../../constants';\nimport { hasChildren } from '../../helpers';\nimport BlazeLink from '../BlazeLink';\nimport MenuContext from '../Menu/MenuContext';\nimport { injectHelperIntoTemplate } from './helpers';\n\nconst MenuItemRender = ({ children, eventType, text, modifier, url, parent }) => {\n const [displayChildren, setDisplayChildren] = useState(false);\n const { showMobileMenu } = useContext(MenuContext);\n const {\n loading: loadingText,\n data: [textToUse]\n } = useStringTemplate(parent, [text]);\n const {\n loading: loadingUrl,\n data: [urlToUse]\n } = useStringTemplate(parent, [injectHelperIntoTemplate(url, 'url_encode')]);\n\n const router = useRouter();\n const isHoverEvent = eventType === HOVER;\n const childrenDisplayClass = displayChildren ? '' : HIDDEN;\n\n useEffect(\n () => {\n if (!showMobileMenu) setDisplayChildren(false);\n },\n [showMobileMenu]\n );\n\n useEffect(\n () => {\n if (isHoverEvent) {\n setDisplayChildren(false);\n }\n },\n [router.asPath, isHoverEvent]\n );\n\n if (loadingUrl || loadingText) return '';\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 return (\n <li className={modifier} onMouseEnter={handleItemEvent} onMouseLeave={handleItemEvent}>\n <div className=\"menu--item--link\">\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,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,UAAU,EAAEC,SAAS,QAAQ,OAAO;AAC9D,OAAOC,SAAS,MAAM,YAAY;AAClC,SAASC,aAAa,EAAEC,WAAW,QAAQ,gBAAgB;AAC3D,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,iBAAiB,QAAQ,6BAA6B;AAC/D,SAASC,KAAK,EAAEC,WAAW,EAAEC,WAAW,EAAEC,MAAM,QAAQ,iBAAiB;AACzE,SAASC,WAAW,QAAQ,eAAe;AAC3C,OAAOC,SAAS,MAAM,cAAc;AACpC,OAAOC,WAAW,MAAM,qBAAqB;AAC7C,SAASC,wBAAwB,QAAQ,WAAW;AAEpD,MAAMC,cAAc,GAAGA,CAAC;EAAEC,QAAQ;EAAEC,SAAS;EAAEC,IAAI;EAAEC,QAAQ;EAAEC,GAAG;EAAEC;AAAO,CAAC,KAAK;EAC/E,MAAM,CAACC,eAAe,EAAEC,kBAAkB,CAAC,GAAGxB,QAAQ,CAAC,KAAK,CAAC;EAC7D,MAAM;IAAEyB;EAAe,CAAC,GAAGxB,UAAU,CAACa,WAAW,CAAC;EAClD,MAAM;IACJY,OAAO,EAAEC,WAAW;IACpBC,IAA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AED,eAAeN,cAAc","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blaze-cms/react-page-builder",
|
|
3
|
-
"version": "0.146.0-alpha.
|
|
3
|
+
"version": "0.146.0-alpha.32",
|
|
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": "2bb1bfa4e03f7ad0f80b4ae67bc3130956cfca71"
|
|
94
94
|
}
|
|
@@ -6,16 +6,16 @@ import Wrapper from '../Wrapper';
|
|
|
6
6
|
|
|
7
7
|
dayjs.extend(LocalizedFormat);
|
|
8
8
|
|
|
9
|
-
const DateTime = ({ format, customFormat, modifier }) => {
|
|
9
|
+
const DateTime = ({ format, customFormat, modifier, prefix, suffix }) => {
|
|
10
10
|
const dateFormat = customFormat || format;
|
|
11
11
|
|
|
12
12
|
if (!dateFormat) return null;
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
const formattedDate = dayjs().format(dateFormat);
|
|
15
15
|
|
|
16
16
|
return (
|
|
17
17
|
<Wrapper className="date" modifiers={modifier}>
|
|
18
|
-
{
|
|
18
|
+
{prefix} {formattedDate} {suffix}
|
|
19
19
|
</Wrapper>
|
|
20
20
|
);
|
|
21
21
|
};
|
|
@@ -23,12 +23,16 @@ const DateTime = ({ format, customFormat, modifier }) => {
|
|
|
23
23
|
DateTime.propTypes = {
|
|
24
24
|
format: PropTypes.string.isRequired,
|
|
25
25
|
customFormat: PropTypes.string,
|
|
26
|
-
modifier: PropTypes.string
|
|
26
|
+
modifier: PropTypes.string,
|
|
27
|
+
prefix: PropTypes.string,
|
|
28
|
+
suffix: PropTypes.string
|
|
27
29
|
};
|
|
28
30
|
|
|
29
31
|
DateTime.defaultProps = {
|
|
32
|
+
customFormat: '',
|
|
30
33
|
modifier: null,
|
|
31
|
-
|
|
34
|
+
prefix: '',
|
|
35
|
+
suffix: ''
|
|
32
36
|
};
|
|
33
37
|
|
|
34
38
|
export default DateTime;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { useState, useContext, useEffect } from 'react';
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import { FaChevronDown, FaChevronUp } from 'react-icons/fa';
|
|
4
|
+
import { useRouter } from 'next/router';
|
|
4
5
|
import { useStringTemplate } from '@blaze-cms/utils-handlebars';
|
|
5
6
|
import { HOVER, MOUSE_ENTER, MOUSE_LEAVE, HIDDEN } from '../../constants';
|
|
6
7
|
import { hasChildren } from '../../helpers';
|
|
@@ -15,12 +16,15 @@ const MenuItemRender = ({ children, eventType, text, modifier, url, parent }) =>
|
|
|
15
16
|
loading: loadingText,
|
|
16
17
|
data: [textToUse]
|
|
17
18
|
} = useStringTemplate(parent, [text]);
|
|
18
|
-
|
|
19
19
|
const {
|
|
20
20
|
loading: loadingUrl,
|
|
21
21
|
data: [urlToUse]
|
|
22
22
|
} = useStringTemplate(parent, [injectHelperIntoTemplate(url, 'url_encode')]);
|
|
23
23
|
|
|
24
|
+
const router = useRouter();
|
|
25
|
+
const isHoverEvent = eventType === HOVER;
|
|
26
|
+
const childrenDisplayClass = displayChildren ? '' : HIDDEN;
|
|
27
|
+
|
|
24
28
|
useEffect(
|
|
25
29
|
() => {
|
|
26
30
|
if (!showMobileMenu) setDisplayChildren(false);
|
|
@@ -28,10 +32,16 @@ const MenuItemRender = ({ children, eventType, text, modifier, url, parent }) =>
|
|
|
28
32
|
[showMobileMenu]
|
|
29
33
|
);
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
useEffect(
|
|
36
|
+
() => {
|
|
37
|
+
if (isHoverEvent) {
|
|
38
|
+
setDisplayChildren(false);
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
[router.asPath, isHoverEvent]
|
|
42
|
+
);
|
|
32
43
|
|
|
33
|
-
|
|
34
|
-
const childrenDisplayClass = displayChildren ? '' : HIDDEN;
|
|
44
|
+
if (loadingUrl || loadingText) return '';
|
|
35
45
|
|
|
36
46
|
const handleItemEvent = ({ type }) => {
|
|
37
47
|
if (isHoverEvent) {
|
|
@@ -43,6 +53,7 @@ const MenuItemRender = ({ children, eventType, text, modifier, url, parent }) =>
|
|
|
43
53
|
}
|
|
44
54
|
}
|
|
45
55
|
};
|
|
56
|
+
|
|
46
57
|
const hasValidChildren = hasChildren(children);
|
|
47
58
|
|
|
48
59
|
return (
|
|
@@ -4,9 +4,12 @@
|
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { render } from '@testing-library/react';
|
|
6
6
|
import '@testing-library/jest-dom/extend-expect';
|
|
7
|
+
import dayjs from 'dayjs';
|
|
7
8
|
import DateTime from '../../../../../src/components/DateTime';
|
|
8
9
|
|
|
9
10
|
describe('DateTime component', () => {
|
|
11
|
+
const customFormat = 'MM-DD-YYYY';
|
|
12
|
+
|
|
10
13
|
it('renders null if both format and customFormat are not provided', () => {
|
|
11
14
|
const { container } = render(<DateTime />);
|
|
12
15
|
expect(container.firstChild).toBeNull();
|
|
@@ -86,14 +89,13 @@ describe('DateTime component', () => {
|
|
|
86
89
|
).toBeInTheDocument();
|
|
87
90
|
});
|
|
88
91
|
|
|
89
|
-
it('renders correctly with customFormat', () => {
|
|
90
|
-
const
|
|
91
|
-
const { getByText } = render(<DateTime format="L" customFormat={
|
|
92
|
-
expect(getByText(/\d{
|
|
92
|
+
it('renders correctly with customFormat DD-YYYY-MM', () => {
|
|
93
|
+
const customDateFormat = 'DD-YYYY-MM';
|
|
94
|
+
const { getByText } = render(<DateTime format="L" customFormat={customDateFormat} />);
|
|
95
|
+
expect(getByText(/\d{2}-\d{4}-\d{2}/)).toBeInTheDocument();
|
|
93
96
|
});
|
|
94
97
|
|
|
95
98
|
it('renders correctly with customFormat and modifier', () => {
|
|
96
|
-
const customFormat = 'MM-DD-YYYY';
|
|
97
99
|
const modifier = 'bold';
|
|
98
100
|
const { getByText } = render(
|
|
99
101
|
<DateTime format="L" customFormat={customFormat} modifier={modifier} />
|
|
@@ -102,4 +104,26 @@ describe('DateTime component', () => {
|
|
|
102
104
|
expect(dateElement).toBeInTheDocument();
|
|
103
105
|
expect(dateElement).toHaveClass('bold');
|
|
104
106
|
});
|
|
107
|
+
|
|
108
|
+
it('renders with prefix and suffix', () => {
|
|
109
|
+
const formattedDate = dayjs().format(customFormat);
|
|
110
|
+
const prefix = 'Start: ';
|
|
111
|
+
const suffix = ' End';
|
|
112
|
+
|
|
113
|
+
const { getByText } = render(
|
|
114
|
+
<DateTime format="L" customFormat={customFormat} prefix={prefix} suffix={suffix} />
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
expect(getByText(`${prefix}${formattedDate}${suffix}`)).toBeInTheDocument();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('renders only the date when prefix and suffix are not provided', () => {
|
|
121
|
+
const formattedDate = dayjs().format(customFormat);
|
|
122
|
+
|
|
123
|
+
const { getByText, queryByText } = render(<DateTime format="L" customFormat={customFormat} />);
|
|
124
|
+
|
|
125
|
+
expect(getByText(formattedDate)).toBeInTheDocument();
|
|
126
|
+
expect(queryByText('Start: ')).not.toBeInTheDocument();
|
|
127
|
+
expect(queryByText(' End')).not.toBeInTheDocument();
|
|
128
|
+
});
|
|
105
129
|
});
|
|
@@ -15,6 +15,10 @@ jest.mock('@blaze-cms/utils-handlebars', () => ({
|
|
|
15
15
|
useStringTemplate: jest.fn((parent, [title]) => ({ loading: false, data: [title] }))
|
|
16
16
|
}));
|
|
17
17
|
|
|
18
|
+
jest.mock('next/router', () => ({
|
|
19
|
+
useRouter: () => ({ asPath: '/' })
|
|
20
|
+
}));
|
|
21
|
+
|
|
18
22
|
const componentProps = {
|
|
19
23
|
id: 'id',
|
|
20
24
|
name: 'mock name',
|
|
@@ -7,8 +7,14 @@ import { render, fireEvent } from '@testing-library/react';
|
|
|
7
7
|
import '@testing-library/jest-dom/extend-expect';
|
|
8
8
|
import MenuRender from '../../../../../src/components/MenuItem/MenuItemRender';
|
|
9
9
|
|
|
10
|
+
let mockAsPathValue = '/';
|
|
11
|
+
|
|
12
|
+
jest.mock('next/router', () => ({
|
|
13
|
+
useRouter: () => ({ asPath: mockAsPathValue })
|
|
14
|
+
}));
|
|
15
|
+
|
|
10
16
|
jest.mock('@blaze-cms/utils-handlebars', () => ({
|
|
11
|
-
useStringTemplate: jest.fn((parent, [title]) => ({
|
|
17
|
+
useStringTemplate: jest.fn((parent, [title]) => ({ loading: false, data: [title] }))
|
|
12
18
|
}));
|
|
13
19
|
|
|
14
20
|
describe('MenuRender component', () => {
|
|
@@ -52,4 +58,26 @@ describe('MenuRender component', () => {
|
|
|
52
58
|
fireEvent.click(parentElement);
|
|
53
59
|
expect(childElement).toBeInTheDocument();
|
|
54
60
|
});
|
|
61
|
+
|
|
62
|
+
it('closes menu when asPath changes for hover event', () => {
|
|
63
|
+
const { getByText, container, rerender } = render(
|
|
64
|
+
<MenuRender eventType="hover" text="Parent">
|
|
65
|
+
<div data-testid="child">Child</div>
|
|
66
|
+
</MenuRender>
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
fireEvent.mouseEnter(getByText('Parent'));
|
|
70
|
+
let childContainer = container.querySelector('.menu--item-children');
|
|
71
|
+
expect(childContainer).not.toHaveClass('hidden');
|
|
72
|
+
|
|
73
|
+
mockAsPathValue = '/new-route';
|
|
74
|
+
rerender(
|
|
75
|
+
<MenuRender eventType="hover" text="Parent">
|
|
76
|
+
<div data-testid="child">Child</div>
|
|
77
|
+
</MenuRender>
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
childContainer = container.querySelector('.menu--item-children');
|
|
81
|
+
expect(childContainer).toHaveClass('hidden');
|
|
82
|
+
});
|
|
55
83
|
});
|