@lowdefy/blocks-antd 4.0.0-alpha.29 → 4.0.0-alpha.31

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.
Files changed (193) hide show
  1. package/dist/blocks/Affix/Affix.js +43 -0
  2. package/dist/blocks/Affix/schema.json +34 -0
  3. package/dist/blocks/Affix/style.less +17 -0
  4. package/dist/blocks/Alert/Alert.js +78 -0
  5. package/dist/blocks/Alert/schema.json +62 -0
  6. package/dist/blocks/Alert/style.less +17 -0
  7. package/dist/blocks/AutoComplete/AutoComplete.js +86 -0
  8. package/dist/blocks/AutoComplete/schema.json +148 -0
  9. package/dist/blocks/AutoComplete/style.less +17 -0
  10. package/dist/blocks/Avatar/Avatar.js +49 -0
  11. package/dist/blocks/Avatar/schema.json +71 -0
  12. package/dist/blocks/Avatar/style.less +17 -0
  13. package/dist/blocks/Badge/Badge.js +44 -0
  14. package/dist/blocks/Badge/schema.json +70 -0
  15. package/dist/blocks/Badge/style.less +17 -0
  16. package/dist/blocks/Breadcrumb/Breadcrumb.js +79 -0
  17. package/dist/blocks/Breadcrumb/schema.json +78 -0
  18. package/dist/blocks/Breadcrumb/style.less +17 -0
  19. package/dist/blocks/Button/Button.js +77 -0
  20. package/dist/blocks/Button/schema.json +91 -0
  21. package/dist/blocks/Button/style.less +17 -0
  22. package/dist/blocks/ButtonSelector/ButtonSelector.js +91 -0
  23. package/dist/blocks/ButtonSelector/schema.json +188 -0
  24. package/dist/blocks/ButtonSelector/style.less +18 -0
  25. package/dist/blocks/Card/Card.js +50 -0
  26. package/dist/blocks/Card/schema.json +58 -0
  27. package/dist/blocks/Card/style.less +17 -0
  28. package/dist/blocks/CheckboxSelector/CheckboxSelector.js +97 -0
  29. package/dist/blocks/CheckboxSelector/schema.json +193 -0
  30. package/dist/blocks/CheckboxSelector/style.less +19 -0
  31. package/dist/blocks/CheckboxSwitch/CheckboxSwitch.js +74 -0
  32. package/dist/blocks/CheckboxSwitch/schema.json +105 -0
  33. package/dist/blocks/CheckboxSwitch/style.less +19 -0
  34. package/dist/blocks/Collapse/Collapse.js +89 -0
  35. package/dist/blocks/Collapse/schema.json +90 -0
  36. package/dist/blocks/Collapse/style.less +17 -0
  37. package/dist/blocks/Comment/Comment.js +56 -0
  38. package/dist/blocks/Comment/schema.json +39 -0
  39. package/dist/blocks/Comment/style.less +18 -0
  40. package/dist/blocks/ConfirmModal/ConfirmModal.js +96 -0
  41. package/dist/blocks/ConfirmModal/schema.json +122 -0
  42. package/dist/blocks/ConfirmModal/style.less +17 -0
  43. package/dist/blocks/Content/Content.js +31 -0
  44. package/dist/blocks/Content/schema.json +16 -0
  45. package/dist/blocks/Content/style.less +17 -0
  46. package/dist/blocks/ControlledList/ControlledList.js +137 -0
  47. package/dist/blocks/ControlledList/schema.json +68 -0
  48. package/dist/blocks/ControlledList/style.less +19 -0
  49. package/dist/blocks/DateRangeSelector/DateRangeSelector.js +102 -0
  50. package/dist/blocks/DateRangeSelector/schema.json +221 -0
  51. package/dist/blocks/DateRangeSelector/style.less +18 -0
  52. package/dist/blocks/DateSelector/DateSelector.js +90 -0
  53. package/dist/blocks/DateSelector/schema.json +183 -0
  54. package/dist/blocks/DateSelector/style.less +18 -0
  55. package/dist/blocks/DateTimeSelector/DateTimeSelector.js +98 -0
  56. package/dist/blocks/DateTimeSelector/schema.json +215 -0
  57. package/dist/blocks/DateTimeSelector/style.less +18 -0
  58. package/dist/blocks/Descriptions/Descriptions.js +83 -0
  59. package/dist/blocks/Descriptions/schema.json +186 -0
  60. package/dist/blocks/Descriptions/style.less +17 -0
  61. package/dist/blocks/Divider/Divider.js +37 -0
  62. package/dist/blocks/Divider/schema.json +35 -0
  63. package/dist/blocks/Divider/style.less +17 -0
  64. package/dist/blocks/Drawer/Drawer.js +104 -0
  65. package/dist/blocks/Drawer/schema.json +113 -0
  66. package/dist/blocks/Drawer/style.less +17 -0
  67. package/dist/blocks/Footer/Footer.js +36 -0
  68. package/dist/blocks/Footer/schema.json +16 -0
  69. package/dist/blocks/Footer/style.less +17 -0
  70. package/dist/blocks/Header/Header.js +36 -0
  71. package/dist/blocks/Header/schema.json +22 -0
  72. package/dist/blocks/Header/style.less +17 -0
  73. package/dist/blocks/Label/Label.js +116 -0
  74. package/dist/blocks/Label/getLabelCol.js +55 -0
  75. package/dist/blocks/Label/getWrapperCol.js +69 -0
  76. package/dist/blocks/Label/labelLogic.js +106 -0
  77. package/dist/blocks/Label/schema.json +62 -0
  78. package/dist/blocks/Label/style.less +34 -0
  79. package/dist/blocks/Layout/Layout.js +30 -0
  80. package/dist/blocks/Layout/schema.json +16 -0
  81. package/dist/blocks/Layout/style.less +17 -0
  82. package/dist/blocks/Menu/Menu.js +209 -0
  83. package/dist/blocks/Menu/schema.json +236 -0
  84. package/dist/blocks/Menu/style.less +17 -0
  85. package/dist/blocks/Message/Message.js +53 -0
  86. package/dist/blocks/Message/schema.json +48 -0
  87. package/dist/blocks/Message/style.less +17 -0
  88. package/dist/blocks/MobileMenu/MobileMenu.js +128 -0
  89. package/dist/blocks/MobileMenu/schema.json +236 -0
  90. package/dist/blocks/MobileMenu/style.less +19 -0
  91. package/dist/blocks/Modal/Modal.js +130 -0
  92. package/dist/blocks/Modal/schema.json +118 -0
  93. package/dist/blocks/Modal/style.less +17 -0
  94. package/dist/blocks/MonthSelector/MonthSelector.js +90 -0
  95. package/dist/blocks/MonthSelector/schema.json +183 -0
  96. package/dist/blocks/MonthSelector/style.less +18 -0
  97. package/dist/blocks/MultipleSelector/MultipleSelector.js +146 -0
  98. package/dist/blocks/MultipleSelector/schema.json +239 -0
  99. package/dist/blocks/MultipleSelector/style.less +18 -0
  100. package/dist/blocks/Notification/Notification.js +77 -0
  101. package/dist/blocks/Notification/schema.json +85 -0
  102. package/dist/blocks/Notification/style.less +18 -0
  103. package/dist/blocks/NumberInput/NumberInput.js +82 -0
  104. package/dist/blocks/NumberInput/schema.json +157 -0
  105. package/dist/blocks/NumberInput/style.less +18 -0
  106. package/dist/blocks/PageHCF/PageHCF.js +70 -0
  107. package/dist/blocks/PageHCF/schema.json +64 -0
  108. package/dist/blocks/PageHCF/style.less +20 -0
  109. package/dist/blocks/PageHCSF/PageHCSF.js +98 -0
  110. package/dist/blocks/PageHCSF/schema.json +148 -0
  111. package/dist/blocks/PageHCSF/style.less +21 -0
  112. package/dist/blocks/PageHSCF/PageHSCF.js +98 -0
  113. package/dist/blocks/PageHSCF/schema.json +147 -0
  114. package/dist/blocks/PageHSCF/style.less +21 -0
  115. package/dist/blocks/PageHeaderMenu/PageHeaderMenu.js +302 -0
  116. package/dist/blocks/PageHeaderMenu/schema.json +215 -0
  117. package/dist/blocks/PageHeaderMenu/style.less +23 -0
  118. package/dist/blocks/PageSHCF/PageSHCF.js +98 -0
  119. package/dist/blocks/PageSHCF/schema.json +148 -0
  120. package/dist/blocks/PageSHCF/style.less +21 -0
  121. package/dist/blocks/PageSiderMenu/PageSiderMenu.js +409 -0
  122. package/dist/blocks/PageSiderMenu/schema.json +283 -0
  123. package/dist/blocks/PageSiderMenu/style.less +26 -0
  124. package/dist/blocks/Pagination/Pagination.js +98 -0
  125. package/dist/blocks/Pagination/schema.json +75 -0
  126. package/dist/blocks/Pagination/style.less +17 -0
  127. package/dist/blocks/Paragraph/Paragraph.js +102 -0
  128. package/dist/blocks/Paragraph/schema.json +131 -0
  129. package/dist/blocks/Paragraph/style.less +17 -0
  130. package/dist/blocks/ParagraphInput/ParagraphInput.js +125 -0
  131. package/dist/blocks/ParagraphInput/schema.json +162 -0
  132. package/dist/blocks/ParagraphInput/style.less +17 -0
  133. package/dist/blocks/PasswordInput/PasswordInput.js +78 -0
  134. package/dist/blocks/PasswordInput/schema.json +123 -0
  135. package/dist/blocks/PasswordInput/style.less +18 -0
  136. package/dist/blocks/Progress/Progress.js +42 -0
  137. package/dist/blocks/Progress/schema.json +76 -0
  138. package/dist/blocks/Progress/style.less +17 -0
  139. package/dist/blocks/RadioSelector/RadioSelector.js +96 -0
  140. package/dist/blocks/RadioSelector/schema.json +190 -0
  141. package/dist/blocks/RadioSelector/style.less +19 -0
  142. package/dist/blocks/RatingSlider/RatingSlider.js +240 -0
  143. package/dist/blocks/RatingSlider/schema.json +169 -0
  144. package/dist/blocks/RatingSlider/style.less +19 -0
  145. package/dist/blocks/Result/Result.js +48 -0
  146. package/dist/blocks/Result/schema.json +30 -0
  147. package/dist/blocks/Result/style.less +17 -0
  148. package/dist/blocks/Selector/Selector.js +140 -0
  149. package/dist/blocks/Selector/schema.json +236 -0
  150. package/dist/blocks/Selector/style.less +18 -0
  151. package/dist/blocks/Sider/Sider.js +85 -0
  152. package/dist/blocks/Sider/schema.json +71 -0
  153. package/dist/blocks/Sider/style.less +17 -0
  154. package/dist/blocks/Statistic/Statistic.js +51 -0
  155. package/dist/blocks/Statistic/schema.json +74 -0
  156. package/dist/blocks/Statistic/style.less +17 -0
  157. package/dist/blocks/Switch/Switch.js +101 -0
  158. package/dist/blocks/Switch/schema.json +136 -0
  159. package/dist/blocks/Switch/style.less +18 -0
  160. package/dist/blocks/Tabs/Tabs.js +108 -0
  161. package/dist/blocks/Tabs/schema.json +97 -0
  162. package/dist/blocks/Tabs/style.less +17 -0
  163. package/dist/blocks/TextArea/TextArea.js +87 -0
  164. package/dist/blocks/TextArea/schema.json +164 -0
  165. package/dist/blocks/TextArea/style.less +18 -0
  166. package/dist/blocks/TextInput/TextInput.js +92 -0
  167. package/dist/blocks/TextInput/schema.json +149 -0
  168. package/dist/blocks/TextInput/style.less +18 -0
  169. package/dist/blocks/TimelineList/TimelineList.js +102 -0
  170. package/dist/blocks/TimelineList/schema.json +65 -0
  171. package/dist/blocks/TimelineList/style.less +17 -0
  172. package/dist/blocks/Title/Title.js +109 -0
  173. package/dist/blocks/Title/schema.json +136 -0
  174. package/dist/blocks/Title/style.less +17 -0
  175. package/dist/blocks/TitleInput/TitleInput.js +122 -0
  176. package/dist/blocks/TitleInput/schema.json +171 -0
  177. package/dist/blocks/TitleInput/style.less +17 -0
  178. package/dist/blocks/Tooltip/Tooltip.js +48 -0
  179. package/dist/blocks/Tooltip/schema.json +91 -0
  180. package/dist/blocks/Tooltip/style.less +17 -0
  181. package/dist/blocks/WeekSelector/WeekSelector.js +91 -0
  182. package/dist/blocks/WeekSelector/schema.json +183 -0
  183. package/dist/blocks/WeekSelector/style.less +18 -0
  184. package/dist/blocks.js +74 -0
  185. package/dist/color.js +85 -0
  186. package/dist/disabledDate.js +45 -0
  187. package/dist/getUniqueValues.js +30 -0
  188. package/dist/getValueIndex.js +42 -0
  189. package/dist/style.less +17 -0
  190. package/dist/types.js +31 -0
  191. package/dist/useRunAfterUpdate.js +29 -0
  192. package/dist/validationExamples.js +40 -0
  193. package/package.json +9 -9
@@ -0,0 +1,106 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { type } from '@lowdefy/helpers';
16
+ import classNames from 'classnames';
17
+ import getWrapperCol from './getWrapperCol.js';
18
+ import getLabelCol from './getLabelCol.js';
19
+ const labelLogic = ({ blockId , content , methods , properties ={} , required =false , validation ={
20
+ messages: [],
21
+ status: null
22
+ } , })=>{
23
+ const wrapperCol = getWrapperCol(properties, properties.inline);
24
+ const labelCol = getLabelCol(properties, properties.inline);
25
+ // render label priority order: content.label area -> properties.title -> blockId and do not render an empty label
26
+ let label = content.label ? content.label() : !type.isString(properties.title) ? blockId : properties.title;
27
+ label = label === '' ? null : label;
28
+ // trim colon when colon is set, and the user inputs a colon, because antd class renders a colon
29
+ if (type.isString(label) && properties.colon && label.trim() !== '') {
30
+ label = label.replace(/[:|:]\s*$/, '');
31
+ }
32
+ const rowClassName = classNames({
33
+ [`ant-form-item`]: true,
34
+ [`ant-form-item-with-help`]: false,
35
+ [methods.makeCssClass({
36
+ flexWrap: properties.inline && 'inherit',
37
+ marginBottom: 0
38
+ })]: true
39
+ });
40
+ const labelColClassName = classNames({
41
+ [`ant-form-item-label`]: true,
42
+ [`ant-form-item-label-left`]: properties.align === 'left' || !properties.align,
43
+ [methods.makeCssClass({
44
+ overflow: properties.inline && 'inherit',
45
+ whiteSpace: !properties.inline && 'normal',
46
+ marginBottom: properties.size === 'small' ? 0 : 8
47
+ })]: true
48
+ });
49
+ const labelClassName = classNames({
50
+ [`ant-form-item-required`]: required,
51
+ [`ant-form-item-no-colon`]: properties.colon === false,
52
+ [methods.makeCssClass([
53
+ {
54
+ height: 'fit-content !important',
55
+ minHeight: properties.inline && (properties.size === 'large' ? 40 : properties.size === 'small' ? 24 : 32)
56
+ },
57
+ properties.style,
58
+ ])]: true
59
+ });
60
+ const extraClassName = classNames({
61
+ 'ant-form-item-explain': true,
62
+ 'ant-form-item-extra': true,
63
+ [methods.makeCssClass([
64
+ {
65
+ marginTop: properties.size === 'small' ? -4 : 0
66
+ },
67
+ properties.extraStyle,
68
+ ])]: true
69
+ });
70
+ const feedbackClassName = classNames({
71
+ [`ant-form-item-explain-success`]: validation.status === 'success',
72
+ [`ant-form-item-explain-warning`]: validation.status === 'warning',
73
+ [`ant-form-item-explain-error`]: validation.status === 'error',
74
+ [`ant-form-item-explain-validating`]: validation.status === 'validating',
75
+ [methods.makeCssClass([
76
+ {
77
+ marginTop: properties.size === 'small' ? -4 : 0
78
+ },
79
+ properties.feedbackStyle,
80
+ ])]: true
81
+ });
82
+ const iconClassName = classNames({
83
+ 'ant-form-item-feedback-icon': true,
84
+ [`ant-form-item-feedback-icon-success`]: validation.status === 'success',
85
+ [`ant-form-item-feedback-icon-warning`]: validation.status === 'warning',
86
+ [`ant-form-item-feedback-icon-error`]: validation.status === 'error',
87
+ [`ant-form-item-feedback-icon-validating`]: validation.status === 'validating',
88
+ 'ldf-feedback-icon': true
89
+ });
90
+ const showExtra = !!properties.extra && (!validation.status || validation.status === 'success');
91
+ const showFeedback = validation.status === 'warning' || validation.status === 'error';
92
+ return {
93
+ extraClassName,
94
+ feedbackClassName,
95
+ iconClassName,
96
+ label: !properties.disabled && label,
97
+ labelClassName,
98
+ labelCol,
99
+ labelColClassName,
100
+ rowClassName,
101
+ showExtra,
102
+ showFeedback,
103
+ wrapperCol
104
+ };
105
+ };
106
+ export default labelLogic;
@@ -0,0 +1,62 @@
1
+ {
2
+ "type": "object",
3
+ "properties": {
4
+ "type": "object",
5
+ "additionalProperties": false,
6
+ "properties": {
7
+ "align": {
8
+ "type": "string",
9
+ "enum": ["left", "right"],
10
+ "default": "left",
11
+ "description": "Align label left or right when inline."
12
+ },
13
+ "colon": {
14
+ "type": "boolean",
15
+ "default": true,
16
+ "description": "Append label with colon."
17
+ },
18
+ "disabled": {
19
+ "type": "boolean",
20
+ "default": false,
21
+ "description": "Disable to not render a label title."
22
+ },
23
+ "extra": {
24
+ "type": "string",
25
+ "description": "Extra text to display beneath the content - supports html."
26
+ },
27
+ "size": {
28
+ "type": "string",
29
+ "enum": ["small", "default", "large"],
30
+ "default": "default",
31
+ "description": "Size of the block."
32
+ },
33
+ "title": {
34
+ "type": "string",
35
+ "description": "Label title - supports html."
36
+ },
37
+ "extraStyle": {
38
+ "type": "object",
39
+ "description": "Css style to applied to label extra.",
40
+ "docs": {
41
+ "displayType": "yaml"
42
+ }
43
+ },
44
+ "feedbackStyle": {
45
+ "type": "object",
46
+ "description": "Css style to applied to label feedback.",
47
+ "docs": {
48
+ "displayType": "yaml"
49
+ }
50
+ },
51
+ "span": {
52
+ "type": "number",
53
+ "description": "Label inline span."
54
+ },
55
+ "inline": {
56
+ "type": "boolean",
57
+ "default": false,
58
+ "description": "Render input and label inline."
59
+ }
60
+ }
61
+ }
62
+ }
@@ -0,0 +1,34 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ @import 'antd/lib/form/style/index.less';
18
+
19
+ .ant-form-vertical .ant-form-item-label > label::after,
20
+ .ant-form-item .ant-form-item-label > label::after,
21
+ .ant-col-24.ant-form-item-label > label::after,
22
+ .ant-col-xl-24.ant-form-item-label > label::after,
23
+ .ant-col-lg-24.ant-form-item-label > label::after,
24
+ .ant-col-md-24.ant-form-item-label > label::after,
25
+ .ant-col-sm-24.ant-form-item-label > label::after {
26
+ display: block !important;
27
+ }
28
+ .ant-input-affix-wrapper {
29
+ height: 100% !important;
30
+ }
31
+
32
+ .ldf-feedback-icon {
33
+ margin-left: @margin-xss;
34
+ }
@@ -0,0 +1,30 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import React from 'react';
16
+ import { blockDefaultProps } from '@lowdefy/block-utils';
17
+ import { Layout } from 'antd';
18
+ const LayoutBlock = ({ blockId , content , properties , methods })=>/*#__PURE__*/ React.createElement(Layout, {
19
+ id: blockId,
20
+ className: methods.makeCssClass(properties.style)
21
+ }, content.content && content.content());
22
+ LayoutBlock.defaultProps = blockDefaultProps;
23
+ LayoutBlock.meta = {
24
+ category: 'container',
25
+ icons: [],
26
+ styles: [
27
+ 'blocks/Layout/style.less'
28
+ ]
29
+ };
30
+ export default LayoutBlock;
@@ -0,0 +1,16 @@
1
+ {
2
+ "type": "object",
3
+ "properties": {
4
+ "type": "object",
5
+ "additionalProperties": false,
6
+ "properties": {
7
+ "style": {
8
+ "type": "object",
9
+ "description": "Css style object to applied to layout.",
10
+ "docs": {
11
+ "displayType": "yaml"
12
+ }
13
+ }
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,17 @@
1
+ /*
2
+ Copyright 2020-2022 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+
17
+ @import 'antd/lib/layout/style/index.less';
@@ -0,0 +1,209 @@
1
+ function _extends() {
2
+ _extends = Object.assign || function(target) {
3
+ for(var i = 1; i < arguments.length; i++){
4
+ var source = arguments[i];
5
+ for(var key in source){
6
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
7
+ target[key] = source[key];
8
+ }
9
+ }
10
+ }
11
+ return target;
12
+ };
13
+ return _extends.apply(this, arguments);
14
+ }
15
+ /*
16
+ Copyright 2020-2022 Lowdefy, Inc
17
+
18
+ Licensed under the Apache License, Version 2.0 (the "License");
19
+ you may not use this file except in compliance with the License.
20
+ You may obtain a copy of the License at
21
+
22
+ http://www.apache.org/licenses/LICENSE-2.0
23
+
24
+ Unless required by applicable law or agreed to in writing, software
25
+ distributed under the License is distributed on an "AS IS" BASIS,
26
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27
+ See the License for the specific language governing permissions and
28
+ limitations under the License.
29
+ */ import React from 'react';
30
+ import { blockDefaultProps } from '@lowdefy/block-utils';
31
+ import { Menu } from 'antd';
32
+ import { type, get } from '@lowdefy/helpers';
33
+ const getDefaultMenu = (menus, menuId = 'default', links)=>{
34
+ if (type.isArray(links)) return links;
35
+ if (!type.isArray(menus)) return [];
36
+ const menu = (menus.find((item)=>item.menuId === menuId) ?? menus[0]) ?? {};
37
+ return menu.links ?? [];
38
+ };
39
+ const getTitle = ({ id , properties , pageId , url })=>(((properties && properties.title) ?? pageId) ?? url) ?? id;
40
+ const MenuComp = ({ blockId , components: { Icon , Link } , events , menus , methods , pageId , properties , rename , })=>{
41
+ const styles = {
42
+ lineHeight: '64px',
43
+ width: '100%',
44
+ display: properties.mode === 'horizontal' && 'inline-block'
45
+ };
46
+ const exProps = {};
47
+ if (properties.mode === 'inline') {
48
+ exProps.collapsed = properties.collapsed;
49
+ exProps.inlineIndent = properties.inlineIndent;
50
+ }
51
+ const menu = getDefaultMenu(menus, properties.menuId, properties.links);
52
+ const theme = properties.theme ?? 'dark';
53
+ return /*#__PURE__*/ React.createElement(Menu, _extends({
54
+ id: blockId,
55
+ expandIcon: properties.expandIcon && /*#__PURE__*/ React.createElement(Icon, {
56
+ blockId: `${blockId}_expandIcon`,
57
+ events: events,
58
+ properties: properties.expandIcon
59
+ }),
60
+ forceSubMenuRender: properties.forceSubMenuRender,
61
+ mode: properties.mode,
62
+ selectable: true,
63
+ theme: theme,
64
+ className: methods.makeCssClass([
65
+ styles,
66
+ properties.style
67
+ ]),
68
+ defaultOpenKeys: (properties.defaultOpenKeys ?? (properties.mode === 'inline' && properties.collapsed !== true && [
69
+ (menu.find((link1)=>(link1.links || []).map((subLink)=>subLink.links ? subLink.links.map((subSubLink)=>subSubLink.pageId) : [
70
+ subLink.pageId
71
+ ]).flat().some((link)=>(properties.selectedKeys ?? [
72
+ pageId
73
+ ]).indexOf(link) !== -1)) ?? {}).id,
74
+ ])) ?? [],
75
+ selectedKeys: properties.selectedKeys ?? [
76
+ pageId
77
+ ],
78
+ subMenuCloseDelay: properties.subMenuCloseDelay,
79
+ subMenuOpenDelay: properties.subMenuOpenDelay,
80
+ onSelect: (item)=>methods.triggerEvent({
81
+ name: get(rename, 'events.onSelect', {
82
+ default: 'onSelect'
83
+ }),
84
+ event: {
85
+ key: item.key
86
+ }
87
+ }),
88
+ onClick: (item)=>methods.triggerEvent({
89
+ name: get(rename, 'events.onClick', {
90
+ default: 'onClick'
91
+ }),
92
+ event: {
93
+ key: item.key
94
+ }
95
+ }),
96
+ onOpenChange: (openKeys)=>methods.triggerEvent({
97
+ name: get(rename, 'events.onToggleMenuGroup', {
98
+ default: 'onToggleMenuGroup'
99
+ }),
100
+ event: {
101
+ openKeys
102
+ }
103
+ })
104
+ }, exProps), menu.map((link, i)=>{
105
+ switch(link.type){
106
+ case 'MenuDivider':
107
+ return /*#__PURE__*/ React.createElement(Menu.Divider, {
108
+ key: link.id,
109
+ className: methods.makeCssClass([
110
+ link.style
111
+ ]),
112
+ dashed: link.properties && link.properties.dashed
113
+ });
114
+ case 'MenuGroup':
115
+ return /*#__PURE__*/ React.createElement(Menu.SubMenu, {
116
+ key: link.pageId ?? link.id,
117
+ title: /*#__PURE__*/ React.createElement(Link, _extends({
118
+ id: (link.pageId ?? link.id) ?? i,
119
+ className: methods.makeCssClass(link.style, true)
120
+ }, link), getTitle(link)),
121
+ icon: link.properties && link.properties.icon && /*#__PURE__*/ React.createElement(Icon, {
122
+ blockId: `${link.id}_icon`,
123
+ events: events,
124
+ properties: link.properties.icon
125
+ })
126
+ }, get(link, 'links', {
127
+ default: []
128
+ }).map((subLink, j)=>{
129
+ switch(subLink.type){
130
+ case 'MenuDivider':
131
+ return /*#__PURE__*/ React.createElement(Menu.Divider, {
132
+ key: subLink.id ?? j,
133
+ className: methods.makeCssClass([
134
+ subLink.style
135
+ ]),
136
+ dashed: subLink.properties && subLink.properties.dashed
137
+ });
138
+ case 'MenuGroup':
139
+ return /*#__PURE__*/ React.createElement(Menu.ItemGroup, {
140
+ key: subLink.pageId ?? subLink.id,
141
+ title: /*#__PURE__*/ React.createElement(Link, _extends({
142
+ id: (subLink.pageId ?? subLink.id) ?? j,
143
+ className: methods.makeCssClass(subLink.style, true)
144
+ }, subLink), getTitle(subLink))
145
+ }, subLink.links.map((subLinkGroup, k)=>{
146
+ if (subLinkGroup.type === 'MenuDivider') {
147
+ return /*#__PURE__*/ React.createElement(Menu.Divider, {
148
+ key: `${subLink.id}_${k}`,
149
+ className: methods.makeCssClass([
150
+ subLink.style
151
+ ]),
152
+ dashed: subLink.properties && subLink.properties.dashed
153
+ });
154
+ }
155
+ return /*#__PURE__*/ React.createElement(Menu.Item, {
156
+ key: subLinkGroup.pageId ?? subLinkGroup.id,
157
+ danger: get(subLinkGroup, 'properties.danger'),
158
+ icon: subLinkGroup.properties && subLinkGroup.properties.icon && /*#__PURE__*/ React.createElement(Icon, {
159
+ blockId: `${subLinkGroup.id}_icon`,
160
+ events: events,
161
+ properties: subLinkGroup.properties.icon
162
+ })
163
+ }, /*#__PURE__*/ React.createElement(Link, _extends({
164
+ id: (subLinkGroup.pageId ?? subLinkGroup.id) ?? k,
165
+ className: methods.makeCssClass(subLinkGroup.style, true)
166
+ }, subLinkGroup), getTitle(subLinkGroup)));
167
+ }));
168
+ case 'MenuLink':
169
+ default:
170
+ return /*#__PURE__*/ React.createElement(Menu.Item, {
171
+ key: subLink.pageId ?? subLink.id,
172
+ danger: get(subLink, 'properties.danger'),
173
+ icon: subLink.properties && subLink.properties.icon && /*#__PURE__*/ React.createElement(Icon, {
174
+ blockId: `${subLink.id}_icon`,
175
+ events: events,
176
+ properties: subLink.properties.icon
177
+ })
178
+ }, /*#__PURE__*/ React.createElement(Link, _extends({
179
+ id: (subLink.pageId ?? subLink.id) ?? j,
180
+ className: methods.makeCssClass(subLink.style, true)
181
+ }, subLink), getTitle(subLink)));
182
+ }
183
+ }));
184
+ case 'MenuLink':
185
+ default:
186
+ return /*#__PURE__*/ React.createElement(Menu.Item, {
187
+ key: link.pageId ?? link.id,
188
+ danger: get(link, 'properties.danger'),
189
+ icon: link.properties && link.properties.icon && /*#__PURE__*/ React.createElement(Icon, {
190
+ blockId: `${link.id}_icon`,
191
+ events: events,
192
+ properties: link.properties.icon
193
+ })
194
+ }, /*#__PURE__*/ React.createElement(Link, _extends({
195
+ id: (link.pageId ?? link.id) ?? i,
196
+ className: methods.makeCssClass(link.style, true)
197
+ }, link), getTitle(link)));
198
+ }
199
+ }));
200
+ };
201
+ MenuComp.defaultProps = blockDefaultProps;
202
+ MenuComp.meta = {
203
+ category: 'display',
204
+ icons: [],
205
+ styles: [
206
+ 'blocks/Menu/style.less'
207
+ ]
208
+ };
209
+ export default MenuComp;