function _define_property(obj, key, value) {
    if (key in obj) {
        Object.defineProperty(obj, key, {
            value: value,
            enumerable: true,
            configurable: true,
            writable: true
        });
    } else {
        obj[key] = value;
    }
    return obj;
}
function _object_spread(target) {
    for(var i = 1; i < arguments.length; i++){
        var source = arguments[i] != null ? arguments[i] : {};
        var ownKeys = Object.keys(source);
        if (typeof Object.getOwnPropertySymbols === "function") {
            ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
                return Object.getOwnPropertyDescriptor(source, sym).enumerable;
            }));
        }
        ownKeys.forEach(function(key) {
            _define_property(target, key, source[key]);
        });
    }
    return target;
}
function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);
    if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);
        if (enumerableOnly) {
            symbols = symbols.filter(function(sym) {
                return Object.getOwnPropertyDescriptor(object, sym).enumerable;
            });
        }
        keys.push.apply(keys, symbols);
    }
    return keys;
}
function _object_spread_props(target, source) {
    source = source != null ? source : {};
    if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
    } else {
        ownKeys(Object(source)).forEach(function(key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
    }
    return target;
}
import React, { useEffect } from "react";
import { MarkdownEditor, parserMdToSchema } from "../MarkdownEditor";
import { MarkdownFormatter } from "../Plugins/formatter";
/** 思维链中的 MarkdownEditor 封装，自动格式化 + 流式更新 */ export var MarkdownEditorUpdate = function MarkdownEditorUpdate(props) {
    var _props_streaming;
    var editorRef = React.useRef();
    useEffect(function() {
        var _editorRef_current_store, _editorRef_current;
        var formatted = MarkdownFormatter.format(props.initValue || '') || '';
        (_editorRef_current = editorRef.current) === null || _editorRef_current === void 0 ? void 0 : (_editorRef_current_store = _editorRef_current.store) === null || _editorRef_current_store === void 0 ? void 0 : _editorRef_current_store.updateNodeList(parserMdToSchema(formatted.trim(), props.plugins).schema);
    }, [
        props.initValue
    ]);
    useEffect(function() {
        if (props.isFinished) {
            var _editorRef_current_store, _editorRef_current;
            (_editorRef_current = editorRef.current) === null || _editorRef_current === void 0 ? void 0 : (_editorRef_current_store = _editorRef_current.store) === null || _editorRef_current_store === void 0 ? void 0 : _editorRef_current_store.setMDContent(MarkdownFormatter.format(props.initValue || ''), props.plugins);
        }
    }, [
        props.isFinished
    ]);
    return /*#__PURE__*/ React.createElement(MarkdownEditor, _object_spread_props(_object_spread({
        editorRef: editorRef,
        style: {
            padding: 0,
            width: '100%'
        },
        toc: false,
        readonly: true,
        contentStyle: {
            padding: 0,
            width: '100%'
        },
        codeProps: {
            showLineNumbers: false
        }
    }, props), {
        streaming: ((_props_streaming = props.streaming) !== null && _props_streaming !== void 0 ? _props_streaming : props.typewriter) && !props.isFinished,
        initValue: ""
    }));
};
