@bigbinary/neeto-molecules 1.6.12 → 1.7.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/Builder.js CHANGED
@@ -1,11 +1,12 @@
1
1
  import React, { useState, useMemo, memo, useRef, useEffect } from 'react';
2
+ import classnames from 'classnames';
2
3
  import { noop, isPresent, isNotEmpty, findById, hyphenate } from '@bigbinary/neeto-cist';
4
+ import { useBreakpoints } from '@bigbinary/neeto-commons-frontend/react-utils';
5
+ import { Search, MenuVertical, MenuHorizontal, Flash, Collapse, DownArrow, Close } from '@bigbinary/neeto-icons';
6
+ import { Typography, Button, Input, Dropdown, Tooltip } from '@bigbinary/neetoui';
3
7
  import { isEmpty, mergeRight } from 'ramda';
4
8
  import { joinHyphenCase, withEventTargetValue } from '@bigbinary/neeto-commons-frontend/utils/general';
5
- import { Search, MenuVertical, MenuHorizontal, Flash, DownArrow } from '@bigbinary/neeto-icons';
6
- import { Typography, Button, Input, Dropdown, Tooltip } from '@bigbinary/neetoui';
7
9
  import { useTranslation } from 'react-i18next';
8
- import classnames from 'classnames';
9
10
  import { DragDropContext, Droppable, Draggable } from '@hello-pangea/dnd';
10
11
  import { PLURAL } from '@bigbinary/neeto-commons-frontend/constants';
11
12
  import withT from '@bigbinary/neeto-commons-frontend/react-utils/withT';
@@ -106,18 +107,6 @@ function _defineProperty(obj, key, value) {
106
107
  return obj;
107
108
  }
108
109
 
109
- var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
110
-
111
- var css = ":root{--neeto-molecule-builder-left-sidebar-width:360px;--neeto-molecule-builder-left-sidebar-header-height:70px;--neeto-molecule-builder-left-sidebar-search-height:40px;--neeto-molecule-builder-right-sidebar-width:420px}.neeto-molecules-builder-elements-list-panel{height:100%;min-width:360px;min-width:var(--neeto-molecule-builder-left-sidebar-width);width:360px;width:var(--neeto-molecule-builder-left-sidebar-width)}.neeto-molecules-builder-questions-list-panel__scroll{height:calc(100% - 70px);height:calc(100% - var(--neeto-molecule-builder-left-sidebar-header-height));overflow-y:auto;padding:8px 24px}.neeto-molecules-builder-questions-list-panel__scroll.neeto-molecules-builder-questions-list-panel__scroll--small{height:calc(100% - 110px);height:calc(100% - var(--neeto-molecule-builder-left-sidebar-header-height) - var(--neeto-molecule-builder-left-sidebar-search-height))}.neeto-molecules-builder-elements-list{margin-bottom:24px}.neeto-molecules-builder-elements-list .neeto-ui-accordion__wrapper{border-bottom:none}.neeto-molecules-builder-elements-list .neeto-ui-accordion__wrapper .neeto-ui-accordion__item{padding:12px 0}.neeto-molecules-builder-elements-list .neeto-ui-accordion__wrapper .neeto-ui-accordion__item .neeto-ui-accordion__item-handle{color:rgb(var(--neeto-ui-gray-600));font-size:var(--neeto-ui-text-xs);font-weight:var(--neeto-ui-font-semibold);text-transform:uppercase;transition:var(--neeto-ui-transition)}.neeto-molecules-builder-elements-list .neeto-ui-accordion__wrapper .neeto-ui-accordion__item .neeto-ui-accordion__item-toggle-icon{transform:rotate(90deg)!important}.neeto-molecules-builder-elements-list .neeto-ui-accordion__wrapper .neeto-ui-accordion__item:hover{background-color:transparent}.neeto-molecules-builder-elements-list .neeto-ui-accordion__wrapper .neeto-ui-accordion__item.neeto-ui-accordion__item--open .neeto-ui-accordion__item-handle,.neeto-molecules-builder-elements-list .neeto-ui-accordion__wrapper .neeto-ui-accordion__item:hover .neeto-ui-accordion__item-handle{color:rgb(var(--neeto-ui-gray-800))}.neeto-molecules-builder-elements-list .neeto-ui-accordion__wrapper .neeto-ui-accordion__item.neeto-ui-accordion__item--open .neeto-ui-accordion__item-toggle-icon{transform:rotate(270deg)!important}.neeto-molecules-builder-elements-list .neeto-ui-accordion__wrapper .neeto-ui-accordion__drop{padding:0}.neeto-molecules-builder-element-properties-panel{height:100%;min-width:420px;min-width:var(--neeto-molecule-builder-right-sidebar-width);padding-left:24px;padding-top:24px;width:420px;width:var(--neeto-molecule-builder-right-sidebar-width)}.neeto-molecules-builder-element--active{border-color:rgb(var(--neeto-ui-primary-500))!important;box-shadow:0 0 0 1px rgb(var(--neeto-ui-primary-500))!important}";
112
- n(css,{});
113
-
114
- var Body = function Body(props) {
115
- return /*#__PURE__*/React.createElement("div", {
116
- className: "neeto-molecules-builder-questions-list-panel__scroll neeto-molecules-builder-questions-list-panel__scroll--small",
117
- "data-testid": props["data-testid"]
118
- }, props.children);
119
- };
120
-
121
110
  function _extends() {
122
111
  _extends = Object.assign ? Object.assign.bind() : function (target) {
123
112
  for (var i = 1; i < arguments.length; i++) {
@@ -133,6 +122,51 @@ function _extends() {
133
122
  return _extends.apply(this, arguments);
134
123
  }
135
124
 
125
+ function _objectWithoutPropertiesLoose(source, excluded) {
126
+ if (source == null) return {};
127
+ var target = {};
128
+ var sourceKeys = Object.keys(source);
129
+ var key, i;
130
+ for (i = 0; i < sourceKeys.length; i++) {
131
+ key = sourceKeys[i];
132
+ if (excluded.indexOf(key) >= 0) continue;
133
+ target[key] = source[key];
134
+ }
135
+ return target;
136
+ }
137
+
138
+ function _objectWithoutProperties(source, excluded) {
139
+ if (source == null) return {};
140
+ var target = _objectWithoutPropertiesLoose(source, excluded);
141
+ var key, i;
142
+ if (Object.getOwnPropertySymbols) {
143
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
144
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
145
+ key = sourceSymbolKeys[i];
146
+ if (excluded.indexOf(key) >= 0) continue;
147
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
148
+ target[key] = source[key];
149
+ }
150
+ }
151
+ return target;
152
+ }
153
+
154
+ var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
155
+
156
+ var css = ":root{--neeto-molecule-builder-left-sidebar-width:288px;--neeto-molecule-builder-left-sidebar-width-lg:360px;--neeto-molecule-builder-left-sidebar-header-height:70px;--neeto-molecule-builder-left-sidebar-search-height:40px;--neeto-molecule-builder-right-sidebar-width:420px}.neeto-molecules-builder-elements-list-panel__wrapper{height:100%;min-width:360px;min-width:var(--neeto-molecule-builder-left-sidebar-width-lg);position:relative;transition:all .15s;width:360px;width:var(--neeto-molecule-builder-left-sidebar-width-lg);z-index:101}@media screen and (min-width:768px) and (max-width:1279px){.neeto-molecules-builder-elements-list-panel__wrapper{min-width:288px;min-width:var(--neeto-molecule-builder-left-sidebar-width);width:288px;width:var(--neeto-molecule-builder-left-sidebar-width)}}@media screen and (max-width:767px){.neeto-molecules-builder-elements-list-panel__wrapper{left:0;position:fixed;top:0;transition:none}}@media screen and (max-width:576px){.neeto-molecules-builder-elements-list-panel__wrapper{height:100%;max-width:100%;min-width:0;width:100%}}.neeto-molecules-builder-elements-list-panel__wrapper--collapsed{max-width:0;min-width:0;width:0}.neeto-molecules-builder-elements-list-panel__wrapper--collapsed .neeto-molecules-builder-elements-list-panel__toggler{transform:scale(-1)}@media screen and (max-width:767px){.neeto-molecules-builder-elements-list-panel__wrapper--collapsed .neeto-molecules-builder-elements-list-panel__toggler{top:72px}}@media screen and (max-width:576px){.neeto-molecules-builder-elements-list-panel__wrapper--collapsed .neeto-molecules-builder-elements-list-panel__toggler{left:8px;right:auto}}.neeto-molecules-builder-elements-list-panel__container{height:100%;overflow:hidden;width:100%}.neeto-molecules-builder-elements-list-panel{height:100%;min-width:360px;min-width:var(--neeto-molecule-builder-left-sidebar-width-lg);width:360px;width:var(--neeto-molecule-builder-left-sidebar-width-lg)}@media screen and (min-width:768px) and (max-width:1279px){.neeto-molecules-builder-elements-list-panel{min-width:288px;min-width:var(--neeto-molecule-builder-left-sidebar-width);width:288px;width:var(--neeto-molecule-builder-left-sidebar-width)}}@media screen and (max-width:576px){.neeto-molecules-builder-elements-list-panel{padding-top:24px;width:100%}}.neeto-molecules-builder-elements-list-panel__toggler{flex-shrink:0;left:calc(100% + 8px);position:absolute;top:8px;transition:color .3s ease-in-out}@media screen and (min-width:1024px){.neeto-molecules-builder-elements-list-panel__toggler{opacity:0;pointer-events:none}}@media screen and (max-width:576px){.neeto-molecules-builder-elements-list-panel__toggler{left:24px}}.neeto-molecules-builder-questions-list-panel__scroll{height:calc(100% - 70px);height:calc(100% - var(--neeto-molecule-builder-left-sidebar-header-height));overflow-y:auto;padding:8px 24px;width:100%}.neeto-molecules-builder-questions-list-panel__scroll.neeto-molecules-builder-questions-list-panel__scroll--small{height:calc(100% - 110px);height:calc(100% - var(--neeto-molecule-builder-left-sidebar-header-height) - var(--neeto-molecule-builder-left-sidebar-search-height))}.neeto-molecules-builder-element-properties-panel__wrapper{height:100%;min-width:420px;min-width:var(--neeto-molecule-builder-right-sidebar-width);position:relative;transition:all .15s;width:420px;width:var(--neeto-molecule-builder-right-sidebar-width);z-index:101}.neeto-molecules-builder-element-properties-panel__wrapper .neeto-molecules-builder-properties-panel__close{opacity:0;pointer-events:none;position:absolute;right:8px;top:8px}@media screen and (max-width:1279px){.neeto-molecules-builder-element-properties-panel__wrapper .neeto-molecules-builder-properties-panel__close{opacity:1;pointer-events:all}.neeto-molecules-builder-element-properties-panel__wrapper{position:fixed;right:0;top:0;transition:none}}@media screen and (max-width:576px){.neeto-molecules-builder-element-properties-panel__wrapper{height:100%;max-width:100%;min-width:0;width:100%}}.neeto-molecules-builder-element-properties-panel__wrapper--collapsed{max-width:0;min-width:0;width:0}.neeto-molecules-builder-element-properties-panel{display:flex;flex-direction:column;height:100%;min-width:0;overflow-y:auto;padding-left:24px;padding-top:24px;width:100%}.neeto-molecules-builder-element-properties-panel--collapsed{max-width:0;min-width:0;padding:0;width:0}@media screen and (max-width:1279px){.neeto-molecules-builder-element-properties-panel{padding-top:48px}}.neeto-molecules-builder-element--active{border-color:rgb(var(--neeto-ui-primary-500))!important;box-shadow:0 0 0 1px rgb(var(--neeto-ui-primary-500))!important}.neeto-molecules-builder-panel__backdrop{background-color:rgba(var(--neeto-ui-black),.4);display:none;height:100%;left:0;position:fixed;top:0;visibility:hidden;width:100%;z-index:101}@media screen and (max-width:767px){.neeto-molecules-builder-panel__backdrop{display:block;visibility:visible}}@media screen and (max-width:1279px){.neeto-molecules-builder-panel__backdrop--extended{display:block;visibility:visible}}";
157
+ n(css,{});
158
+
159
+ var _excluded$4 = ["size"];
160
+ var Body = function Body(_ref) {
161
+ var size = _ref.size,
162
+ props = _objectWithoutProperties(_ref, _excluded$4);
163
+ return /*#__PURE__*/React.createElement("div", _extends({}, props, {
164
+ className: classnames("neeto-molecules-builder-questions-list-panel__scroll", {
165
+ "neeto-molecules-builder-questions-list-panel__scroll--small": size === "small"
166
+ })
167
+ }));
168
+ };
169
+
136
170
  var Element = function Element(_ref) {
137
171
  var label = _ref.label,
138
172
  Icon = _ref.icon,
@@ -241,9 +275,8 @@ var ElementList = function ElementList(_ref) {
241
275
  value: searchString,
242
276
  onChange: withEventTargetValue(setSearchString)
243
277
  })), /*#__PURE__*/React.createElement(Body, {
244
- "data-testid": "elements-container"
245
- }, /*#__PURE__*/React.createElement("div", {
246
- className: "neeto-molecules-builder-questions-list-panel__scroll--small"
278
+ "data-testid": "elements-container",
279
+ size: "small"
247
280
  }, filteredSections.map(function (section) {
248
281
  return /*#__PURE__*/React.createElement(Section, {
249
282
  onSelect: onSelect,
@@ -252,38 +285,9 @@ var ElementList = function ElementList(_ref) {
252
285
  key: section.key,
253
286
  title: section.title
254
287
  });
255
- }))));
288
+ })));
256
289
  };
257
290
 
258
- function _objectWithoutPropertiesLoose(source, excluded) {
259
- if (source == null) return {};
260
- var target = {};
261
- var sourceKeys = Object.keys(source);
262
- var key, i;
263
- for (i = 0; i < sourceKeys.length; i++) {
264
- key = sourceKeys[i];
265
- if (excluded.indexOf(key) >= 0) continue;
266
- target[key] = source[key];
267
- }
268
- return target;
269
- }
270
-
271
- function _objectWithoutProperties(source, excluded) {
272
- if (source == null) return {};
273
- var target = _objectWithoutPropertiesLoose(source, excluded);
274
- var key, i;
275
- if (Object.getOwnPropertySymbols) {
276
- var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
277
- for (i = 0; i < sourceSymbolKeys.length; i++) {
278
- key = sourceSymbolKeys[i];
279
- if (excluded.indexOf(key) >= 0) continue;
280
- if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
281
- target[key] = source[key];
282
- }
283
- }
284
- return target;
285
- }
286
-
287
291
  var MENU_ITEM_TYPES = {
288
292
  menuItem: "menuItem",
289
293
  divider: "divider"
@@ -633,13 +637,34 @@ var ElementsPanel = function ElementsPanel(_ref) {
633
637
  _useState2 = _slicedToArray(_useState, 2),
634
638
  isElementsListVisible = _useState2[0],
635
639
  setIsElementsListVisible = _useState2[1];
640
+ var _useBreakpoints = useBreakpoints(),
641
+ isSize = _useBreakpoints.isSize;
642
+ var isLargerScreen = !isSize("mobile");
643
+ var _useState3 = useState(!isLargerScreen),
644
+ _useState4 = _slicedToArray(_useState3, 2),
645
+ isElementsPanelCollapsed = _useState4[0],
646
+ setIsElementsPanelCollapsed = _useState4[1];
636
647
  var isSelectedElementsEmpty = isEmpty(selectedElements);
637
648
  var shouldShowElementsList = isSelectedElementsEmpty || isElementsListVisible;
638
649
  var handleElementSelect = function handleElementSelect(element) {
639
650
  setIsElementsListVisible(false);
640
651
  handleAddElement(element);
641
652
  };
642
- return /*#__PURE__*/React.createElement("div", {
653
+ useEffect(function () {
654
+ setIsElementsPanelCollapsed(!isLargerScreen);
655
+ }, [isLargerScreen]);
656
+ return /*#__PURE__*/React.createElement(React.Fragment, null, !isElementsPanelCollapsed && /*#__PURE__*/React.createElement("div", {
657
+ className: "neeto-molecules-builder-panel__backdrop",
658
+ onClick: function onClick() {
659
+ setIsElementsPanelCollapsed(!isElementsPanelCollapsed);
660
+ }
661
+ }), /*#__PURE__*/React.createElement("div", {
662
+ className: classnames("neeto-molecules-builder-elements-list-panel__wrapper", {
663
+ "neeto-molecules-builder-elements-list-panel__wrapper--collapsed": isElementsPanelCollapsed
664
+ })
665
+ }, /*#__PURE__*/React.createElement("div", {
666
+ className: "neeto-molecules-builder-elements-list-panel__container"
667
+ }, /*#__PURE__*/React.createElement("div", {
643
668
  className: "neeto-molecules-builder-elements-list-panel neeto-ui-bg-gray-100",
644
669
  onClick: function onClick(event) {
645
670
  return event.stopPropagation();
@@ -666,13 +691,20 @@ var ElementsPanel = function ElementsPanel(_ref) {
666
691
  selectedElements: selectedElements,
667
692
  setIsElementsListVisible: setIsElementsListVisible,
668
693
  showElementsFillButton: showElementsFillButton
669
- }));
694
+ }))), /*#__PURE__*/React.createElement(Button, {
695
+ className: "neeto-molecules-builder-elements-list-panel__toggler",
696
+ icon: Collapse,
697
+ style: "secondary",
698
+ onClick: function onClick() {
699
+ setIsElementsPanelCollapsed(!isElementsPanelCollapsed);
700
+ }
701
+ })));
670
702
  };
671
703
 
672
704
  var EmptyProperty = withT(function (_ref) {
673
705
  var t = _ref.t;
674
706
  return /*#__PURE__*/React.createElement("div", {
675
- className: "space-y-4 "
707
+ className: "space-y-4 pr-6 pb-6"
676
708
  }, /*#__PURE__*/React.createElement("div", {
677
709
  className: "neeto-ui-bg-gray-200 neeto-ui-text-gray-600 neeto-ui-rounded-lg flex w-full flex-col items-center justify-center space-y-2 px-16 py-8"
678
710
  }, /*#__PURE__*/React.createElement(Typography, {
@@ -690,7 +722,7 @@ var EmptyProperty = withT(function (_ref) {
690
722
  var Skeleton = withT(function (_ref) {
691
723
  var t = _ref.t;
692
724
  return /*#__PURE__*/React.createElement("div", {
693
- className: "space-y-4 pr-6"
725
+ className: "space-y-4 pr-6 pb-6"
694
726
  }, /*#__PURE__*/React.createElement("div", {
695
727
  className: "neeto-ui-bg-gray-200 neeto-ui-rounded-lg h-12 w-full"
696
728
  }), /*#__PURE__*/React.createElement("div", {
@@ -708,10 +740,46 @@ var Skeleton = withT(function (_ref) {
708
740
  });
709
741
 
710
742
  var PropertiesPanel = function PropertiesPanel(_ref) {
711
- var children = _ref.children;
712
- return /*#__PURE__*/React.createElement("div", {
743
+ var id = _ref.id,
744
+ children = _ref.children,
745
+ onClose = _ref.onClose;
746
+ var _useBreakpoints = useBreakpoints(function (window) {
747
+ return {
748
+ largeDesktop: window.innerWidth >= 1280
749
+ };
750
+ }),
751
+ isSize = _useBreakpoints.isSize;
752
+ var isLargerScreen = isSize("largeDesktop");
753
+ var _useState = useState(!isLargerScreen),
754
+ _useState2 = _slicedToArray(_useState, 2),
755
+ isPropertiesPanelCollapsed = _useState2[0],
756
+ setIsPropertiesPanelCollapsed = _useState2[1];
757
+ useEffect(function () {
758
+ setIsPropertiesPanelCollapsed(!isLargerScreen);
759
+ }, [isLargerScreen]);
760
+ useEffect(function () {
761
+ if (!id) return;
762
+ setIsPropertiesPanelCollapsed(false);
763
+ }, [id]);
764
+ var handleCollapsePanel = function handleCollapsePanel() {
765
+ setIsPropertiesPanelCollapsed(!isPropertiesPanelCollapsed);
766
+ onClose === null || onClose === void 0 ? void 0 : onClose(id);
767
+ };
768
+ return /*#__PURE__*/React.createElement(React.Fragment, null, !isPropertiesPanelCollapsed && /*#__PURE__*/React.createElement("div", {
769
+ className: "neeto-molecules-builder-panel__backdrop neeto-molecules-builder-panel__backdrop--extended",
770
+ onClick: handleCollapsePanel
771
+ }), /*#__PURE__*/React.createElement("div", {
772
+ className: classnames("neeto-molecules-builder-element-properties-panel__wrapper", {
773
+ "neeto-molecules-builder-element-properties-panel__wrapper--collapsed": isPropertiesPanelCollapsed
774
+ })
775
+ }, /*#__PURE__*/React.createElement("div", {
713
776
  className: "neeto-molecules-builder-element-properties-panel neeto-ui-bg-gray-100"
714
- }, children !== null && children !== void 0 ? children : /*#__PURE__*/React.createElement(Skeleton, null));
777
+ }, children !== null && children !== void 0 ? children : /*#__PURE__*/React.createElement(Skeleton, null)), !isPropertiesPanelCollapsed && /*#__PURE__*/React.createElement(Button, {
778
+ className: "neeto-molecules-builder-properties-panel__close",
779
+ icon: Close,
780
+ style: "secondary",
781
+ onClick: handleCollapsePanel
782
+ })));
715
783
  };
716
784
  PropertiesPanel.EmptyProperty = EmptyProperty;
717
785