Nav apraksta

index.js 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import React, { useState } from 'react';
  2. import { s as styleInject } from '../style-inject.es-1f59c1d0.js';
  3. import { _ as _defineProperty } from '../defineProperty-18999f8e.js';
  4. import { c as classnames } from '../index-e3cf212a.js';
  5. import { _ as _slicedToArray } from '../slicedToArray-4cd9e6d3.js';
  6. import BraftEditor from 'braft-editor';
  7. import 'braft-editor/dist/index.css';
  8. import 'braft-extensions/dist/emoticon.css';
  9. import Emoticon, { defaultEmoticons } from 'braft-extensions/dist/emoticon';
  10. import MaxLength from 'braft-extensions/dist/max-length';
  11. var css = ".index_baseWrapper__1_-58 {\n position: relative;\n}\n.index_baseWrapper__1_-58 .bf-container {\n display: flex;\n flex-direction: column;\n}\n.index_baseWrapper__1_-58 .bf-container .index_controlBar__3SzSH {\n box-shadow: none;\n}\n.index_baseWrapper__1_-58 .bf-container .index_editorContent__2UOaX {\n border: 1px solid #ccc;\n border-radius: 4px;\n height: auto;\n transition: border-color 0.3s;\n}\n.index_baseWrapper__1_-58 .bf-container .index_editorContent__2UOaX.index_focus__puDJA {\n border-color: #1790ff;\n}\n.index_baseWrapper__1_-58 .index_floatControls__2hVPf {\n position: absolute;\n right: 15px;\n bottom: 15px;\n display: flex;\n z-index: 2;\n}\n";
  12. var styles = {
  13. "baseWrapper": "index_baseWrapper__1_-58",
  14. "controlBar": "index_controlBar__3SzSH",
  15. "editorContent": "index_editorContent__2UOaX",
  16. "focus": "index_focus__puDJA",
  17. "floatControls": "index_floatControls__2hVPf"
  18. };
  19. styleInject(css);
  20. var lengthOptions = {
  21. defaultValue: 100
  22. };
  23. BraftEditor.use(MaxLength(lengthOptions));
  24. var emoticons = defaultEmoticons.map(function (item) {
  25. return require("braft-extensions/dist/assets/".concat(item));
  26. });
  27. var emotionOptions = {
  28. emoticons: emoticons,
  29. closeOnBlur: true,
  30. closeOnSelect: false
  31. };
  32. BraftEditor.use(Emoticon(emotionOptions));
  33. var BarftEditorPage = function BarftEditorPage(_ref) {
  34. var _classnames2;
  35. var value = _ref.value,
  36. onChange = _ref.onChange,
  37. controls = _ref.controls,
  38. _ref$contentStyle = _ref.contentStyle,
  39. contentStyle = _ref$contentStyle === void 0 ? {} : _ref$contentStyle,
  40. FloatControls = _ref.FloatControls;
  41. var optionsControls = controls ? controls : ["bold", "italic", "underline", "separator", "link", "emoji", "separator", "media"];
  42. var options = {
  43. controls: optionsControls,
  44. showControlsBar: optionsControls && optionsControls.length > 0 && !FloatControls,
  45. showFloatControls: FloatControls
  46. };
  47. var _useState = useState(false),
  48. _useState2 = _slicedToArray(_useState, 2),
  49. focusState = _useState2[0],
  50. setFocusState = _useState2[1];
  51. return React.createElement("div", {
  52. className: styles.baseWrapper
  53. }, React.createElement(BraftEditor, {
  54. value: value,
  55. onChange: onChange,
  56. controls: options.controls,
  57. controlBarClassName: classnames(styles.controlBar, _defineProperty({}, styles.focus, focusState)),
  58. controlBarStyle: options.showControlsBar ? {} : {
  59. display: "none"
  60. },
  61. contentClassName: classnames(styles.editorContent, (_classnames2 = {}, _defineProperty(_classnames2, styles.focus, focusState), _defineProperty(_classnames2, styles.hasFloatControls, options.showFloatControls), _classnames2)),
  62. contentStyle: contentStyle,
  63. onFocus: function onFocus() {
  64. return setFocusState(true);
  65. },
  66. onBlur: function onBlur() {
  67. return setFocusState(false);
  68. },
  69. hooks: {
  70. "toggle-link": function toggleLink(_ref2) {
  71. var href = _ref2.href,
  72. target = _ref2.target;
  73. href = href.indexOf("http") === 0 ? href : "http://".concat(href);
  74. return {
  75. href: href,
  76. target: target
  77. };
  78. }
  79. }
  80. }), options.showFloatControls ? React.createElement("div", {
  81. className: classnames(styles.floatControls)
  82. }, React.createElement(FloatControls, {
  83. editorState: value,
  84. setEditorState: onChange
  85. })) : null);
  86. };
  87. export default BarftEditorPage;
  88. export { BarftEditorPage };
  89. //# sourceMappingURL=index.js.map