UNPKG

@flatbiz/antd

Version:
80 lines (76 loc) 2.71 kB
/*! @flatjs/forge MIT @flatbiz/antd */ import _FullscreenOutlined from '@ant-design/icons/es/icons/FullscreenOutlined.js'; import { classNames } from '@dimjs/utils/class-names/class-names'; import { a as _slicedToArray } from './_rollupPluginBabelHelpers-BspM60Sw.js'; import { useState, useRef } from 'react'; import { useKeyPress, useMemoizedFn } from 'ahooks'; import { fbaHooks } from './fba-hooks/index.js'; import { I as IconWrapper } from './icon-wrapper-DE97bI14.js'; import { R as RichTextEditor } from './rich-text-editor-k8SgoKVU.js'; import { jsxs, jsx } from 'react/jsx-runtime'; /** * 预览 RichTextEditor 生成的富文本数据 * ``` * 1. 通过 onInit 属性可获取实例:editor * 2. 如果高度发生变更,可执行 editor.execCommand('mceAutoResize'); * * ``` * @param props * @returns */ var RichTextViewer = function RichTextViewer(props) { var _useState = useState(false), _useState2 = _slicedToArray(_useState, 2), isFixed = _useState2[0], setIsFixed = _useState2[1]; var editorRef = useRef(); useKeyPress(function () { return true; }, function (event) { if (event.type === 'keyup' && event.key === 'Escape' && isFixed) { setIsFixed(false); } }, { events: ['keydown', 'keyup'] }); var onChangeFixed = useMemoizedFn(function () { setIsFixed(!isFixed); }); var onInit = useMemoizedFn(function (_, editor) { var _props$onInit; editorRef.current = editor; (_props$onInit = props.onInit) === null || _props$onInit === void 0 || _props$onInit.call(props, editor); }); fbaHooks.useEffectCustom(function () { var _editorRef$current; (_editorRef$current = editorRef.current) === null || _editorRef$current === void 0 || _editorRef$current.editorCommands.execCommand('mceAutoResize'); }, [props.value]); return /*#__PURE__*/jsxs("div", { className: classNames('fba-editor-viewer', { 'fba-editor-viewer-fixed': isFixed }, props.className), style: props.style, children: [props.children, props.fullscreen && props.value && /*#__PURE__*/jsx("div", { className: "fba-editor-viewer-icon", children: /*#__PURE__*/jsx(IconWrapper, { hoverTips: props.fullscreenIconTips, icon: /*#__PURE__*/jsx(_FullscreenOutlined, {}), onClick: onChangeFixed }) }), /*#__PURE__*/jsx(RichTextEditor, { value: props.value, onInit: onInit, imgPreview: true, disabled: true, init: { plugins: 'autoresize', menubar: false, toolbar: '', statusbar: false, readonly: true } })] }); }; export { RichTextViewer as R }; //# sourceMappingURL=rich-text-viewer-BuOKtoaJ.js.map