@startlibs/form 1.0.5 → 1.0.7
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/lib/index.js +116 -206
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -37,6 +37,7 @@ import _possibleConstructorReturn from '@babel/runtime/helpers/possibleConstruct
|
|
|
37
37
|
import _getPrototypeOf from '@babel/runtime/helpers/getPrototypeOf';
|
|
38
38
|
import _inherits from '@babel/runtime/helpers/inherits';
|
|
39
39
|
import _concat from 'lodash/fp/concat';
|
|
40
|
+
import _last from 'lodash/fp/last';
|
|
40
41
|
import _without from 'lodash/fp/without';
|
|
41
42
|
import _isEqual from 'lodash/fp/isEqual';
|
|
42
43
|
import ContentEditable from 'react-contenteditable';
|
|
@@ -51,7 +52,6 @@ import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
|
51
52
|
import _isBoolean from 'lodash/fp/isBoolean';
|
|
52
53
|
import _negate from 'lodash/fp/negate';
|
|
53
54
|
import _zipObject from 'lodash/fp/zipObject';
|
|
54
|
-
import _last from 'lodash/fp/last';
|
|
55
55
|
import _flatten from 'lodash/fp/flatten';
|
|
56
56
|
import _fromPairs from 'lodash/fp/fromPairs';
|
|
57
57
|
import _pick from 'lodash/fp/pick';
|
|
@@ -650,8 +650,9 @@ var formInput = function formInput(_ref) {
|
|
|
650
650
|
return;
|
|
651
651
|
}
|
|
652
652
|
|
|
653
|
-
|
|
654
|
-
|
|
653
|
+
var transformedValue = transform(callIfFunction(value, formValue), opts);
|
|
654
|
+
setFormValue(transformedValue);
|
|
655
|
+
callIfFunction(onChange, transformedValue, opts);
|
|
655
656
|
};
|
|
656
657
|
|
|
657
658
|
var setValueFromEventTarget = function setValueFromEventTarget(e) {
|
|
@@ -951,6 +952,7 @@ var ConfirmDialog = function ConfirmDialog(_ref2) {
|
|
|
951
952
|
skipDom = _ref2.skipDom,
|
|
952
953
|
className = _ref2.className,
|
|
953
954
|
closeDialog = _ref2.closeDialog,
|
|
955
|
+
onClose = _ref2.onClose,
|
|
954
956
|
skipCloseIcon = _ref2.skipCloseIcon,
|
|
955
957
|
_ref2$cancelLabel = _ref2.cancelLabel,
|
|
956
958
|
cancelLabel = _ref2$cancelLabel === void 0 ? "Cancelar" : _ref2$cancelLabel,
|
|
@@ -983,6 +985,33 @@ var ConfirmDialog = function ConfirmDialog(_ref2) {
|
|
|
983
985
|
skipErrors = _ref2.skipErrors,
|
|
984
986
|
hidden = _ref2.hidden,
|
|
985
987
|
skipCheckFocus = _ref2.skipCheckFocus;
|
|
988
|
+
var handleClose = React.useCallback(
|
|
989
|
+
/*#__PURE__*/
|
|
990
|
+
_asyncToGenerator(
|
|
991
|
+
/*#__PURE__*/
|
|
992
|
+
_regeneratorRuntime.mark(function _callee() {
|
|
993
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
994
|
+
while (1) {
|
|
995
|
+
switch (_context.prev = _context.next) {
|
|
996
|
+
case 0:
|
|
997
|
+
if (!onClose) {
|
|
998
|
+
_context.next = 3;
|
|
999
|
+
break;
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
_context.next = 3;
|
|
1003
|
+
return onClose().catch(console.error);
|
|
1004
|
+
|
|
1005
|
+
case 3:
|
|
1006
|
+
if (closeDialog) closeDialog();
|
|
1007
|
+
|
|
1008
|
+
case 4:
|
|
1009
|
+
case "end":
|
|
1010
|
+
return _context.stop();
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}, _callee, this);
|
|
1014
|
+
})), [onClose, closeDialog]);
|
|
986
1015
|
return React.createElement(WithForm$1, {
|
|
987
1016
|
alwaysSave: alwaysSave,
|
|
988
1017
|
ref: formRef,
|
|
@@ -1001,7 +1030,7 @@ var ConfirmDialog = function ConfirmDialog(_ref2) {
|
|
|
1001
1030
|
|
|
1002
1031
|
return Promise.resolve(callIfFunction.apply(void 0, [_onSuccess].concat(props))).then(function (v) {
|
|
1003
1032
|
if (!keepOnSuccess) {
|
|
1004
|
-
|
|
1033
|
+
handleClose();
|
|
1005
1034
|
}
|
|
1006
1035
|
|
|
1007
1036
|
if (notify) {
|
|
@@ -1019,15 +1048,15 @@ var ConfirmDialog = function ConfirmDialog(_ref2) {
|
|
|
1019
1048
|
skipCloseIcon: skipCloseIcon,
|
|
1020
1049
|
confirmChanges: confirmChanges,
|
|
1021
1050
|
isLoading: isLoading,
|
|
1022
|
-
closeDialog:
|
|
1051
|
+
closeDialog: handleClose,
|
|
1023
1052
|
form: form,
|
|
1024
1053
|
stickyFooter: stickyFooter,
|
|
1025
1054
|
auxiliarActions: auxiliarActions,
|
|
1026
1055
|
fullscreen: fullscreen,
|
|
1027
1056
|
fullscreenOnMobile: fullscreenOnMobile,
|
|
1028
|
-
footer: (cancelButton || alternativeButton || confirm) && React.createElement(React.Fragment, null, cancelButton && addExtraProp(callIfFunction(cancelButton,
|
|
1029
|
-
onClick:
|
|
1030
|
-
}, false), callIfFunction(alternativeButton,
|
|
1057
|
+
footer: (cancelButton || alternativeButton || confirm) && React.createElement(React.Fragment, null, cancelButton && addExtraProp(callIfFunction(cancelButton, handleClose), {
|
|
1058
|
+
onClick: handleClose
|
|
1059
|
+
}, false), callIfFunction(alternativeButton, handleClose), confirm && using(callIfFunction(confirm, {
|
|
1031
1060
|
form: form,
|
|
1032
1061
|
isLoading: isLoading
|
|
1033
1062
|
}))(function (c) {
|
|
@@ -1136,6 +1165,7 @@ var useTextInput = function useTextInput(_ref, ref) {
|
|
|
1136
1165
|
var onFocus = _ref.onFocus,
|
|
1137
1166
|
onBlur = _ref.onBlur,
|
|
1138
1167
|
autoResize = _ref.autoResize,
|
|
1168
|
+
autoSelectOnFocus = _ref.autoSelectOnFocus,
|
|
1139
1169
|
constraint = _ref.constraint,
|
|
1140
1170
|
pattern = _ref.pattern,
|
|
1141
1171
|
path = _ref.path,
|
|
@@ -1146,7 +1176,7 @@ var useTextInput = function useTextInput(_ref, ref) {
|
|
|
1146
1176
|
raw = _ref.raw,
|
|
1147
1177
|
showValue = _ref.showValue,
|
|
1148
1178
|
deleteTrailing = _ref.deleteTrailing,
|
|
1149
|
-
rest = _objectWithoutProperties(_ref, ["onFocus", "onBlur", "autoResize", "constraint", "pattern", "path", "rawValue", "rawSetValue", "rawHasErrors", "transformOnBlur", "raw", "showValue", "deleteTrailing"]);
|
|
1179
|
+
rest = _objectWithoutProperties(_ref, ["onFocus", "onBlur", "autoResize", "autoSelectOnFocus", "constraint", "pattern", "path", "rawValue", "rawSetValue", "rawHasErrors", "transformOnBlur", "raw", "showValue", "deleteTrailing"]);
|
|
1150
1180
|
|
|
1151
1181
|
var _useInput = useInput$1(_objectSpread({
|
|
1152
1182
|
path: path,
|
|
@@ -1168,6 +1198,15 @@ var useTextInput = function useTextInput(_ref, ref) {
|
|
|
1168
1198
|
|
|
1169
1199
|
var handleOnFocus = function handleOnFocus(e) {
|
|
1170
1200
|
setFocused(true);
|
|
1201
|
+
|
|
1202
|
+
if (!!autoSelectOnFocus && !!ref.current) {
|
|
1203
|
+
setTimeout(function () {
|
|
1204
|
+
var _ref$current;
|
|
1205
|
+
|
|
1206
|
+
return (_ref$current = ref.current) === null || _ref$current === void 0 ? void 0 : _ref$current.select();
|
|
1207
|
+
}, 0);
|
|
1208
|
+
}
|
|
1209
|
+
|
|
1171
1210
|
callIfFunction(onFocus, e);
|
|
1172
1211
|
};
|
|
1173
1212
|
|
|
@@ -1190,6 +1229,15 @@ var useTextInput = function useTextInput(_ref, ref) {
|
|
|
1190
1229
|
doAutoResize(ref.current);
|
|
1191
1230
|
}
|
|
1192
1231
|
}, []);
|
|
1232
|
+
useEffect(function () {
|
|
1233
|
+
if (!!autoSelectOnFocus && !!ref.current && document.activeElement === ref.current) {
|
|
1234
|
+
setTimeout(function () {
|
|
1235
|
+
var _ref$current2;
|
|
1236
|
+
|
|
1237
|
+
return (_ref$current2 = ref.current) === null || _ref$current2 === void 0 ? void 0 : _ref$current2.select();
|
|
1238
|
+
}, 0);
|
|
1239
|
+
}
|
|
1240
|
+
}, [autoSelectOnFocus]);
|
|
1193
1241
|
|
|
1194
1242
|
var handleChange = function handleChange(e) {
|
|
1195
1243
|
if (autoResize) {
|
|
@@ -1312,6 +1360,7 @@ var TextInput = styled(forwardRef(function (_ref2, forwardedRef) {
|
|
|
1312
1360
|
onImage = _ref2$onImage === void 0 ? false : _ref2$onImage,
|
|
1313
1361
|
autoFocus = _ref2.autoFocus,
|
|
1314
1362
|
noFocus = _ref2.noFocus,
|
|
1363
|
+
autoSelectOnFocus = _ref2.autoSelectOnFocus,
|
|
1315
1364
|
onFocus = _ref2.onFocus,
|
|
1316
1365
|
onBlur = _ref2.onBlur,
|
|
1317
1366
|
pattern = _ref2.pattern,
|
|
@@ -1321,7 +1370,7 @@ var TextInput = styled(forwardRef(function (_ref2, forwardedRef) {
|
|
|
1321
1370
|
raw = _ref2.raw,
|
|
1322
1371
|
_ref2$tabIndex = _ref2.tabIndex,
|
|
1323
1372
|
tabIndex = _ref2$tabIndex === void 0 ? 1 : _ref2$tabIndex,
|
|
1324
|
-
rest = _objectWithoutProperties(_ref2, ["showValue", "label", "type", "helpText", "descText", "bellowDescText", "mandatory", "isLoading", "locked", "textBoxBefore", "textBoxAfter", "className", "fieldClassName", "FieldType", "margin", "value", "setValue", "hasErrors", "textarea", "onImage", "autoFocus", "noFocus", "onFocus", "onBlur", "pattern", "autoResize", "constraint", "path", "raw", "tabIndex"]);
|
|
1373
|
+
rest = _objectWithoutProperties(_ref2, ["showValue", "label", "type", "helpText", "descText", "bellowDescText", "mandatory", "isLoading", "locked", "textBoxBefore", "textBoxAfter", "className", "fieldClassName", "FieldType", "margin", "value", "setValue", "hasErrors", "textarea", "onImage", "autoFocus", "noFocus", "autoSelectOnFocus", "onFocus", "onBlur", "pattern", "autoResize", "constraint", "path", "raw", "tabIndex"]);
|
|
1325
1374
|
|
|
1326
1375
|
var ref = useEnsureRef(forwardedRef);
|
|
1327
1376
|
|
|
@@ -1330,6 +1379,7 @@ var TextInput = styled(forwardRef(function (_ref2, forwardedRef) {
|
|
|
1330
1379
|
onFocus: onFocus,
|
|
1331
1380
|
onBlur: onBlur,
|
|
1332
1381
|
autoResize: autoResize,
|
|
1382
|
+
autoSelectOnFocus: autoSelectOnFocus,
|
|
1333
1383
|
constraint: constraint,
|
|
1334
1384
|
pattern: pattern,
|
|
1335
1385
|
rawValue: rawValue,
|
|
@@ -2948,6 +2998,7 @@ var DropdownIconContainer = styled(Icon).withConfig({
|
|
|
2948
2998
|
var focusBeforeLast = function focusBeforeLast(e) {
|
|
2949
2999
|
if (e.target && e.target !== e.currentTarget) return;
|
|
2950
3000
|
var el = [].slice.call(e.currentTarget.querySelectorAll('div[contenteditable]')).slice(-1)[0];
|
|
3001
|
+
if (!el) return;
|
|
2951
3002
|
el.focus();
|
|
2952
3003
|
|
|
2953
3004
|
if (!el.firstChild) {
|
|
@@ -3089,7 +3140,7 @@ var AutoComplete = React.forwardRef(function (_ref, outerRef) {
|
|
|
3089
3140
|
};
|
|
3090
3141
|
|
|
3091
3142
|
var shouldFocusInput = useToggle();
|
|
3092
|
-
var recentlyAdded = useRefState();
|
|
3143
|
+
var recentlyAdded = useRefState(false);
|
|
3093
3144
|
useEffect(function () {
|
|
3094
3145
|
if (autoFocus) {
|
|
3095
3146
|
focusInput();
|
|
@@ -3196,7 +3247,12 @@ var AutoComplete = React.forwardRef(function (_ref, outerRef) {
|
|
|
3196
3247
|
|
|
3197
3248
|
useEffect(function () {
|
|
3198
3249
|
if (!lastIsEditable) {
|
|
3199
|
-
|
|
3250
|
+
if (recentlyAdded.get() !== _cancelEditable.current) {
|
|
3251
|
+
setFormValue(_without([_cancelEditable.current], formValue).concat(""));
|
|
3252
|
+
} else {
|
|
3253
|
+
setLocalFormValue(_last(formValue) === "" ? formValue : formValue.concat(""));
|
|
3254
|
+
}
|
|
3255
|
+
|
|
3200
3256
|
_cancelEditable.current = null;
|
|
3201
3257
|
}
|
|
3202
3258
|
}, [lastIsEditable]);
|
|
@@ -3259,8 +3315,8 @@ var AutoComplete = React.forwardRef(function (_ref, outerRef) {
|
|
|
3259
3315
|
|
|
3260
3316
|
var addValue = function addValue(value, fromBlur) {
|
|
3261
3317
|
var index = Math.max(lastIsEditable ? getValue().length - 1 : getValue().length, 0);
|
|
3318
|
+
recentlyAdded.set((formValue === null || formValue === void 0 ? void 0 : formValue[index]) || "");
|
|
3262
3319
|
setFormValue(_flow(_set([index], value), _concat(_concat.placeholder, "")));
|
|
3263
|
-
recentlyAdded.set(true);
|
|
3264
3320
|
|
|
3265
3321
|
if (!fromBlur) {
|
|
3266
3322
|
focusInput();
|
|
@@ -3516,7 +3572,7 @@ function (_React$Component) {
|
|
|
3516
3572
|
};
|
|
3517
3573
|
|
|
3518
3574
|
_this.onChange = function (evt) {
|
|
3519
|
-
_this.props.onChange(_this.props.index, cleanText(evt.target.value));
|
|
3575
|
+
_this.props.onChange(_this.props.index, cleanText(evt.currentTarget.isContentEditable ? evt.currentTarget.innerText : evt.target.value));
|
|
3520
3576
|
};
|
|
3521
3577
|
|
|
3522
3578
|
_this.onPaste = function (ev) {
|
|
@@ -4210,7 +4266,7 @@ var EditableBox = function EditableBox(_ref17) {
|
|
|
4210
4266
|
var internalBox = React.useRef();
|
|
4211
4267
|
|
|
4212
4268
|
var resetField = function resetField() {
|
|
4213
|
-
return path ? form.resetField(
|
|
4269
|
+
return path ? form.resetField(_s.toPath(path)) : form.resetForm();
|
|
4214
4270
|
};
|
|
4215
4271
|
|
|
4216
4272
|
var _onClose = function _onClose(skipReset) {
|
|
@@ -4783,7 +4839,7 @@ var DatePicker = forwardRef(function (_ref, maybeInputRef) {
|
|
|
4783
4839
|
}, 1);
|
|
4784
4840
|
}
|
|
4785
4841
|
}, [textValue]);
|
|
4786
|
-
var isShortcutsEnabled = daysFromNowShortcuts && daysFromNowShortcuts.length > 0 || monthsFromNowShortcuts && monthsFromNowShortcuts.length > 0;
|
|
4842
|
+
var isShortcutsEnabled = !!daysFromNowShortcuts && daysFromNowShortcuts.length > 0 || !!monthsFromNowShortcuts && monthsFromNowShortcuts.length > 0;
|
|
4787
4843
|
|
|
4788
4844
|
var setDateToNDaysFromNow = function setDateToNDaysFromNow(daysFromNow) {
|
|
4789
4845
|
var date = new Date(now());
|
|
@@ -4937,7 +4993,7 @@ var DatePicker = forwardRef(function (_ref, maybeInputRef) {
|
|
|
4937
4993
|
onClick: iconClick,
|
|
4938
4994
|
icon: "calendar",
|
|
4939
4995
|
className: isShortcutsEnabled ? "hasShortcuts" : ""
|
|
4940
|
-
})), (daysFromNowShortcuts === null || daysFromNowShortcuts === void 0 ? void 0 : daysFromNowShortcuts.length) > 0 || (monthsFromNowShortcuts === null || monthsFromNowShortcuts === void 0 ? void 0 : monthsFromNowShortcuts.length) > 0 ? React.createElement(ShortcutsWrapper, null, React.createElement("span", null, "Em:"), daysFromNowShortcuts.map(function (daysFromNow) {
|
|
4996
|
+
})), (daysFromNowShortcuts === null || daysFromNowShortcuts === void 0 ? void 0 : daysFromNowShortcuts.length) > 0 || (monthsFromNowShortcuts === null || monthsFromNowShortcuts === void 0 ? void 0 : monthsFromNowShortcuts.length) > 0 ? React.createElement(ShortcutsWrapper, null, React.createElement("span", null, "Em:"), daysFromNowShortcuts === null || daysFromNowShortcuts === void 0 ? void 0 : daysFromNowShortcuts.map(function (daysFromNow) {
|
|
4941
4997
|
return React.createElement("span", {
|
|
4942
4998
|
class: "link",
|
|
4943
4999
|
key: "days-from-now-".concat(daysFromNow),
|
|
@@ -4946,7 +5002,7 @@ var DatePicker = forwardRef(function (_ref, maybeInputRef) {
|
|
|
4946
5002
|
},
|
|
4947
5003
|
disabled: disabled
|
|
4948
5004
|
}, daysFromNow, " dia", daysFromNow > 1 ? 's' : '');
|
|
4949
|
-
}), monthsFromNowShortcuts.map(function (monthsFromNow) {
|
|
5005
|
+
}), monthsFromNowShortcuts === null || monthsFromNowShortcuts === void 0 ? void 0 : monthsFromNowShortcuts.map(function (monthsFromNow) {
|
|
4950
5006
|
return React.createElement("span", {
|
|
4951
5007
|
class: "link",
|
|
4952
5008
|
key: "months-from-now".concat(monthsFromNow),
|
|
@@ -5709,7 +5765,7 @@ var RichTextContainer = styled.div.withConfig({
|
|
|
5709
5765
|
var RichTextInput = styled.div.withConfig({
|
|
5710
5766
|
displayName: "RichText__RichTextInput",
|
|
5711
5767
|
componentId: "x8c1ig-2"
|
|
5712
|
-
})(["
|
|
5768
|
+
})(["font-size:14px;color:", ";background:white;border-radius:5px;> div{overflow:auto;width:100%;outline:none;min-height:", "px;padding:0.7rem;}b,strong{font-weight:600;}&[contenteditable=true]:empty:before{content:attr(placeholder);color:rgba(0,0,0,0.3);}", ""], getColor('gray60'), function (props) {
|
|
5713
5769
|
return props.minHeight || 78;
|
|
5714
5770
|
}, function (props) {
|
|
5715
5771
|
return props.disabled && "\n &[disabled] {\n background: rgba(0, 0, 0, 0.075) !important;\n opacity: 0.75 !important;\n }\n ";
|
|
@@ -5749,14 +5805,6 @@ var addHttp = function addHttp(s) {
|
|
|
5749
5805
|
}
|
|
5750
5806
|
};
|
|
5751
5807
|
|
|
5752
|
-
var getRightMostElement = function getRightMostElement(node) {
|
|
5753
|
-
if (node.childNodes.length) {
|
|
5754
|
-
return getRightMostElement(node.childNodes[node.childNodes.length - 1]);
|
|
5755
|
-
} else {
|
|
5756
|
-
return node;
|
|
5757
|
-
}
|
|
5758
|
-
};
|
|
5759
|
-
|
|
5760
5808
|
var setSelectionRange$1 = function setSelectionRange(input, selectionStart) {
|
|
5761
5809
|
var selectionEnd = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
5762
5810
|
if (!input) return;
|
|
@@ -5873,45 +5921,6 @@ var cleanEditor = function cleanEditor(editor, acceptedTags) {
|
|
|
5873
5921
|
clean(editor.childNodes);
|
|
5874
5922
|
};
|
|
5875
5923
|
|
|
5876
|
-
var insertToken = function insertToken(node, offset) {
|
|
5877
|
-
var parent = node.parentNode;
|
|
5878
|
-
var token = document.createElement("span");
|
|
5879
|
-
|
|
5880
|
-
if (node.nodeType === Node.TEXT_NODE) {
|
|
5881
|
-
var splitted = node.splitText(offset);
|
|
5882
|
-
parent.insertBefore(token, splitted);
|
|
5883
|
-
} else {
|
|
5884
|
-
parent.insertBefore(token, node);
|
|
5885
|
-
}
|
|
5886
|
-
|
|
5887
|
-
return token;
|
|
5888
|
-
};
|
|
5889
|
-
/*
|
|
5890
|
-
* pagely reformat
|
|
5891
|
-
.replace(/^[a-z]/, function (e) {
|
|
5892
|
-
return e.toUpperCase()
|
|
5893
|
-
})
|
|
5894
|
-
* */
|
|
5895
|
-
|
|
5896
|
-
|
|
5897
|
-
var parseAndExecCommand = function parseAndExecCommand(c) {
|
|
5898
|
-
if (c === "strikethrough" || c === "underline") {
|
|
5899
|
-
document.execCommand('styleWithCSS', false, false);
|
|
5900
|
-
} else {
|
|
5901
|
-
document.execCommand('styleWithCSS', false, true);
|
|
5902
|
-
}
|
|
5903
|
-
|
|
5904
|
-
if (c.indexOf('fontSize') === 0) {
|
|
5905
|
-
var direction = c.indexOf('Up') > 0 ? 1 : -1;
|
|
5906
|
-
var newValue = Math.min(7, Math.max(1, parseInt(document.queryCommandValue('fontSize') || 3) + direction));
|
|
5907
|
-
document.execCommand('fontSize', false, newValue);
|
|
5908
|
-
} else {
|
|
5909
|
-
var sanitizedCommand = c.indexOf("List") >= 0 && document.queryCommandState(c) ? 'outdent' : c; // FIX CHROME HANGS when list is called and already active
|
|
5910
|
-
|
|
5911
|
-
document.execCommand(sanitizedCommand);
|
|
5912
|
-
}
|
|
5913
|
-
};
|
|
5914
|
-
|
|
5915
5924
|
var RichText = function RichText(_ref5) {
|
|
5916
5925
|
var path = _ref5.path,
|
|
5917
5926
|
inputRef = _ref5.inputRef,
|
|
@@ -5955,25 +5964,28 @@ var RichText = function RichText(_ref5) {
|
|
|
5955
5964
|
}, raw),
|
|
5956
5965
|
_useInput2 = _slicedToArray(_useInput, 3),
|
|
5957
5966
|
formValue = _useInput2[0],
|
|
5958
|
-
|
|
5967
|
+
_setFormValue = _useInput2[1],
|
|
5959
5968
|
hasErrors = _useInput2[2].hasErrors; // const tempValue = useConstant(formValue)
|
|
5960
5969
|
|
|
5961
5970
|
|
|
5962
|
-
var
|
|
5963
|
-
|
|
5964
|
-
|
|
5965
|
-
|
|
5971
|
+
var tempValue = useRef(formValue);
|
|
5972
|
+
|
|
5973
|
+
var setFormValue = function setFormValue(v) {
|
|
5974
|
+
tempValue.current = v;
|
|
5975
|
+
|
|
5976
|
+
_setFormValue(v);
|
|
5977
|
+
};
|
|
5966
5978
|
|
|
5967
5979
|
useEffect(function () {
|
|
5968
5980
|
if (value === formValue && formValue !== tempValue) {
|
|
5969
|
-
|
|
5981
|
+
tempValue.current = formValue;
|
|
5970
5982
|
}
|
|
5971
5983
|
}, [path]);
|
|
5972
5984
|
|
|
5973
|
-
var
|
|
5974
|
-
|
|
5975
|
-
activatedTools =
|
|
5976
|
-
setActivatedTools =
|
|
5985
|
+
var _useState = useState({}),
|
|
5986
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
5987
|
+
activatedTools = _useState2[0],
|
|
5988
|
+
setActivatedTools = _useState2[1];
|
|
5977
5989
|
|
|
5978
5990
|
var validElements = useLazyConstant(function () {
|
|
5979
5991
|
return ['br', 'div', 'p', 'span'].concat(_flatten(formatTools.map(function (tool) {
|
|
@@ -6097,6 +6109,7 @@ var RichText = function RichText(_ref5) {
|
|
|
6097
6109
|
}
|
|
6098
6110
|
}
|
|
6099
6111
|
|
|
6112
|
+
tempValue.current = input.current.innerHTML;
|
|
6100
6113
|
openDialog(nodeEl);
|
|
6101
6114
|
} else {
|
|
6102
6115
|
if (!isSelectionInsideRichTextEditor()) {
|
|
@@ -6114,63 +6127,11 @@ var RichText = function RichText(_ref5) {
|
|
|
6114
6127
|
sel.addRange(_range);
|
|
6115
6128
|
}
|
|
6116
6129
|
|
|
6117
|
-
|
|
6118
|
-
|
|
6119
|
-
|
|
6120
|
-
if (window.getSelection().getRangeAt(0).startContainer === input.current) {
|
|
6121
|
-
// firefox ctrl+a bug
|
|
6122
|
-
startSelectionToken.set(insertToken(input.current.firstChild, 0));
|
|
6123
|
-
endSelectionToken.set(insertToken(input.current.lastChild, input.current.lastChild.length));
|
|
6124
|
-
} else {
|
|
6125
|
-
// ORDER MATTERS HERE splitText creates new text on the right https://developer.mozilla.org/en-US/docs/Web/API/Text/splitText
|
|
6126
|
-
endSelectionToken.set(insertToken(window.getSelection().getRangeAt(0).endContainer, window.getSelection().getRangeAt(0).endOffset));
|
|
6127
|
-
startSelectionToken.set(insertToken(window.getSelection().getRangeAt(0).startContainer, window.getSelection().getRangeAt(0).startOffset));
|
|
6128
|
-
}
|
|
6129
|
-
}
|
|
6130
|
-
|
|
6131
|
-
containerFocused.openWith(1);
|
|
6130
|
+
document.execCommand(command);
|
|
6131
|
+
setFormValue(input.current.innerHTML);
|
|
6132
|
+
toggleButtonsState();
|
|
6132
6133
|
focus();
|
|
6133
6134
|
}
|
|
6134
|
-
|
|
6135
|
-
if (command === 'insertUnorderedList' || command === 'insertOrderedList') {
|
|
6136
|
-
var _range2 = document.createRange();
|
|
6137
|
-
|
|
6138
|
-
_range2.setStart(startSelectionToken.get().nextSibling, 0);
|
|
6139
|
-
|
|
6140
|
-
var _end = endSelectionToken.get().nextSibling;
|
|
6141
|
-
startSelectionToken.get().remove();
|
|
6142
|
-
endSelectionToken.get().remove();
|
|
6143
|
-
startSelectionToken.set(null);
|
|
6144
|
-
endSelectionToken.set(null);
|
|
6145
|
-
|
|
6146
|
-
_range2.setEnd(_end, 0);
|
|
6147
|
-
}
|
|
6148
|
-
};
|
|
6149
|
-
|
|
6150
|
-
var execCommandMouseUp = function execCommandMouseUp() {
|
|
6151
|
-
if (startSelectionToken.get()) {
|
|
6152
|
-
// window.getSelection().removeAllRanges()
|
|
6153
|
-
var range = document.createRange();
|
|
6154
|
-
range.setStart(startSelectionToken.get().nextSibling, 0);
|
|
6155
|
-
var end = endSelectionToken.get().nextSibling;
|
|
6156
|
-
startSelectionToken.get().remove();
|
|
6157
|
-
endSelectionToken.get().remove();
|
|
6158
|
-
startSelectionToken.set(null);
|
|
6159
|
-
endSelectionToken.set(null);
|
|
6160
|
-
range.setEnd(end, 0);
|
|
6161
|
-
window.getSelection().addRange(range);
|
|
6162
|
-
} else {
|
|
6163
|
-
input.current.focus();
|
|
6164
|
-
}
|
|
6165
|
-
|
|
6166
|
-
commands.get().forEach(function (c) {
|
|
6167
|
-
return parseAndExecCommand(c);
|
|
6168
|
-
}); // commands.set(_.without(['insertUnorderedList','insertOrderedList','outdent','indent']))
|
|
6169
|
-
|
|
6170
|
-
commands.set([]);
|
|
6171
|
-
setFormValue(input.current.innerHTML);
|
|
6172
|
-
containerFocused.openWith(2);
|
|
6173
|
-
toggleButtonsState();
|
|
6174
6135
|
};
|
|
6175
6136
|
|
|
6176
6137
|
var isSelectionInsideRichTextEditor = function isSelectionInsideRichTextEditor() {
|
|
@@ -6225,72 +6186,28 @@ var RichText = function RichText(_ref5) {
|
|
|
6225
6186
|
|
|
6226
6187
|
var handleKeyUp = function handleKeyUp(e) {
|
|
6227
6188
|
toggleButtonsState();
|
|
6228
|
-
commands.set([]);
|
|
6229
6189
|
setFormValue(reformatText(input.current.innerHTML));
|
|
6230
6190
|
};
|
|
6231
6191
|
|
|
6232
6192
|
var handleKeyDown = function handleKeyDown(e) {
|
|
6233
|
-
if (linkJustCreated.current && e.which === 8) {
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
|
|
6237
|
-
|
|
6238
|
-
|
|
6239
|
-
|
|
6240
|
-
|
|
6241
|
-
|
|
6242
|
-
|
|
6243
|
-
|
|
6244
|
-
|
|
6245
|
-
|
|
6246
|
-
|
|
6247
|
-
|
|
6248
|
-
|
|
6249
|
-
|
|
6250
|
-
|
|
6251
|
-
traverseAndAddLink(range);
|
|
6252
|
-
}
|
|
6253
|
-
};
|
|
6254
|
-
|
|
6255
|
-
var traverseAndAddLink = function traverseAndAddLink(range) {
|
|
6256
|
-
var match = range.toString().match(/[\s\t\n\r]([^\s\t\n\r]*)$/);
|
|
6257
|
-
|
|
6258
|
-
if (match) {
|
|
6259
|
-
if (/^(https?:\/\/|www\.)/.test(match[1]) && linkRegex.test(match[1])) {
|
|
6260
|
-
range.setStart(range.startContainer, match.index + 1);
|
|
6261
|
-
range.endContainer.splitText(range.endContainer.textContent.length - 1);
|
|
6262
|
-
var newNode = document.createElement('a');
|
|
6263
|
-
newNode.href = match[1];
|
|
6264
|
-
newNode.appendChild(range.extractContents());
|
|
6265
|
-
range.insertNode(newNode);
|
|
6266
|
-
window.getSelection().getRangeAt(0).setEndAfter(newNode);
|
|
6267
|
-
window.getSelection().getRangeAt(0).setStartAfter(newNode);
|
|
6268
|
-
linkJustCreated.set(newNode);
|
|
6269
|
-
}
|
|
6270
|
-
} else {
|
|
6271
|
-
var previous = getPreviousElement(range.startContainer);
|
|
6272
|
-
|
|
6273
|
-
if (previous) {
|
|
6274
|
-
range.setStart(previous, 0);
|
|
6275
|
-
traverseAndAddLink(range);
|
|
6276
|
-
}
|
|
6277
|
-
}
|
|
6278
|
-
};
|
|
6279
|
-
|
|
6280
|
-
var getPreviousElement = function getPreviousElement(node) {
|
|
6281
|
-
if (node.previousSibling) {
|
|
6282
|
-
var rightMost = getRightMostElement(node.previousSibling);
|
|
6283
|
-
|
|
6284
|
-
if (rightMost.nodeType === Node.TEXT_NODE) {
|
|
6285
|
-
return rightMost;
|
|
6286
|
-
} else {
|
|
6287
|
-
return getPreviousElement(rightMost);
|
|
6288
|
-
}
|
|
6289
|
-
} else if (node.parentNode && node !== input.current) {
|
|
6290
|
-
return getPreviousElement(node.parentNode);
|
|
6291
|
-
} else {
|
|
6292
|
-
return null;
|
|
6293
|
-
}
|
|
6193
|
+
/*if (linkJustCreated.current && e.which === 8) {
|
|
6194
|
+
linkJustCreated.current.outerHTML = linkJustCreated.current.innerHTML
|
|
6195
|
+
input.current.normalize()
|
|
6196
|
+
return
|
|
6197
|
+
}
|
|
6198
|
+
commands.set([])
|
|
6199
|
+
linkJustCreated.set(null)
|
|
6200
|
+
const selectedRange = window.getSelection().getRangeAt(0)
|
|
6201
|
+
if (!selectedRange) return
|
|
6202
|
+
const possibleTextNode = selectedRange.startContainer
|
|
6203
|
+
const node = possibleTextNode.nodeType === Node.TEXT_NODE ? possibleTextNode.parentNode : possibleTextNode
|
|
6204
|
+
const parent = node.closest('a,.'+JS_CLASS)
|
|
6205
|
+
if ((e.key === 'Enter' || e.which === 32) && parent && parent.matches('.'+JS_CLASS)) {
|
|
6206
|
+
const range = document.createRange()
|
|
6207
|
+
range.setEnd(selectedRange.startContainer, selectedRange.startOffset)
|
|
6208
|
+
range.setStart(selectedRange.startContainer, 0)
|
|
6209
|
+
traverseAndAddLink(range)
|
|
6210
|
+
}*/
|
|
6294
6211
|
};
|
|
6295
6212
|
|
|
6296
6213
|
var handlePasteDrop = function handlePasteDrop(e) {
|
|
@@ -6347,12 +6264,9 @@ var RichText = function RichText(_ref5) {
|
|
|
6347
6264
|
return React.createElement(ToolButton, {
|
|
6348
6265
|
key: tool,
|
|
6349
6266
|
tabIndex: -1,
|
|
6350
|
-
|
|
6267
|
+
onClick: function onClick(e) {
|
|
6351
6268
|
return execCommand(e, tool);
|
|
6352
6269
|
},
|
|
6353
|
-
onMouseUp: function onMouseUp(e) {
|
|
6354
|
-
return execCommandMouseUp();
|
|
6355
|
-
},
|
|
6356
6270
|
className: 'button exec-command rich-text-button only-icon ' + (activatedTools[tool] ? 'activated' : ''),
|
|
6357
6271
|
type: "button"
|
|
6358
6272
|
}, React.createElement("span", {
|
|
@@ -6363,7 +6277,6 @@ var RichText = function RichText(_ref5) {
|
|
|
6363
6277
|
var richTextElement = React.createElement(RichTextContainer, {
|
|
6364
6278
|
linkColor: linkColor,
|
|
6365
6279
|
ref: container,
|
|
6366
|
-
onClick: stopPropagation(),
|
|
6367
6280
|
onFocus: containerFocus,
|
|
6368
6281
|
onBlur: containerBlur,
|
|
6369
6282
|
focus: containerFocused.isOpen,
|
|
@@ -6376,9 +6289,10 @@ var RichText = function RichText(_ref5) {
|
|
|
6376
6289
|
className: "separator",
|
|
6377
6290
|
key: "separator-" + i
|
|
6378
6291
|
}) : toolButton(t);
|
|
6379
|
-
})), React.createElement(RichTextInput, {
|
|
6380
|
-
|
|
6381
|
-
|
|
6292
|
+
})), React.createElement(RichTextInput, null, React.createElement(ContentEditable, {
|
|
6293
|
+
className: JS_CLASS,
|
|
6294
|
+
innerRef: input,
|
|
6295
|
+
html: tempValue.current || "",
|
|
6382
6296
|
onBlur: onBlur,
|
|
6383
6297
|
onClick: handleClick,
|
|
6384
6298
|
onKeyUp: handleKeyUp,
|
|
@@ -6386,14 +6300,10 @@ var RichText = function RichText(_ref5) {
|
|
|
6386
6300
|
onPaste: handlePasteDrop,
|
|
6387
6301
|
onDrop: handlePasteDrop,
|
|
6388
6302
|
tabIndex: tabIndex,
|
|
6389
|
-
dangerouslySetInnerHTML: {
|
|
6390
|
-
__html: tempValue
|
|
6391
|
-
},
|
|
6392
6303
|
disabled: disabled,
|
|
6393
|
-
className: JS_CLASS,
|
|
6394
6304
|
minHeight: minHeight,
|
|
6395
6305
|
placeholder: placeholder
|
|
6396
|
-
}), locked && React.createElement(InputIcon, {
|
|
6306
|
+
})), locked && React.createElement(InputIcon, {
|
|
6397
6307
|
icon: "lock"
|
|
6398
6308
|
}), linkPopup.isOpen && React.createElement(EditLinkPopup, {
|
|
6399
6309
|
input: input,
|