@startlibs/form 1.0.0-alpha-9w → 1.0.0-alpha-9z

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 (2) hide show
  1. package/lib/index.js +459 -233
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -44,13 +44,18 @@ var _filter = _interopDefault(require('lodash/fp/filter'));
44
44
  var _map = _interopDefault(require('lodash/fp/map'));
45
45
  var _stubFalse = _interopDefault(require('lodash/fp/stubFalse'));
46
46
  var _isObject = _interopDefault(require('lodash/fp/isObject'));
47
+ require('@babel/runtime/helpers/awaitAsyncGenerator');
48
+ require('@babel/runtime/helpers/wrapAsyncGenerator');
49
+ var _ = _interopDefault(require('lodash/fp'));
50
+ require('@babel/runtime/helpers/typeof');
51
+ var createEmotion = _interopDefault(require('create-emotion'));
47
52
  var _isFinite = _interopDefault(require('lodash/fp/isFinite'));
53
+ var _negate = _interopDefault(require('lodash/fp/negate'));
48
54
  var _zipObject = _interopDefault(require('lodash/fp/zipObject'));
49
55
  var _flatten = _interopDefault(require('lodash/fp/flatten'));
50
56
  var _fromPairs = _interopDefault(require('lodash/fp/fromPairs'));
51
57
  var _pick = _interopDefault(require('lodash/fp/pick'));
52
58
  var _toPairs = _interopDefault(require('lodash/fp/toPairs'));
53
- var _negate = _interopDefault(require('lodash/fp/negate'));
54
59
  var _get = _interopDefault(require('lodash/fp/get'));
55
60
  var _entries = _interopDefault(require('lodash/fp/entries'));
56
61
 
@@ -137,7 +142,9 @@ var useProvideErrors = function useProvideErrors() {
137
142
  };
138
143
 
139
144
  var setErrors = function setErrors(newErrors) {
140
- return errors.openWith(parseMultipleErrors(newErrors));
145
+ console.log(parseMultipleErrors(newErrors));
146
+ errors.openWith(parseMultipleErrors(newErrors));
147
+ errors.get();
141
148
  };
142
149
 
143
150
  var setError = function setError(errorPath, errorValue) {
@@ -1104,7 +1111,9 @@ var Container = styled__default.div.withConfig({
1104
1111
  var Label = styled__default.label.withConfig({
1105
1112
  displayName: "Field__Label",
1106
1113
  componentId: "p9woft-2"
1107
- })(["font-weight:500;display:inline-block;font-size:14px;margin-bottom:.5rem;", " ", ""], function (props) {
1114
+ })(["font-weight:500;display:inline-block;font-size:", "px;margin-bottom:.5rem;", " ", ""], function (props) {
1115
+ return props.labelFontSize ? props.labelFontSize : '14';
1116
+ }, function (props) {
1108
1117
  return props.isOnImage && 'color: #fff;';
1109
1118
  }, utils.customTheme("FieldLabel"));
1110
1119
  var HelpText = styled__default.span.withConfig({
@@ -1130,14 +1139,16 @@ var Field = React__default.forwardRef(function (_ref, ref) {
1130
1139
  mandatory = _ref.mandatory,
1131
1140
  onImage = _ref.onImage,
1132
1141
  children = _ref.children,
1133
- rest = _objectWithoutProperties(_ref, ["label", "helpText", "descText", "bellowDescText", "className", "labelClick", "focused", "mandatory", "onImage", "children"]);
1142
+ labelFontSize = _ref.labelFontSize,
1143
+ rest = _objectWithoutProperties(_ref, ["label", "helpText", "descText", "bellowDescText", "className", "labelClick", "focused", "mandatory", "onImage", "children", "labelFontSize"]);
1134
1144
 
1135
1145
  return React__default.createElement(Container, _extends({
1136
1146
  ref: ref
1137
1147
  }, rest, {
1138
1148
  className: className
1139
1149
  }), label && React__default.createElement(Label, _extends({}, rest, {
1140
- onClick: labelClick
1150
+ onClick: labelClick,
1151
+ labelFontSize: labelFontSize
1141
1152
  }), label, mandatory && React__default.createElement(Mandatory, {
1142
1153
  mandatory: mandatory
1143
1154
  }, "*"), helpText && React__default.createElement(HelpText, null, " ", helpText), descText && React__default.createElement(FieldDescription, null, descText)), children, bellowDescText && React__default.createElement(BellowFieldDescription, null, bellowDescText));
@@ -3050,6 +3061,206 @@ var FormMeta = function FormMeta(_ref3) {
3050
3061
  return utils.ifUndefined(utils.callIfFunction(children, value, setValue), value, null);
3051
3062
  };
3052
3063
 
3064
+ var scrollWidth = function () {
3065
+ if (!window.document) return 0;
3066
+ var html = document.documentElement;
3067
+ var oldOverflow = html.style.overflowY;
3068
+ html.style.overflowY = 'scroll';
3069
+ var width = window.innerWidth - html.clientWidth;
3070
+ html.style.overflowY = oldOverflow;
3071
+ return width;
3072
+ }();
3073
+
3074
+ var callIfFunction = function callIfFunction(prop) {
3075
+ for (var _len6 = arguments.length, args = new Array(_len6 > 1 ? _len6 - 1 : 0), _key6 = 1; _key6 < _len6; _key6++) {
3076
+ args[_key6 - 1] = arguments[_key6];
3077
+ }
3078
+
3079
+ return typeof prop === "function" ? prop.apply(void 0, args) : prop;
3080
+ };
3081
+
3082
+ var moveElement = _.curry(function (from, to, list) {
3083
+ var el = list[from];
3084
+
3085
+ var without = _.pullAt(from, list);
3086
+
3087
+ without.splice(to, 0, el);
3088
+ return without;
3089
+ });
3090
+ var unsetOrRemoveAt = _.curry(function (path, value) {
3091
+ var pathArr = toPath(path);
3092
+
3093
+ var _pathArr$slice = pathArr.slice(-1),
3094
+ _pathArr$slice2 = _slicedToArray(_pathArr$slice, 1),
3095
+ lastKey = _pathArr$slice2[0];
3096
+
3097
+ return update(pathArr.slice(0, -1), function (v) {
3098
+ return Array.isArray(v) ? removeAt(lastKey, v) : unset(lastKey, v);
3099
+ }, value);
3100
+ });
3101
+
3102
+ var sanitizePath = function sanitizePath(path) {
3103
+ return Array.isArray(path) ? path.map(sanitizePath) : typeof path === 'number' ? path.toString() : path === undefined ? [] : path;
3104
+ };
3105
+
3106
+ var toPath = function toPath(path) {
3107
+ return _.toPath(sanitizePath(path));
3108
+ };
3109
+
3110
+ var isEmptyPath = function isEmptyPath(path) {
3111
+ return path && !path.length;
3112
+ };
3113
+
3114
+ var update = _.curry(function (path, updater, state) {
3115
+ var sanitizedPath = sanitizePath(path);
3116
+
3117
+ if (isEmptyPath(sanitizedPath)) {
3118
+ return updater(state);
3119
+ } else {
3120
+ return _.update(sanitizedPath, updater, state);
3121
+ }
3122
+ });
3123
+ var get = _.curry(function (path, state) {
3124
+ var sanitizedPath = sanitizePath(path);
3125
+
3126
+ if (isEmptyPath(sanitizedPath)) {
3127
+ return state;
3128
+ } else {
3129
+ return _.get(sanitizedPath, state);
3130
+ }
3131
+ });
3132
+ var set = _.curry(function (path, value, state) {
3133
+ var sanitizedPath = sanitizePath(path);
3134
+
3135
+ if (isEmptyPath(sanitizedPath)) {
3136
+ return value;
3137
+ } else {
3138
+ return _.set(sanitizedPath, value, state);
3139
+ }
3140
+ });
3141
+ var unset = _.curry(function (path, state) {
3142
+ var sanitizedPath = sanitizePath(path);
3143
+
3144
+ if (isEmptyPath(sanitizedPath)) {
3145
+ return undefined;
3146
+ } else {
3147
+ return _.unset(sanitizedPath, state);
3148
+ }
3149
+ });
3150
+ var removeNAt = _.curry(function (pos, n, value) {
3151
+ return _toConsumableArray(value.slice(0, Number(pos))).concat(_toConsumableArray(value.slice(Number(pos) + n)));
3152
+ });
3153
+ var removeAt = removeNAt(_.__, 1);
3154
+ var when = _.curry(function (cond, fn, value) {
3155
+ return callIfFunction(cond, value) ? fn(value) : value;
3156
+ });
3157
+ var assign = _.curry(function (a, b) {
3158
+ return _.assign(b, a);
3159
+ });
3160
+ var concat = _.curry(function (a, b) {
3161
+ return _.concat(b, a);
3162
+ });
3163
+ var each = _.each.convert({
3164
+ cap: false
3165
+ });
3166
+ var find = _.find.convert({
3167
+ cap: false
3168
+ });
3169
+ var filter = _.filter.convert({
3170
+ cap: false
3171
+ });
3172
+ var map = _.map.convert({
3173
+ cap: false
3174
+ });
3175
+ var insertAt = _.curry(function (pos, newElements, value) {
3176
+ return _toConsumableArray(value.slice(0, pos).concat(newElements)).concat(_toConsumableArray(value.slice(pos)));
3177
+ });
3178
+
3179
+ function _templateObject$3() {
3180
+ var data = _taggedTemplateLiteral(["\n ", ""]);
3181
+
3182
+ _templateObject$3 = function _templateObject() {
3183
+ return data;
3184
+ };
3185
+
3186
+ return data;
3187
+ }
3188
+
3189
+ var checkCustomScreenWidth = function checkCustomScreenWidth(sizeParis, customWidth) {
3190
+ var currentWidth = callIfFunction(customWidth);
3191
+ return !sizeParis.find(function (_ref4) {
3192
+ var _ref5 = _slicedToArray(_ref4, 2),
3193
+ size = _ref5[0],
3194
+ type = _ref5[1];
3195
+
3196
+ if (type === "min-width") {
3197
+ return currentWidth < size;
3198
+ }
3199
+
3200
+ if (type === "max-width") {
3201
+ return currentWidth > size;
3202
+ }
3203
+ });
3204
+ };
3205
+
3206
+ var media = function media() {
3207
+ for (var _len3 = arguments.length, sizePairs = new Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
3208
+ sizePairs[_key3] = arguments[_key3];
3209
+ }
3210
+
3211
+ return function () {
3212
+ for (var _len4 = arguments.length, args = new Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
3213
+ args[_key4] = arguments[_key4];
3214
+ }
3215
+
3216
+ return styled.css(["", ""], function (props) {
3217
+ var _props$theme, _props$theme2;
3218
+
3219
+ return ((_props$theme = props.theme) === null || _props$theme === void 0 ? void 0 : _props$theme.overrideMediaWidth) ? checkCustomScreenWidth(sizePairs, (_props$theme2 = props.theme) === null || _props$theme2 === void 0 ? void 0 : _props$theme2.overrideMediaWidth) ? styled.css.apply(void 0, args) : "" : styled.css(["@media ", "{", "}"], sizePairs.map(function (_ref6) {
3220
+ var _ref7 = _slicedToArray(_ref6, 2),
3221
+ size = _ref7[0],
3222
+ type = _ref7[1];
3223
+
3224
+ return "(".concat(type, ": ").concat(size + scrollWidth, "px)");
3225
+ }).join(' and '), styled.css.apply(void 0, args));
3226
+ });
3227
+ };
3228
+ };
3229
+ media.mobile = media([600, 'max-width']);
3230
+
3231
+ media.between = function (min, max) {
3232
+ return media([min, 'min-width'], [max, 'max-width']);
3233
+ };
3234
+
3235
+ media.max = function (n) {
3236
+ return media([n, 'max-width']);
3237
+ };
3238
+
3239
+ media.min = function (n) {
3240
+ return media([n, 'min-width']);
3241
+ };
3242
+
3243
+ media.desktop = media([601, 'min-width']);
3244
+
3245
+ var getFrameOffset = function getFrameOffset(i, total) {
3246
+ return Math.round(i * 100 / (total - 1));
3247
+ };
3248
+
3249
+ var emotion = createEmotion({
3250
+ nonce: __webpack_nonce__
3251
+ });
3252
+ var oneWayAnimation = function oneWayAnimation() {
3253
+ for (var _len5 = arguments.length, frames = new Array(_len5), _key5 = 0; _key5 < _len5; _key5++) {
3254
+ frames[_key5] = arguments[_key5];
3255
+ }
3256
+
3257
+ return emotion.keyframes(_templateObject$3(), frames.map(function (frame, i) {
3258
+ return !frame ? '' : "".concat(getFrameOffset(i, frames.length), "% {\n ").concat(frame, "\n }");
3259
+ }));
3260
+ };
3261
+ var identityTranslateFrames = oneWayAnimation('transform: translateY(0);', 'transform: translateY(0);');
3262
+ var identityOpacityFrames = oneWayAnimation('opacity: 1;', 'opacity:1;');
3263
+
3053
3264
  var addRootPath = function addRootPath(errorRootPath, errors, path) {
3054
3265
  var rootPath = [].concat(errorRootPath || [], path);
3055
3266
  return Object.keys(errors).reduce(function (acc, error) {
@@ -3487,11 +3698,12 @@ var EditableBoxPresentation = styled__default(React.forwardRef(function (_ref13,
3487
3698
 
3488
3699
  var SharedEditableTabBox = function SharedEditableTabBox(_ref15) {
3489
3700
  var path = _ref15.path,
3490
- props = _objectWithoutProperties(_ref15, ["path"]);
3701
+ isSingle = _ref15.isSingle,
3702
+ props = _objectWithoutProperties(_ref15, ["path", "isSingle"]);
3491
3703
 
3492
3704
  var editableGroup = React.useContext(EditableContext);
3493
3705
  var form = React.useContext(FormContext);
3494
- var isNew = core.useRefState(utils._s.get(path, form.getOriginalValues()) !== form.getValue(path));
3706
+ var isNew = core.useRefState(isSingle ? false : utils._s.get(path, form.getOriginalValues()) !== form.getValue(path));
3495
3707
  var internalBox = React__default.useRef();
3496
3708
 
3497
3709
  var loading = function loading() {
@@ -3778,10 +3990,10 @@ var Radiobox = function Radiobox(_ref) {
3778
3990
  }));
3779
3991
  };
3780
3992
 
3781
- function _templateObject$3() {
3993
+ function _templateObject$4() {
3782
3994
  var data = _taggedTemplateLiteral(["\n padding: 7px 12px 7px 32px;\n "]);
3783
3995
 
3784
- _templateObject$3 = function _templateObject() {
3996
+ _templateObject$4 = function _templateObject() {
3785
3997
  return data;
3786
3998
  };
3787
3999
 
@@ -3807,7 +4019,7 @@ var CheckboxContent = styled__default.div.withConfig({
3807
4019
  displayName: "SimpleCheckbox__CheckboxContent",
3808
4020
  componentId: "am8pps-4"
3809
4021
  })(["cursor:pointer;position:relative;padding-left:2rem;", ""], function (props) {
3810
- return props.framed && styled.css(["border:1px solid ", ";border-radius:6px;min-height:3rem;min-width:8rem;background:white;:hover{background:rgb(245,245,245);}:active{background:rgb(235,235,235);}padding:10px 12px 10px 32px;", " ", " ", " ", " ", ""], utils.getColor('gray210'), utils.media.desktop(_templateObject$3()), function (props) {
4022
+ return props.framed && styled.css(["border:1px solid ", ";border-radius:6px;min-height:3rem;min-width:8rem;background:white;:hover{background:rgb(245,245,245);}:active{background:rgb(235,235,235);}padding:10px 12px 10px 32px;", " ", " ", " ", " ", ""], utils.getColor('gray210'), utils.media.desktop(_templateObject$4()), function (props) {
3811
4023
  return props.hasErrors && styled.css(["border-color:", " !important;"], utils.getColor('alert'));
3812
4024
  }, function (props) {
3813
4025
  return props.checked && props.highlightSelected && styled.css(["border-color:", ";background:", ";:hover{background:", ";}", "{", "{color:", ";}}"], utils.getColor('main'), function (props) {
@@ -3863,10 +4075,10 @@ var SimpleCheckbox = styled__default(function (_ref) {
3863
4075
  componentId: "am8pps-5"
3864
4076
  })(["cursor:pointer;position:relative;margin-bottom:1rem;display:block;", ""], utils.ifProp('disabled', styled.css(["pointer-events:none;"])));
3865
4077
 
3866
- function _templateObject$4() {
4078
+ function _templateObject$5() {
3867
4079
  var data = _taggedTemplateLiteral(["\n padding: 7px 12px 7px 32px;\n "]);
3868
4080
 
3869
- _templateObject$4 = function _templateObject() {
4081
+ _templateObject$5 = function _templateObject() {
3870
4082
  return data;
3871
4083
  };
3872
4084
 
@@ -3892,7 +4104,7 @@ var RadioboxContent = styled__default.div.withConfig({
3892
4104
  displayName: "SimpleRadiobox__RadioboxContent",
3893
4105
  componentId: "qv83xo-4"
3894
4106
  })(["cursor:pointer;position:relative;padding-left:2rem;", ""], function (props) {
3895
- return props.framed && styled.css(["border:1px solid ", ";border-radius:6px;min-height:3rem;min-width:8rem;background:white;:hover{background:rgb(245,245,245);}:active{background:rgb(235,235,235);}padding:10px 12px 10px 32px;", " ", " ", " ", " ", ""], utils.getColor('gray210'), utils.media.desktop(_templateObject$4()), function (props) {
4107
+ return props.framed && styled.css(["border:1px solid ", ";border-radius:6px;min-height:3rem;min-width:8rem;background:white;:hover{background:rgb(245,245,245);}:active{background:rgb(235,235,235);}padding:10px 12px 10px 32px;", " ", " ", " ", " ", ""], utils.getColor('gray210'), utils.media.desktop(_templateObject$5()), function (props) {
3896
4108
  return props.hasErrors && styled.css(["border-color:", " !important;"], utils.getColor('alert'));
3897
4109
  }, function (props) {
3898
4110
  return props.checked && props.highlightSelected && styled.css(["border-color:", ";background:", ";:hover{background:", ";}", "{:before{background-color:", ";}}"], utils.getColor('main'), function (props) {
@@ -3994,10 +4206,10 @@ function _templateObject2$2() {
3994
4206
  return data;
3995
4207
  }
3996
4208
 
3997
- function _templateObject$5() {
4209
+ function _templateObject$6() {
3998
4210
  var data = _taggedTemplateLiteral(["\n width: 2.5rem;\n "]);
3999
4211
 
4000
- _templateObject$5 = function _templateObject() {
4212
+ _templateObject$6 = function _templateObject() {
4001
4213
  return data;
4002
4214
  };
4003
4215
 
@@ -4010,7 +4222,7 @@ var LEVELS = [DAY, MONTH, YEAR];
4010
4222
  var DatePickerContainer = styled__default.div.withConfig({
4011
4223
  displayName: "DatePicker__DatePickerContainer",
4012
4224
  componentId: "sc-1wo8j4d-0"
4013
- })(["width:20rem;position:absolute;z-index:10;background-color:white;border-radius:5px;border:1px solid ", ";user-select:none;box-shadow:0 0 4px 0 rgba(0,0,0,0.2);font-size:13px;text-align:center;animation:0.2s datePickerFadeInDown ease-out;display:none;@supports (flex-wrap:wrap){display:block;}input{padding-right:2.25rem;", "}@keyframes datePickerFadeInDown{from{opacity:0;transform:translateY(-10px);pointer-events:none;}to{opacity:1;transform:none;pointer-events:none;}}"], utils.getColor('gray210'), utils.media.mobile(_templateObject$5()));
4225
+ })(["width:20rem;position:absolute;z-index:10;background-color:white;border-radius:5px;border:1px solid ", ";user-select:none;box-shadow:0 0 4px 0 rgba(0,0,0,0.2);font-size:13px;text-align:center;animation:0.2s datePickerFadeInDown ease-out;display:none;@supports (flex-wrap:wrap){display:block;}input{padding-right:2.25rem;", "}@keyframes datePickerFadeInDown{from{opacity:0;transform:translateY(-10px);pointer-events:none;}to{opacity:1;transform:none;pointer-events:none;}}"], utils.getColor('gray210'), utils.media.mobile(_templateObject$6()));
4014
4226
  var CalendarHeader = styled__default.div.withConfig({
4015
4227
  displayName: "DatePicker__CalendarHeader",
4016
4228
  componentId: "sc-1wo8j4d-1"
@@ -4683,6 +4895,219 @@ function getClosestNextLeapYear(year) {
4683
4895
  return y;
4684
4896
  }
4685
4897
 
4898
+ function _templateObject$7() {
4899
+ var data = _taggedTemplateLiteral(["\n padding 1rem;\n "]);
4900
+
4901
+ _templateObject$7 = function _templateObject() {
4902
+ return data;
4903
+ };
4904
+
4905
+ return data;
4906
+ }
4907
+
4908
+ var shouldPreventExpand = function shouldPreventExpand(fn) {
4909
+ return function (e) {
4910
+ return e.target.closest('body,[data-expand="false"],label,input,textarea,button').matches('body,[data-expand="true"]') && fn(e);
4911
+ };
4912
+ };
4913
+
4914
+ var ExpandableBoxStyled = styled__default.div.withConfig({
4915
+ displayName: "ExpandableBox__ExpandableBoxStyled",
4916
+ componentId: "sc-1nsk1wq-0"
4917
+ })(["padding:1rem;border-radius:6px;background:", ";font-size:14px;outline:none;transition:background 0.25s linear;position:relative;", " ", " & ~ &{margin-top:0.75rem;}", " &{margin-top:0.75rem;}"], utils.getColor('gray240'), function (props) {
4918
+ return props.small && "\n padding: 0.875rem 1rem;\n min-height: 3rem;\n ";
4919
+ }, function (props) {
4920
+ return props.collapsed ? styled.css(["cursor:pointer;padding-right:3.25rem;:hover{background:", ";}:active{background:", ";}"], function (props) {
4921
+ return polished.darken(0.05, utils.getColor("gray240")(props));
4922
+ }, function (props) {
4923
+ return polished.darken(0.08, utils.getColor("gray240")(props));
4924
+ }) : styled.css(["padding 1.5rem;", " ", ""], utils.media.max(340)(_templateObject$7()), function (props) {
4925
+ return props.fixMarginBottom && "\n padding-bottom: 0.5rem !important;\n ";
4926
+ });
4927
+ }, components.SwitchDiv);
4928
+ var EditIcon = styled__default(components.Icon).attrs({
4929
+ icon: 'edit'
4930
+ }).withConfig({
4931
+ displayName: "ExpandableBox__EditIcon",
4932
+ componentId: "sc-1nsk1wq-1"
4933
+ })(["position:absolute;top:50%;transform:translateY(-50%);right:-24px;color:rgba(0,0,0,0.25);font-size:20px;"]);
4934
+ var checkErrors = function checkErrors() {
4935
+ for (var _len = arguments.length, checks = new Array(_len), _key = 0; _key < _len; _key++) {
4936
+ checks[_key] = arguments[_key];
4937
+ }
4938
+
4939
+ return function (v, setErrors) {
4940
+ var results = checks.map(function (c) {
4941
+ return c(v);
4942
+ }).filter(Boolean);
4943
+
4944
+ if (!results.length) {
4945
+ return true;
4946
+ }
4947
+
4948
+ var messages = results.filter(_negate(_isBoolean));
4949
+
4950
+ if (messages.length) {
4951
+ setErrors.apply(void 0, _toConsumableArray(messages));
4952
+ }
4953
+
4954
+ return false;
4955
+ };
4956
+ };
4957
+ var timing = utils.animationTiming('0.25s ease-out');
4958
+ var switchAnimation = utils.oneWayAnimation('opacity: 1;transform:translateY(0);', 'opacity: 0;', 'opacity: 0; transform:translateY(30px);');
4959
+ var ExpandableBox = function ExpandableBox(_ref) {
4960
+ var children = _ref.children,
4961
+ info = _ref.info,
4962
+ isOpen = _ref.isOpen,
4963
+ openWhen = _ref.openWhen,
4964
+ path = _ref.path,
4965
+ _ref$retargetFilter = _ref.retargetFilter,
4966
+ retargetFilter = _ref$retargetFilter === void 0 ? function (el) {
4967
+ var _el$tagName;
4968
+
4969
+ return (el === null || el === void 0 ? void 0 : (_el$tagName = el.tagName) === null || _el$tagName === void 0 ? void 0 : _el$tagName.toLowerCase()) === "button";
4970
+ } : _ref$retargetFilter,
4971
+ _ref$isValid = _ref.isValid,
4972
+ isValid = _ref$isValid === void 0 ? function () {
4973
+ return true;
4974
+ } : _ref$isValid,
4975
+ fixMarginBottom = _ref.fixMarginBottom,
4976
+ _ref$animation = _ref.animation,
4977
+ animation = _ref$animation === void 0 ? switchAnimation : _ref$animation,
4978
+ _ref$animationTiming = _ref.animationTiming,
4979
+ animationTiming = _ref$animationTiming === void 0 ? timing : _ref$animationTiming;
4980
+ var flipAnimation = core.useLazyConstant(components.willUseFlipSwitch);
4981
+
4982
+ var _useFormValue = form.useFormValue(path),
4983
+ _useFormValue2 = _slicedToArray(_useFormValue, 3),
4984
+ value = _useFormValue2[0],
4985
+ setValue = _useFormValue2[1],
4986
+ getValue = _useFormValue2[2];
4987
+
4988
+ var _useTransientErrorHel = useTransientErrorHelper(),
4989
+ _useTransientErrorHel2 = _slicedToArray(_useTransientErrorHel, 2),
4990
+ _setErrors = _useTransientErrorHel2[0],
4991
+ clearErrors = _useTransientErrorHel2[1];
4992
+
4993
+ var setErrors = function setErrors() {
4994
+ for (var _len2 = arguments.length, errors = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
4995
+ errors[_key2] = arguments[_key2];
4996
+ }
4997
+
4998
+ _setErrors(errors.length ? errors.map(function (k) {
4999
+ return _isString(k) ? [k, ''] : k;
5000
+ }) : [[path, '']]);
5001
+
5002
+ return true;
5003
+ };
5004
+
5005
+ var expand = core.useToggle(isOpen, function (newV, prevV) {
5006
+ if (newV === 0 || prevV === 0) {
5007
+ return;
5008
+ }
5009
+
5010
+ if (newV === false) {
5011
+ var result = isValid(getValue(), setErrors);
5012
+
5013
+ if (result === true) {
5014
+ clearErrors();
5015
+ }
5016
+
5017
+ return result;
5018
+ }
5019
+ });
5020
+ var openWhenResult = utils.callIfFunction(openWhen);
5021
+ React.useEffect(function () {
5022
+ if (openWhenResult) {
5023
+ expand.open();
5024
+ }
5025
+ }, [openWhenResult]);
5026
+ React.useEffect(function () {
5027
+ return function () {
5028
+ if (expand.get() === 0) {
5029
+ expand.close();
5030
+ }
5031
+ };
5032
+ }, [expand.isOpen]);
5033
+ var utils$1 = core.useLazyConstant(function () {
5034
+ return {
5035
+ close: utils.constrainEvent(expand.close),
5036
+ setValue: setValue
5037
+ };
5038
+ });
5039
+
5040
+ var onBlur = function onBlur(e) {
5041
+ if (e.currentTarget !== e.relatedTarget && (!e.relatedTarget || !e.currentTarget.contains(e.relatedTarget))) {
5042
+ if (utils.callIfFunction(retargetFilter, e.relatedTarget)) {
5043
+ e.target.focus();
5044
+ } else {
5045
+ expand.close();
5046
+ }
5047
+ }
5048
+ };
5049
+
5050
+ return React__default.createElement(ExpandableBoxStyled, {
5051
+ tabIndex: -1,
5052
+ onBlur: onBlur,
5053
+ collapsed: !expand.isOpen,
5054
+ fixMarginBottom: fixMarginBottom,
5055
+ onClick: shouldPreventExpand(expand.open)
5056
+ }, React__default.createElement(FlipDiv$1, {
5057
+ key: expand.isOpen,
5058
+ useAnimation: flipAnimation,
5059
+ animation: animation,
5060
+ animationTiming: animationTiming
5061
+ }, expand.isOpen ? utils.callIfFunction(children, value, utils$1) : React__default.createElement(React__default.Fragment, null, utils.callIfFunction(info, value, utils$1), React__default.createElement(EditIcon, null))));
5062
+ };
5063
+
5064
+ var overflowEffect = function overflowEffect(element) {
5065
+ var _element$offsetParent;
5066
+
5067
+ if (!(element === null || element === void 0 ? void 0 : (_element$offsetParent = element.offsetParent) === null || _element$offsetParent === void 0 ? void 0 : _element$offsetParent.parentElement)) {
5068
+ return;
5069
+ }
5070
+
5071
+ var parentDom = element.offsetParent.parentElement;
5072
+ var previousOverflow = parentDom.style.overflow;
5073
+ parentDom.style.overflow = 'hidden';
5074
+ return function () {
5075
+ return parentDom.style.overflow = previousOverflow;
5076
+ };
5077
+ };
5078
+
5079
+ var PseudoExpandableBox = function PseudoExpandableBox(_ref2) {
5080
+ var children = _ref2.children,
5081
+ small = _ref2.small,
5082
+ onClick = _ref2.onClick;
5083
+ return React__default.createElement(ExpandableBoxStyled, {
5084
+ collapsed: true,
5085
+ small: small,
5086
+ onClick: onClick
5087
+ }, React__default.createElement(FlipDivStyle, null, children, React__default.createElement(EditIcon, null)));
5088
+ };
5089
+ var FlipDivStyle = styled__default.div.withConfig({
5090
+ displayName: "ExpandableBox__FlipDivStyle",
5091
+ componentId: "sc-1nsk1wq-2"
5092
+ })(["position:relative;"]);
5093
+
5094
+ var FlipDiv$1 = function FlipDiv(_ref3) {
5095
+ var useAnimation = _ref3.useAnimation,
5096
+ animation = _ref3.animation,
5097
+ animationTiming = _ref3.animationTiming,
5098
+ props = _objectWithoutProperties(_ref3, ["useAnimation", "animation", "animationTiming"]);
5099
+
5100
+ var ref = React.useRef();
5101
+ useAnimation(ref, null, null, {
5102
+ switchAnimation: animation,
5103
+ timing: animationTiming,
5104
+ effect: overflowEffect
5105
+ });
5106
+ return React__default.createElement(FlipDivStyle, _extends({}, props, {
5107
+ ref: ref
5108
+ }));
5109
+ };
5110
+
4686
5111
  var FORMAT_TOOLS = {
4687
5112
  'bold': ['b', 'strong'],
4688
5113
  'italic': 'i',
@@ -4977,7 +5402,7 @@ var RichText = function RichText(_ref5) {
4977
5402
  placeholder = _ref5.placeholder,
4978
5403
  className = _ref5.className,
4979
5404
  _ref5$formatTools = _ref5.formatTools,
4980
- formatTools = _ref5$formatTools === void 0 ? ['bold', 'italic', 'underline', 'strikethrough'] : _ref5$formatTools,
5405
+ formatTools = _ref5$formatTools === void 0 ? ['link', 'bold', 'italic', 'underline', 'strikethrough'] : _ref5$formatTools,
4981
5406
  _ref5$reformatText = _ref5.reformatText,
4982
5407
  reformatText = _ref5$reformatText === void 0 ? _identity : _ref5$reformatText,
4983
5408
  mandatory = _ref5.mandatory,
@@ -5414,19 +5839,20 @@ var EditLinkPopup = function EditLinkPopup(_ref7) {
5414
5839
  values = _ref7.values;
5415
5840
  var linkPopup = React.useRef();
5416
5841
  var formRef = React.useRef();
5842
+ var LABELS = React.useContext(core.StartlibsContext).labels.RichText;
5417
5843
 
5418
5844
  var preValidation = function preValidation(formValues) {
5419
5845
  var errors;
5420
5846
 
5421
5847
  if (!formValues.linkText) {
5422
5848
  errors = {
5423
- 'linkText': ['Campos com asterisco (*) são obrigatórios.']
5849
+ 'linkText': [LABELS.linkTextError]
5424
5850
  };
5425
5851
  }
5426
5852
 
5427
5853
  if (!formValues.linkUrl || formValues.linkUrl === ' ' || !utils.linkRegex.test(formValues.linkUrl.trim())) {
5428
5854
  errors = _objectSpread({}, errors, {
5429
- 'linkUrl': ['Adicione um endereço válido.']
5855
+ 'linkUrl': [LABELS.linkUrlError]
5430
5856
  });
5431
5857
  }
5432
5858
 
@@ -5473,227 +5899,26 @@ var EditLinkPopup = function EditLinkPopup(_ref7) {
5473
5899
  autoFocus: !values.linkText,
5474
5900
  mandatory: true,
5475
5901
  path: "linkText",
5476
- label: "Texto de exibi\xE7\xE3o"
5902
+ label: LABELS.popupLinkText
5477
5903
  }), React__default.createElement(TextInput, {
5478
5904
  autoFocus: values.linkText,
5479
5905
  mandatory: true,
5480
5906
  path: "linkUrl",
5481
- label: "Endere\xE7o completo"
5907
+ label: LABELS.popupLinkUrl
5482
5908
  }), React__default.createElement("div", {
5483
5909
  className: "popup-footer"
5484
5910
  }, React__default.createElement(components.Button, {
5485
5911
  className: "remove-link",
5486
5912
  icon: "remove",
5487
5913
  onClick: removeLink
5488
- }, "Remover Link"), React__default.createElement(components.Button, {
5914
+ }, LABELS.popupRemove), React__default.createElement(components.Button, {
5489
5915
  onClick: cancel,
5490
5916
  tabIndex: 0
5491
- }, "Cancelar"), React__default.createElement(components.Button, {
5917
+ }, LABELS.popupCancel), React__default.createElement(components.Button, {
5492
5918
  highlight: true,
5493
5919
  onClick: form.willSubmitForm
5494
- }, "Aplicar")), React__default.createElement(Errors, null));
5495
- });
5496
- };
5497
-
5498
- function _templateObject$6() {
5499
- var data = _taggedTemplateLiteral(["\n padding 1rem;\n "]);
5500
-
5501
- _templateObject$6 = function _templateObject() {
5502
- return data;
5503
- };
5504
-
5505
- return data;
5506
- }
5507
-
5508
- var shouldPreventExpand = function shouldPreventExpand(fn) {
5509
- return function (e) {
5510
- return e.target.closest('body,[data-expand="false"],label,input,textarea,button').matches('body,[data-expand="true"]') && fn(e);
5511
- };
5512
- };
5513
-
5514
- var ExpandableBoxStyled = styled__default.div.withConfig({
5515
- displayName: "ExpandableBox__ExpandableBoxStyled",
5516
- componentId: "sc-1nsk1wq-0"
5517
- })(["padding:1rem;border-radius:8px;background:", ";font-size:14px;outline:none;transition:background 0.25s linear;", " & ~ &{margin-top:0.75rem;}", " &{margin-top:0.75rem;}"], utils.getColor('gray240'), function (props) {
5518
- return props.collapsed ? styled.css(["cursor:pointer;padding-right:3.25rem;:hover{background:", ";}:active{background:", ";}"], function (props) {
5519
- return polished.darken(0.05, utils.getColor("gray240")(props));
5520
- }, function (props) {
5521
- return polished.darken(0.08, utils.getColor("gray240")(props));
5522
- }) : styled.css(["padding 1.5rem;", " ", ""], utils.media.max(340)(_templateObject$6()), function (props) {
5523
- return props.fixMarginBottom && "\n padding-bottom: 0.5rem !important;\n ";
5524
- });
5525
- }, components.SwitchDiv);
5526
- var EditIcon = styled__default(components.Icon).attrs({
5527
- icon: 'edit'
5528
- }).withConfig({
5529
- displayName: "ExpandableBox__EditIcon",
5530
- componentId: "sc-1nsk1wq-1"
5531
- })(["position:absolute;top:50%;transform:translateY(-50%);right:-24px;color:rgba(0,0,0,0.25);font-size:20px;"]);
5532
- var checkErrors = function checkErrors() {
5533
- for (var _len = arguments.length, checks = new Array(_len), _key = 0; _key < _len; _key++) {
5534
- checks[_key] = arguments[_key];
5535
- }
5536
-
5537
- return function (v, setErrors) {
5538
- var results = checks.map(function (c) {
5539
- return c(v);
5540
- }).filter(Boolean);
5541
-
5542
- if (!results.length) {
5543
- return true;
5544
- }
5545
-
5546
- var messages = results.filter(_negate(_isBoolean));
5547
-
5548
- if (messages.length) {
5549
- setErrors.apply(void 0, _toConsumableArray(messages));
5550
- }
5551
-
5552
- return false;
5553
- };
5554
- };
5555
- var timing = utils.animationTiming('0.25s ease-out');
5556
- var switchAnimation = utils.oneWayAnimation('opacity: 1;transform:translateY(0);', 'opacity: 0;', 'opacity: 0; transform:translateY(30px);');
5557
- var ExpandableBox = function ExpandableBox(_ref) {
5558
- var children = _ref.children,
5559
- info = _ref.info,
5560
- isOpen = _ref.isOpen,
5561
- openWhen = _ref.openWhen,
5562
- path = _ref.path,
5563
- _ref$retargetFilter = _ref.retargetFilter,
5564
- retargetFilter = _ref$retargetFilter === void 0 ? function (el) {
5565
- var _el$tagName;
5566
-
5567
- return (el === null || el === void 0 ? void 0 : (_el$tagName = el.tagName) === null || _el$tagName === void 0 ? void 0 : _el$tagName.toLowerCase()) === "button";
5568
- } : _ref$retargetFilter,
5569
- _ref$isValid = _ref.isValid,
5570
- isValid = _ref$isValid === void 0 ? function () {
5571
- return true;
5572
- } : _ref$isValid,
5573
- fixMarginBottom = _ref.fixMarginBottom,
5574
- _ref$animation = _ref.animation,
5575
- animation = _ref$animation === void 0 ? switchAnimation : _ref$animation,
5576
- _ref$animationTiming = _ref.animationTiming,
5577
- animationTiming = _ref$animationTiming === void 0 ? timing : _ref$animationTiming;
5578
- var flipAnimation = core.useLazyConstant(components.willUseFlipSwitch);
5579
-
5580
- var _useFormValue = form.useFormValue(path),
5581
- _useFormValue2 = _slicedToArray(_useFormValue, 3),
5582
- value = _useFormValue2[0],
5583
- setValue = _useFormValue2[1],
5584
- getValue = _useFormValue2[2];
5585
-
5586
- var _useTransientErrorHel = useTransientErrorHelper(),
5587
- _useTransientErrorHel2 = _slicedToArray(_useTransientErrorHel, 2),
5588
- _setErrors = _useTransientErrorHel2[0],
5589
- clearErrors = _useTransientErrorHel2[1];
5590
-
5591
- var setErrors = function setErrors() {
5592
- for (var _len2 = arguments.length, errors = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
5593
- errors[_key2] = arguments[_key2];
5594
- }
5595
-
5596
- _setErrors(errors.length ? errors.map(function (k) {
5597
- return _isString(k) ? [k, ''] : k;
5598
- }) : [[path, '']]);
5599
-
5600
- return true;
5601
- };
5602
-
5603
- var expand = core.useToggle(isOpen, function (newV, prevV) {
5604
- if (newV === 0 || prevV === 0) {
5605
- return;
5606
- }
5607
-
5608
- if (newV === false) {
5609
- var result = isValid(getValue(), setErrors);
5610
-
5611
- if (result === true) {
5612
- clearErrors();
5613
- }
5614
-
5615
- return result;
5616
- }
5617
- });
5618
- var openWhenResult = utils.callIfFunction(openWhen);
5619
- React.useEffect(function () {
5620
- if (openWhenResult) {
5621
- expand.open();
5622
- }
5623
- }, [openWhenResult]);
5624
- React.useEffect(function () {
5625
- return function () {
5626
- if (expand.get() === 0) {
5627
- expand.close();
5628
- }
5629
- };
5630
- }, [expand.isOpen]);
5631
- var utils$1 = core.useLazyConstant(function () {
5632
- return {
5633
- close: utils.constrainEvent(expand.close),
5634
- setValue: setValue
5635
- };
5636
- });
5637
-
5638
- var onBlur = function onBlur(e) {
5639
- if (e.currentTarget !== e.relatedTarget && (!e.relatedTarget || !e.currentTarget.contains(e.relatedTarget))) {
5640
- if (utils.callIfFunction(retargetFilter, e.relatedTarget)) {
5641
- e.target.focus();
5642
- } else {
5643
- expand.close();
5644
- }
5645
- }
5646
- };
5647
-
5648
- return React__default.createElement(ExpandableBoxStyled, {
5649
- tabIndex: -1,
5650
- onBlur: onBlur,
5651
- collapsed: !expand.isOpen,
5652
- fixMarginBottom: fixMarginBottom,
5653
- onClick: shouldPreventExpand(expand.open)
5654
- }, React__default.createElement(FlipDiv$1, {
5655
- key: expand.isOpen,
5656
- useAnimation: flipAnimation,
5657
- animation: animation,
5658
- animationTiming: animationTiming
5659
- }, expand.isOpen ? utils.callIfFunction(children, value, utils$1) : React__default.createElement(React__default.Fragment, null, utils.callIfFunction(info, value, utils$1), React__default.createElement(EditIcon, null))));
5660
- };
5661
-
5662
- var overflowEffect = function overflowEffect(element) {
5663
- var _element$offsetParent;
5664
-
5665
- if (!(element === null || element === void 0 ? void 0 : (_element$offsetParent = element.offsetParent) === null || _element$offsetParent === void 0 ? void 0 : _element$offsetParent.parentElement)) {
5666
- return;
5667
- }
5668
-
5669
- var parentDom = element.offsetParent.parentElement;
5670
- var previousOverflow = parentDom.style.overflow;
5671
- parentDom.style.overflow = 'hidden';
5672
- return function () {
5673
- return parentDom.style.overflow = previousOverflow;
5674
- };
5675
- };
5676
-
5677
- var FlipDivStyle = styled__default.div.withConfig({
5678
- displayName: "ExpandableBox__FlipDivStyle",
5679
- componentId: "sc-1nsk1wq-2"
5680
- })(["position:relative;"]);
5681
-
5682
- var FlipDiv$1 = function FlipDiv(_ref2) {
5683
- var useAnimation = _ref2.useAnimation,
5684
- animation = _ref2.animation,
5685
- animationTiming = _ref2.animationTiming,
5686
- props = _objectWithoutProperties(_ref2, ["useAnimation", "animation", "animationTiming"]);
5687
-
5688
- var ref = React.useRef();
5689
- useAnimation(ref, null, null, {
5690
- switchAnimation: animation,
5691
- timing: animationTiming,
5692
- effect: overflowEffect
5920
+ }, LABELS.popupConfirm)), React__default.createElement(Errors, null));
5693
5921
  });
5694
- return React__default.createElement(FlipDivStyle, _extends({}, props, {
5695
- ref: ref
5696
- }));
5697
5922
  };
5698
5923
 
5699
5924
  var IconRadioBoxText = styled__default.div.withConfig({
@@ -5761,11 +5986,11 @@ var Toggle = styled__default.div.withConfig({
5761
5986
  var ToggleLabel = styled__default.div.withConfig({
5762
5987
  displayName: "ToggleCheckbox__ToggleLabel",
5763
5988
  componentId: "sc-11ob8ah-2"
5764
- })(["flex-basis:0;flex-grow:1;display:inline-block;font-size:13px;"]);
5989
+ })(["flex-basis:0;flex-grow:1;display:inline-block;font-size:14px;"]);
5765
5990
  var DescText$2 = styled__default.div.withConfig({
5766
5991
  displayName: "ToggleCheckbox__DescText",
5767
5992
  componentId: "sc-11ob8ah-3"
5768
- })(["font-weight:400;color:", ";font-size:12px;margin-top:0.25rem;"], utils.getColor('gray120'));
5993
+ })(["font-weight:400;color:rgba(0,0,0,0.4);font-size:12px;margin-top:0.25rem;"]);
5769
5994
  var ToggleCheckbox = styled__default(function (_ref) {
5770
5995
  var path = _ref.path,
5771
5996
  disabled = _ref.disabled,
@@ -5799,10 +6024,10 @@ var ToggleCheckbox = styled__default(function (_ref) {
5799
6024
  return props.disabled && "\n opacity: 0.8;\n pointer-events:none;\n ";
5800
6025
  });
5801
6026
 
5802
- function _templateObject$7() {
6027
+ function _templateObject$8() {
5803
6028
  var data = _taggedTemplateLiteral(["\n min-width: 0;\n ", "\n "]);
5804
6029
 
5805
- _templateObject$7 = function _templateObject() {
6030
+ _templateObject$8 = function _templateObject() {
5806
6031
  return data;
5807
6032
  };
5808
6033
 
@@ -5821,7 +6046,7 @@ var TabButton = styled__default(components.Button).withConfig({
5821
6046
  return props.isFirst !== undefined && !props.isFirst && "\n border-bottom-left-radius: 0;\n border-top-left-radius: 0;\n :focus:after{\n border-bottom-left-radius: 2px;\n border-top-left-radius: 2px;\n }\n ";
5822
6047
  }, function (props) {
5823
6048
  return props.isLast !== undefined && !props.isLast && "\n border-bottom-right-radius: 0;\n border-top-right-radius: 0;\n :focus:after{\n border-bottom-right-radius: 2px;\n border-top-right-radius: 2px;\n z-index: 2;\n }\n ";
5824
- }, utils.media.mobile(_templateObject$7(), function (props) {
6049
+ }, utils.media.mobile(_templateObject$8(), function (props) {
5825
6050
  return props.icon ? "\n padding-left: 1.25rem;\n padding-right: 1rem;\n " : "\n padding-left: 0.25rem;\n padding-right: 0.25rem;\n ";
5826
6051
  }), utils.customTheme('TabButton'));
5827
6052
  var InnerButton = styled__default.a.withConfig({
@@ -5932,16 +6157,16 @@ var buildValidation = function buildValidation(validations) {
5932
6157
  };
5933
6158
  };
5934
6159
  var responseFailure = function responseFailure(fn) {
5935
- return function (_, response, _ref5) {
6160
+ return function (v, response, _ref5) {
5936
6161
  var setErrors = _ref5.setErrors;
5937
6162
  var errorSetter = setErrors;
5938
- var r = [].concat(response, _);
6163
+ var r = [].concat(response, v);
5939
6164
  console.log(r);
5940
6165
  var error = fn.apply(void 0, _toConsumableArray(r));
5941
6166
 
5942
6167
  if (error === true) ; else if (error) {
5943
6168
  errorSetter(error);
5944
- } else {
6169
+ } else if (!_get('response[0].errors')) {
5945
6170
  errorSetter({
5946
6171
  "": [messages.SERVER_ERROR]
5947
6172
  });
@@ -5997,6 +6222,7 @@ exports.IfFormValue = IfFormValue;
5997
6222
  exports.InputboxGroup = InputboxGroup;
5998
6223
  exports.Option = Option;
5999
6224
  exports.PathContext = PathContext;
6225
+ exports.PseudoExpandableBox = PseudoExpandableBox;
6000
6226
  exports.Radiobox = Radiobox;
6001
6227
  exports.RadioboxGroup = RadioboxGroup;
6002
6228
  exports.RichText = RichText;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startlibs/form",
3
- "version": "1.0.0-alpha-9w",
3
+ "version": "1.0.0-alpha-9z",
4
4
  "description": "Startlibs Form",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,