<reponame>outuy1000/numerweb
{"ast":null,"code":"import _defineProperty from \"@babel/runtime/helpers/esm/defineProperty\";\nimport _slicedToArray from \"@babel/runtime/helpers/esm/slicedToArray\";\nimport * as React from 'react';\nimport classNames from 'classnames';\nimport KeyCode from \"rc-util/es/KeyCode\";\nimport EnterOutlined from \"@ant-design/icons/es/icons/EnterOutlined\";\nimport TextArea from '../input/TextArea';\n\nvar Editable = function Editable(_ref) {\n  var prefixCls = _ref.prefixCls,\n      ariaLabel = _ref['aria-label'],\n      className = _ref.className,\n      style = _ref.style,\n      direction = _ref.direction,\n      maxLength = _ref.maxLength,\n      _ref$autoSize = _ref.autoSize,\n      autoSize = _ref$autoSize === void 0 ? true : _ref$autoSize,\n      value = _ref.value,\n      onSave = _ref.onSave,\n      onCancel = _ref.onCancel,\n      onEnd = _ref.onEnd;\n  var ref = React.useRef();\n  var inComposition = React.useRef(false);\n  var lastKeyCode = React.useRef();\n\n  var _React$useState = React.useState(value),\n      _React$useState2 = _slicedToArray(_React$useState, 2),\n      current = _React$useState2[0],\n      setCurrent = _React$useState2[1];\n\n  React.useEffect(function () {\n    setCurrent(value);\n  }, [value]);\n  React.useEffect(function () {\n    if (ref.current && ref.current.resizableTextArea) {\n      var textArea = ref.current.resizableTextArea.textArea;\n      textArea.focus();\n      var length = textArea.value.length;\n      textArea.setSelectionRange(length, length);\n    }\n  }, []);\n\n  var onChange = function onChange(_ref2) {\n    var target = _ref2.target;\n    setCurrent(target.value.replace(/[\\n\\r]/g, ''));\n  };\n\n  var onCompositionStart = function onCompositionStart() {\n    inComposition.current = true;\n  };\n\n  var onCompositionEnd = function onCompositionEnd() {\n    inComposition.current = false;\n  };\n\n  var onKeyDown = function onKeyDown(_ref3) {\n    var keyCode = _ref3.keyCode; // We don't record keyCode when IME is using\n\n    if (inComposition.current) return;\n    lastKeyCode.current = keyCode;\n  };\n\n  var confirmChange = function confirmChange() {\n    onSave(current.trim());\n  };\n\n  var onKeyUp = function onKeyUp(_ref4) {\n    var keyCode = _ref4.keyCode,\n        ctrlKey = _ref4.ctrlKey,\n        altKey = _ref4.altKey,\n        metaKey = _ref4.metaKey,\n        shiftKey = _ref4.shiftKey; // Check if it's a real key\n\n    if (lastKeyCode.current === keyCode && !inComposition.current && !ctrlKey && !altKey && !metaKey && !shiftKey) {\n      if (keyCode === KeyCode.ENTER) {\n        confirmChange();\n        onEnd === null || onEnd === void 0 ? void 0 : onEnd();\n      } else if (keyCode === KeyCode.ESC) {\n        onCancel();\n      }\n    }\n  };\n\n  var onBlur = function onBlur() {\n    confirmChange();\n  };\n\n  var textAreaClassName = classNames(prefixCls, \"\".concat(prefixCls, \"-edit-content\"), _defineProperty({}, \"\".concat(prefixCls, \"-rtl\"), direction === 'rtl'), className);\n  return /*#__PURE__*/React.createElement(\"div\", {\n    className: textAreaClassName,\n    style: style\n  }, /*#__PURE__*/React.createElement(TextArea, {\n    ref: ref,\n    maxLength: maxLength,\n    value: current,\n    onChange: onChange,\n    onKeyDown: onKeyDown,\n    onKeyUp: onKeyUp,\n    onCompositionStart: onCompositionStart,\n    onCompositionEnd: onCompositionEnd,\n    onBlur: onBlur,\n    \"aria-label\": ariaLabel,\n    autoSize: autoSize\n  }), /*#__PURE__*/React.createElement(EnterOutlined, {\n    className: \"\".concat(prefixCls, \"-edit-content-confirm\")\n  }));\n};\n\nexport default Editable;","map":null,"metadata":{},"sourceType":"module"}