{"version":3,"file":"index.js","sources":["../../src/components/Editor/BraftEditor/index.tsx"],"sourcesContent":["import React, { useState } from \"react\";\nimport classnames from \"classnames\";\nimport BraftEditor, { ControlType, EditorState } from \"braft-editor\";\nimport styles from \"./index.less\";\nimport \"braft-editor/dist/index.css\";\n\n// 引入表情包扩展模块样式文件\nimport \"braft-extensions/dist/emoticon.css\";\n// 引入表情包扩展模块和默认表情包列表\nimport Emoticon, { defaultEmoticons } from \"braft-extensions/dist/emoticon\";\nimport MaxLength from \"braft-extensions/dist/max-length\";\n\nconst lengthOptions = {\n  defaultValue: 100 // 指定默认限制数,如不指定则为Infinity(无限)\n  // includeEditors: ['editor-id-1'], // 指定该模块对哪些BraftEditor生效,不传此属性则对所有BraftEditor有效\n  // excludeEditors: ['editor-id-2'],  // 指定该模块对哪些BraftEditor无效\n};\nBraftEditor.use(MaxLength(lengthOptions));\n\n// 转换默认表情包列表,让webpack可以正确加载到默认表情包中的图片,请确保已对png格式的文件配置了loader\n// 如果你使用的webpack版本不支持动态require,或者使用的其他打包工具,请勿使用此写法\nconst emoticons = defaultEmoticons.map((item: string) =>\n  require(`braft-extensions/dist/assets/${item}`)\n);\n\n// 也可以使用自己的表情包资源,不受打包工具限制\n// const emoticons = ['http://path/to/emoticon-1.png', 'http://path/to/emoticon-2.png', 'http://path/to/emoticon-3.png', 'http://path/to/emoticon-4.png', ...]\n\nconst emotionOptions = {\n  // includeEditors: ['editor-id-1'], // 指定该模块对哪些BraftEditor生效,不传此属性则对所有BraftEditor有效\n  // excludeEditors: ['editor-id-2'],  // 指定该模块对哪些BraftEditor无效\n  emoticons: emoticons, // 指定可用表情图片列表,默认为空\n  closeOnBlur: true, // 指定是否在点击表情选择器之外的地方时关闭表情选择器,默认false\n  closeOnSelect: false // 指定是否在选择表情后关闭表情选择器,默认false\n};\n\nBraftEditor.use(Emoticon(emotionOptions));\n\nexport interface BaseEditorProps {\n  value: EditorState;\n  onChange: (editorState: EditorState) => void;\n  contentStyle?: React.CSSProperties;\n  controls?: ControlType[];\n  FloatControls?: any;\n  \n  blockRenderMap?: any;\n  blockRendererFn?: any;\n  draftProps?: any;\n  placeholder?: string;\n  converts?: any;\n}\n\nexport const BarftEditorPage = ({\n  value,\n  onChange,\n  controls,\n  contentStyle = {},\n  FloatControls,\n  draftProps,\n  placeholder,\n  blockRenderMap,\n  blockRendererFn,\n  converts,\n}: BaseEditorProps) => {\n  const optionsControls = controls\n    ? controls\n    : [\n        \"bold\",\n        \"italic\",\n        \"underline\",\n        \"separator\",\n        \"link\",\n        \"emoji\",\n        \"separator\",\n        \"media\"\n      ];\n  const options: any = {\n    controls: optionsControls,\n    showControlsBar:\n      optionsControls && optionsControls.length > 0 && !FloatControls,\n    showFloatControls: FloatControls\n  };\n\n  const [focusState, setFocusState] = useState(false);\n\n  return (\n    <div className={styles.baseWrapper}>\n      <BraftEditor\n        value={value}\n        onChange={onChange}\n        controls={options.controls}\n        controlBarClassName={classnames(styles.controlBar, {\n          [styles.focus]: focusState\n        })}\n        controlBarStyle={options.showControlsBar ? {} : { display: \"none\" }}\n        contentClassName={classnames(styles.editorContent, {\n          [styles.focus]: focusState,\n          [styles.hasFloatControls]: options.showFloatControls\n        })}\n        contentStyle={contentStyle}\n        onFocus={() => setFocusState(true)}\n        onBlur={() => setFocusState(false)}\n        hooks={{\n          \"toggle-link\": ({ href, target }) => {\n            href = href.indexOf(\"http\") === 0 ? href : `http://${href}`;\n            return { href, target };\n          }\n        }}\n        {...{\n          blockRenderMap,\n          blockRendererFn,\n          converts,\n          placeholder,\n          draftProps,\n        }}\n      />\n      {options.showFloatControls ? (\n        <div className={classnames(styles.floatControls)}>\n          {\n            <FloatControls\n              editorState={value}\n              setEditorState={onChange}\n            />\n          }\n        </div>\n      ) : null}\n    </div>\n  );\n};\n\nexport default BarftEditorPage;\n"],"names":["lengthOptions","defaultValue","BraftEditor","use","MaxLength","emoticons","defaultEmoticons","map","item","require","emotionOptions","closeOnBlur","closeOnSelect","Emoticon","BarftEditorPage","value","onChange","controls","contentStyle","FloatControls","draftProps","placeholder","blockRenderMap","blockRendererFn","converts","optionsControls","options","showControlsBar","length","showFloatControls","useState","focusState","setFocusState","React","createElement","className","styles","baseWrapper","Object","assign","controlBarClassName","classnames","controlBar","focus","controlBarStyle","display","contentClassName","editorContent","hasFloatControls","onFocus","onBlur","hooks","href","target","indexOf","floatControls","editorState","setEditorState"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYA,IAAMA,aAAa,GAAG;AACpBC,EAAAA,YAAY,EAAE;AADM,CAAtB;AAKAC,WAAW,CAACC,GAAZ,CAAgBC,SAAS,CAACJ,aAAD,CAAzB;AAIA,IAAMK,SAAS,GAAGC,yBAAgB,CAACC,GAAjB,CAAqB,UAACC,IAAD;SACrCC,OAAO,wCAAiCD,KAAjC;AADS,CAAA,CAAlB;AAOA,IAAME,cAAc,GAAG;AAGrBL,EAAAA,SAAS,EAAEA,SAHU;AAIrBM,EAAAA,WAAW,EAAE,IAJQ;AAKrBC,EAAAA,aAAa,EAAE;AALM,CAAvB;AAQAV,WAAW,CAACC,GAAZ,CAAgBU,iBAAQ,CAACH,cAAD,CAAxB;AAgBA,IAAaI,eAAe,GAAG,SAAlBA,eAAkB,KAAA,EAWT;;;MAVpBC,KAUoB,QAVpBA;MACAC,QASoB,QATpBA;MACAC,QAQoB,QARpBA;+BACAC;MAAAA,YAOoB,kCAPL;MACfC,aAMoB,QANpBA;MACAC,UAKoB,QALpBA;MACAC,WAIoB,QAJpBA;MACAC,cAGoB,QAHpBA;MACAC,eAEoB,QAFpBA;MACAC,QACoB,QADpBA;MAEMC,eAAe,GAAGR,QAAQ,GAC5BA,QAD4B,GAE5B,CACE,MADF,EAEE,QAFF,EAGE,WAHF,EAIE,WAJF,EAKE,MALF,EAME,OANF,EAOE,WAPF,EAQE,OARF;MAUES,OAAO,GAAQ;AACnBT,IAAAA,QAAQ,EAAEQ,eADS;AAEnBE,IAAAA,eAAe,EACbF,eAAe,IAAIA,eAAe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