@bigbinary/neeto-molecules 1.4.5 → 1.4.6-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,14 +1,14 @@
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, withT } 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';
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
- import { withT } from '@bigbinary/neeto-commons-frontend/react-utils';
12
12
 
13
13
  function _arrayWithHoles(arr) {
14
14
  if (Array.isArray(arr)) return arr;
@@ -106,18 +106,6 @@ function _defineProperty(obj, key, value) {
106
106
  return obj;
107
107
  }
108
108
 
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
109
  function _extends() {
122
110
  _extends = Object.assign ? Object.assign.bind() : function (target) {
123
111
  for (var i = 1; i < arguments.length; i++) {
@@ -133,6 +121,51 @@ function _extends() {
133
121
  return _extends.apply(this, arguments);
134
122
  }
135
123
 
124
+ function _objectWithoutPropertiesLoose(source, excluded) {
125
+ if (source == null) return {};
126
+ var target = {};
127
+ var sourceKeys = Object.keys(source);
128
+ var key, i;
129
+ for (i = 0; i < sourceKeys.length; i++) {
130
+ key = sourceKeys[i];
131
+ if (excluded.indexOf(key) >= 0) continue;
132
+ target[key] = source[key];
133
+ }
134
+ return target;
135
+ }
136
+
137
+ function _objectWithoutProperties(source, excluded) {
138
+ if (source == null) return {};
139
+ var target = _objectWithoutPropertiesLoose(source, excluded);
140
+ var key, i;
141
+ if (Object.getOwnPropertySymbols) {
142
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
143
+ for (i = 0; i < sourceSymbolKeys.length; i++) {
144
+ key = sourceSymbolKeys[i];
145
+ if (excluded.indexOf(key) >= 0) continue;
146
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
147
+ target[key] = source[key];
148
+ }
149
+ }
150
+ return target;
151
+ }
152
+
153
+ 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}}
154
+
155
+ 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:51}@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:51}.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:absolute;top:0;visibility:hidden;width:100%;z-index:51}@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}}";
156
+ n(css,{});
157
+
158
+ var _excluded$4 = ["size"];
159
+ var Body = function Body(_ref) {
160
+ var size = _ref.size,
161
+ props = _objectWithoutProperties(_ref, _excluded$4);
162
+ return /*#__PURE__*/React.createElement("div", _extends({}, props, {
163
+ className: classnames("neeto-molecules-builder-questions-list-panel__scroll", {
164
+ "neeto-molecules-builder-questions-list-panel__scroll--small": size === "small"
165
+ })
166
+ }));
167
+ };
168
+
136
169
  var Element = function Element(_ref) {
137
170
  var label = _ref.label,
138
171
  Icon = _ref.icon,
@@ -241,49 +274,19 @@ var ElementList = function ElementList(_ref) {
241
274
  value: searchString,
242
275
  onChange: withEventTargetValue(setSearchString)
243
276
  })), /*#__PURE__*/React.createElement(Body, {
244
- "data-testid": "elements-container"
245
- }, /*#__PURE__*/React.createElement("div", {
246
- className: "neeto-molecules-builder-questions-list-panel__scroll--small"
277
+ "data-testid": "elements-container",
278
+ size: "small"
247
279
  }, filteredSections.map(function (section) {
248
280
  return /*#__PURE__*/React.createElement(Section, {
281
+ onSelect: onSelect,
249
282
  elements: section.elements,
250
283
  isCreatable: section.isCreatable,
251
284
  key: section.key,
252
- title: section.title,
253
- onSelect: onSelect
285
+ title: section.title
254
286
  });
255
- }))));
287
+ })));
256
288
  };
257
289
 
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
290
  var MENU_ITEM_TYPES = {
288
291
  menuItem: "menuItem",
289
292
  divider: "divider"
@@ -623,13 +626,34 @@ var ElementsPanel = function ElementsPanel(_ref) {
623
626
  _useState2 = _slicedToArray(_useState, 2),
624
627
  isElementsListVisible = _useState2[0],
625
628
  setIsElementsListVisible = _useState2[1];
629
+ var _useBreakpoints = useBreakpoints(),
630
+ isSize = _useBreakpoints.isSize;
631
+ var isLargerScreen = !isSize("mobile");
632
+ var _useState3 = useState(!isLargerScreen),
633
+ _useState4 = _slicedToArray(_useState3, 2),
634
+ isElementsPanelCollapsed = _useState4[0],
635
+ setIsElementsPanelCollapsed = _useState4[1];
626
636
  var isSelectedElementsEmpty = isEmpty(selectedElements);
627
637
  var shouldShowElementsList = isSelectedElementsEmpty || isElementsListVisible;
628
638
  var handleElementSelect = function handleElementSelect(element) {
629
639
  setIsElementsListVisible(false);
630
640
  handleAddElement(element);
631
641
  };
632
- return /*#__PURE__*/React.createElement("div", {
642
+ useEffect(function () {
643
+ setIsElementsPanelCollapsed(!isLargerScreen);
644
+ }, [isLargerScreen]);
645
+ return /*#__PURE__*/React.createElement(React.Fragment, null, !isElementsPanelCollapsed && /*#__PURE__*/React.createElement("div", {
646
+ className: "neeto-molecules-builder-panel__backdrop",
647
+ onClick: function onClick() {
648
+ setIsElementsPanelCollapsed(!isElementsPanelCollapsed);
649
+ }
650
+ }), /*#__PURE__*/React.createElement("div", {
651
+ className: classnames("neeto-molecules-builder-elements-list-panel__wrapper", {
652
+ "neeto-molecules-builder-elements-list-panel__wrapper--collapsed": isElementsPanelCollapsed
653
+ })
654
+ }, /*#__PURE__*/React.createElement("div", {
655
+ className: "neeto-molecules-builder-elements-list-panel__container"
656
+ }, /*#__PURE__*/React.createElement("div", {
633
657
  className: "neeto-molecules-builder-elements-list-panel neeto-ui-bg-gray-100",
634
658
  onClick: function onClick(event) {
635
659
  return event.stopPropagation();
@@ -656,13 +680,20 @@ var ElementsPanel = function ElementsPanel(_ref) {
656
680
  selectedElements: selectedElements,
657
681
  setIsElementsListVisible: setIsElementsListVisible,
658
682
  showElementsFillButton: showElementsFillButton
659
- }));
683
+ }))), /*#__PURE__*/React.createElement(Button, {
684
+ className: "neeto-molecules-builder-elements-list-panel__toggler",
685
+ icon: Collapse,
686
+ style: "secondary",
687
+ onClick: function onClick() {
688
+ setIsElementsPanelCollapsed(!isElementsPanelCollapsed);
689
+ }
690
+ })));
660
691
  };
661
692
 
662
693
  var EmptyProperty = withT(function (_ref) {
663
694
  var t = _ref.t;
664
695
  return /*#__PURE__*/React.createElement("div", {
665
- className: "space-y-4 "
696
+ className: "space-y-4 pr-6 pb-6"
666
697
  }, /*#__PURE__*/React.createElement("div", {
667
698
  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"
668
699
  }, /*#__PURE__*/React.createElement(Typography, {
@@ -680,7 +711,7 @@ var EmptyProperty = withT(function (_ref) {
680
711
  var Skeleton = withT(function (_ref) {
681
712
  var t = _ref.t;
682
713
  return /*#__PURE__*/React.createElement("div", {
683
- className: "space-y-4 pr-6"
714
+ className: "space-y-4 pr-6 pb-6"
684
715
  }, /*#__PURE__*/React.createElement("div", {
685
716
  className: "neeto-ui-bg-gray-200 neeto-ui-rounded-lg h-12 w-full"
686
717
  }), /*#__PURE__*/React.createElement("div", {
@@ -698,10 +729,45 @@ var Skeleton = withT(function (_ref) {
698
729
  });
699
730
 
700
731
  var PropertiesPanel = function PropertiesPanel(_ref) {
701
- var children = _ref.children;
702
- return /*#__PURE__*/React.createElement("div", {
732
+ var id = _ref.id,
733
+ children = _ref.children;
734
+ var _useBreakpoints = useBreakpoints(function (window) {
735
+ return {
736
+ largeDesktop: window.innerWidth >= 1280
737
+ };
738
+ }),
739
+ isSize = _useBreakpoints.isSize;
740
+ var isLargerScreen = isSize("largeDesktop");
741
+ var _useState = useState(!isLargerScreen),
742
+ _useState2 = _slicedToArray(_useState, 2),
743
+ isPropertiesPanelCollapsed = _useState2[0],
744
+ setIsPropertiesPanelCollapsed = _useState2[1];
745
+ useEffect(function () {
746
+ setIsPropertiesPanelCollapsed(!isLargerScreen);
747
+ }, [isLargerScreen]);
748
+ useEffect(function () {
749
+ if (!id) return;
750
+ setIsPropertiesPanelCollapsed(false);
751
+ }, [id]);
752
+ return /*#__PURE__*/React.createElement(React.Fragment, null, !isPropertiesPanelCollapsed && /*#__PURE__*/React.createElement("div", {
753
+ className: "neeto-molecules-builder-panel__backdrop neeto-molecules-builder-panel__backdrop--extended",
754
+ onClick: function onClick() {
755
+ setIsPropertiesPanelCollapsed(!isPropertiesPanelCollapsed);
756
+ }
757
+ }), /*#__PURE__*/React.createElement("div", {
758
+ className: classnames("neeto-molecules-builder-element-properties-panel__wrapper", {
759
+ "neeto-molecules-builder-element-properties-panel__wrapper--collapsed": isPropertiesPanelCollapsed
760
+ })
761
+ }, /*#__PURE__*/React.createElement("div", {
703
762
  className: "neeto-molecules-builder-element-properties-panel neeto-ui-bg-gray-100"
704
- }, children !== null && children !== void 0 ? children : /*#__PURE__*/React.createElement(Skeleton, null));
763
+ }, children !== null && children !== void 0 ? children : /*#__PURE__*/React.createElement(Skeleton, null)), !isPropertiesPanelCollapsed && /*#__PURE__*/React.createElement(Button, {
764
+ className: "neeto-molecules-builder-properties-panel__close",
765
+ icon: Close,
766
+ style: "secondary",
767
+ onClick: function onClick() {
768
+ setIsPropertiesPanelCollapsed(!isPropertiesPanelCollapsed);
769
+ }
770
+ })));
705
771
  };
706
772
  PropertiesPanel.EmptyProperty = EmptyProperty;
707
773