Nessuna descrizione

index.js 3.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. FloatControls = _ref.FloatControls;
  39. var optionsControls = controls ? controls : ["bold", "italic", "underline", "separator", "link", "emoji", "separator", "media"];
  40. var options = {
  41. controls: optionsControls,
  42. showControlsBar: optionsControls && optionsControls.length > 0 && !FloatControls,
  43. showFloatControls: FloatControls
  44. };
  45. var _useState = useState(false),
  46. _useState2 = _slicedToArray(_useState, 2),
  47. focusState = _useState2[0],
  48. setFocusState = _useState2[1];
  49. return React.createElement("div", {
  50. className: styles.baseWrapper
  51. }, React.createElement(BraftEditor, {
  52. value: value,
  53. onChange: onChange,
  54. controls: options.controls,
  55. controlBarClassName: classnames(styles.controlBar, _defineProperty({}, styles.focus, focusState)),
  56. controlBarStyle: options.showControlsBar ? {} : {
  57. display: "none"
  58. },
  59. contentClassName: classnames(styles.editorContent, (_classnames2 = {}, _defineProperty(_classnames2, styles.focus, focusState), _defineProperty(_classnames2, styles.hasFloatControls, options.showFloatControls), _classnames2)),
  60. contentStyle: {},
  61. onFocus: function onFocus() {
  62. return setFocusState(true);
  63. },
  64. onBlur: function onBlur() {
  65. return setFocusState(false);
  66. },
  67. hooks: {
  68. "toggle-link": function toggleLink(_ref2) {
  69. var href = _ref2.href,
  70. target = _ref2.target;
  71. href = href.indexOf("http") === 0 ? href : "http://".concat(href);
  72. return {
  73. href: href,
  74. target: target
  75. };
  76. }
  77. }
  78. }), options.showFloatControls ? React.createElement("div", {
  79. className: classnames(styles.floatControls)
  80. }, React.createElement(FloatControls, {
  81. editorState: value,
  82. setEditorState: onChange
  83. })) : null);
  84. };
  85. export default BarftEditorPage;
  86. export { BarftEditorPage };
  87. //# sourceMappingURL=index.js.map