@startlibs/form 1.0.6 → 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.
Files changed (2) hide show
  1. package/lib/index.js +42 -111
  2. package/package.json +1 -1
package/lib/index.js CHANGED
@@ -952,6 +952,7 @@ var ConfirmDialog = function ConfirmDialog(_ref2) {
952
952
  skipDom = _ref2.skipDom,
953
953
  className = _ref2.className,
954
954
  closeDialog = _ref2.closeDialog,
955
+ onClose = _ref2.onClose,
955
956
  skipCloseIcon = _ref2.skipCloseIcon,
956
957
  _ref2$cancelLabel = _ref2.cancelLabel,
957
958
  cancelLabel = _ref2$cancelLabel === void 0 ? "Cancelar" : _ref2$cancelLabel,
@@ -984,6 +985,33 @@ var ConfirmDialog = function ConfirmDialog(_ref2) {
984
985
  skipErrors = _ref2.skipErrors,
985
986
  hidden = _ref2.hidden,
986
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]);
987
1015
  return React.createElement(WithForm$1, {
988
1016
  alwaysSave: alwaysSave,
989
1017
  ref: formRef,
@@ -1002,7 +1030,7 @@ var ConfirmDialog = function ConfirmDialog(_ref2) {
1002
1030
 
1003
1031
  return Promise.resolve(callIfFunction.apply(void 0, [_onSuccess].concat(props))).then(function (v) {
1004
1032
  if (!keepOnSuccess) {
1005
- closeDialog();
1033
+ handleClose();
1006
1034
  }
1007
1035
 
1008
1036
  if (notify) {
@@ -1020,15 +1048,15 @@ var ConfirmDialog = function ConfirmDialog(_ref2) {
1020
1048
  skipCloseIcon: skipCloseIcon,
1021
1049
  confirmChanges: confirmChanges,
1022
1050
  isLoading: isLoading,
1023
- closeDialog: closeDialog,
1051
+ closeDialog: handleClose,
1024
1052
  form: form,
1025
1053
  stickyFooter: stickyFooter,
1026
1054
  auxiliarActions: auxiliarActions,
1027
1055
  fullscreen: fullscreen,
1028
1056
  fullscreenOnMobile: fullscreenOnMobile,
1029
- footer: (cancelButton || alternativeButton || confirm) && React.createElement(React.Fragment, null, cancelButton && addExtraProp(callIfFunction(cancelButton, closeDialog), {
1030
- onClick: closeDialog
1031
- }, false), callIfFunction(alternativeButton, closeDialog), confirm && using(callIfFunction(confirm, {
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, {
1032
1060
  form: form,
1033
1061
  isLoading: isLoading
1034
1062
  }))(function (c) {
@@ -3544,7 +3572,7 @@ function (_React$Component) {
3544
3572
  };
3545
3573
 
3546
3574
  _this.onChange = function (evt) {
3547
- _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));
3548
3576
  };
3549
3577
 
3550
3578
  _this.onPaste = function (ev) {
@@ -5893,45 +5921,6 @@ var cleanEditor = function cleanEditor(editor, acceptedTags) {
5893
5921
  clean(editor.childNodes);
5894
5922
  };
5895
5923
 
5896
- var insertToken = function insertToken(node, offset) {
5897
- var parent = node.parentNode;
5898
- var token = document.createElement("span");
5899
-
5900
- if (node.nodeType === Node.TEXT_NODE) {
5901
- var splitted = node.splitText(offset);
5902
- parent.insertBefore(token, splitted);
5903
- } else {
5904
- parent.insertBefore(token, node);
5905
- }
5906
-
5907
- return token;
5908
- };
5909
- /*
5910
- * pagely reformat
5911
- .replace(/^[a-z]/, function (e) {
5912
- return e.toUpperCase()
5913
- })
5914
- * */
5915
-
5916
-
5917
- var parseAndExecCommand = function parseAndExecCommand(c) {
5918
- if (c === "strikethrough" || c === "underline") {
5919
- document.execCommand('styleWithCSS', false, false);
5920
- } else {
5921
- document.execCommand('styleWithCSS', false, true);
5922
- }
5923
-
5924
- if (c.indexOf('fontSize') === 0) {
5925
- var direction = c.indexOf('Up') > 0 ? 1 : -1;
5926
- var newValue = Math.min(7, Math.max(1, parseInt(document.queryCommandValue('fontSize') || 3) + direction));
5927
- document.execCommand('fontSize', false, newValue);
5928
- } else {
5929
- var sanitizedCommand = c.indexOf("List") >= 0 && document.queryCommandState(c) ? 'outdent' : c; // FIX CHROME HANGS when list is called and already active
5930
-
5931
- document.execCommand(sanitizedCommand);
5932
- }
5933
- };
5934
-
5935
5924
  var RichText = function RichText(_ref5) {
5936
5925
  var path = _ref5.path,
5937
5926
  inputRef = _ref5.inputRef,
@@ -5989,7 +5978,7 @@ var RichText = function RichText(_ref5) {
5989
5978
 
5990
5979
  useEffect(function () {
5991
5980
  if (value === formValue && formValue !== tempValue) {
5992
- setTempValue(formValue);
5981
+ tempValue.current = formValue;
5993
5982
  }
5994
5983
  }, [path]);
5995
5984
 
@@ -6138,63 +6127,11 @@ var RichText = function RichText(_ref5) {
6138
6127
  sel.addRange(_range);
6139
6128
  }
6140
6129
 
6141
- if (window.getSelection().rangeCount) {
6142
- commands.set(window.getSelection().getRangeAt(0).collapsed ? commands.get().concat(command) : [command]);
6143
-
6144
- if (window.getSelection().getRangeAt(0).startContainer === input.current) {
6145
- // firefox ctrl+a bug
6146
- startSelectionToken.set(insertToken(input.current.firstChild, 0));
6147
- endSelectionToken.set(insertToken(input.current.lastChild, input.current.lastChild.length));
6148
- } else {
6149
- // ORDER MATTERS HERE splitText creates new text on the right https://developer.mozilla.org/en-US/docs/Web/API/Text/splitText
6150
- endSelectionToken.set(insertToken(window.getSelection().getRangeAt(0).endContainer, window.getSelection().getRangeAt(0).endOffset));
6151
- startSelectionToken.set(insertToken(window.getSelection().getRangeAt(0).startContainer, window.getSelection().getRangeAt(0).startOffset));
6152
- }
6153
- }
6154
-
6155
- containerFocused.openWith(1);
6130
+ document.execCommand(command);
6131
+ setFormValue(input.current.innerHTML);
6132
+ toggleButtonsState();
6156
6133
  focus();
6157
6134
  }
6158
-
6159
- if (command === 'insertUnorderedList' || command === 'insertOrderedList') {
6160
- var _range2 = document.createRange();
6161
-
6162
- _range2.setStart(startSelectionToken.get().nextSibling, 0);
6163
-
6164
- var _end = endSelectionToken.get().nextSibling;
6165
- startSelectionToken.get().remove();
6166
- endSelectionToken.get().remove();
6167
- startSelectionToken.set(null);
6168
- endSelectionToken.set(null);
6169
-
6170
- _range2.setEnd(_end, 0);
6171
- }
6172
- };
6173
-
6174
- var execCommandMouseUp = function execCommandMouseUp() {
6175
- if (startSelectionToken.get()) {
6176
- // window.getSelection().removeAllRanges()
6177
- var range = document.createRange();
6178
- range.setStart(startSelectionToken.get().nextSibling, 0);
6179
- var end = endSelectionToken.get().nextSibling;
6180
- startSelectionToken.get().remove();
6181
- endSelectionToken.get().remove();
6182
- startSelectionToken.set(null);
6183
- endSelectionToken.set(null);
6184
- range.setEnd(end, 0);
6185
- window.getSelection().addRange(range);
6186
- } else {
6187
- input.current.focus();
6188
- }
6189
-
6190
- commands.get().forEach(function (c) {
6191
- return parseAndExecCommand(c);
6192
- }); // commands.set(_.without(['insertUnorderedList','insertOrderedList','outdent','indent']))
6193
-
6194
- commands.set([]);
6195
- setFormValue(input.current.innerHTML);
6196
- containerFocused.openWith(2);
6197
- toggleButtonsState();
6198
6135
  };
6199
6136
 
6200
6137
  var isSelectionInsideRichTextEditor = function isSelectionInsideRichTextEditor() {
@@ -6249,7 +6186,6 @@ var RichText = function RichText(_ref5) {
6249
6186
 
6250
6187
  var handleKeyUp = function handleKeyUp(e) {
6251
6188
  toggleButtonsState();
6252
- commands.set([]);
6253
6189
  setFormValue(reformatText(input.current.innerHTML));
6254
6190
  };
6255
6191
 
@@ -6328,12 +6264,9 @@ var RichText = function RichText(_ref5) {
6328
6264
  return React.createElement(ToolButton, {
6329
6265
  key: tool,
6330
6266
  tabIndex: -1,
6331
- onMouseDown: function onMouseDown(e) {
6267
+ onClick: function onClick(e) {
6332
6268
  return execCommand(e, tool);
6333
6269
  },
6334
- onMouseUp: function onMouseUp(e) {
6335
- return execCommandMouseUp();
6336
- },
6337
6270
  className: 'button exec-command rich-text-button only-icon ' + (activatedTools[tool] ? 'activated' : ''),
6338
6271
  type: "button"
6339
6272
  }, React.createElement("span", {
@@ -6344,7 +6277,6 @@ var RichText = function RichText(_ref5) {
6344
6277
  var richTextElement = React.createElement(RichTextContainer, {
6345
6278
  linkColor: linkColor,
6346
6279
  ref: container,
6347
- onClick: stopPropagation(),
6348
6280
  onFocus: containerFocus,
6349
6281
  onBlur: containerBlur,
6350
6282
  focus: containerFocused.isOpen,
@@ -6357,11 +6289,10 @@ var RichText = function RichText(_ref5) {
6357
6289
  className: "separator",
6358
6290
  key: "separator-" + i
6359
6291
  }) : toolButton(t);
6360
- })), React.createElement(RichTextInput, {
6361
- className: JS_CLASS
6362
- }, React.createElement(ContentEditable, {
6292
+ })), React.createElement(RichTextInput, null, React.createElement(ContentEditable, {
6293
+ className: JS_CLASS,
6363
6294
  innerRef: input,
6364
- html: tempValue.current,
6295
+ html: tempValue.current || "",
6365
6296
  onBlur: onBlur,
6366
6297
  onClick: handleClick,
6367
6298
  onKeyUp: handleKeyUp,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@startlibs/form",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
4
4
  "description": "Startlibs Form",
5
5
  "main": "lib/index.js",
6
6
  "sideEffects": false,