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";
/**
 * 将内容转换为列表格式的 Markdown
 * @param {string} content - 原始内容
 * @returns {string} 转换后的内容
 */ var toListMarkdown = function(content) {
    return content;
};
/**
 * MarkdownEditorUpdate 组件 - Markdown 编辑器更新组件
 *
 * 该组件是对 MarkdownEditor 的封装，提供自动更新和格式化功能。
 * 主要用于在思维链中显示和更新 Markdown 内容。
 *
 * @component
 * @description Markdown 编辑器更新组件，提供自动更新和格式化功能
 * @param {MarkdownEditorProps & {isFinished?: boolean}} props - 组件属性
 * @param {boolean} [props.isFinished] - 内容是否已完成
 * @param {string} [props.initValue] - 初始内容
 * @param {boolean} [props.typewriter] - 是否启用打字机效果
 * @param {MarkdownEditorProps} props - 其他 MarkdownEditor 属性
 *
 * @example
 * ```tsx
 * import { MarkdownEditorUpdate } from './MarkdownEditor';
 *
 * <MarkdownEditorUpdate
 *   initValue="# Hello World"
 *   isFinished={true}
 *   typewriter={false}
 * />
 * ```
 *
 * @returns {React.ReactElement} 渲染的 Markdown 编辑器组件
 *
 * @remarks
 * - 自动格式化 Markdown 内容
 * - 支持内容完成状态检测
 * - 提供打字机效果
 * - 只读模式
 * - 自动更新节点列表
 * - 响应式布局
 */ export var MarkdownEditorUpdate = function(props) {
    var editorRef = React.useRef();
    useEffect(function() {
        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.updateNodeList(parserMdToSchema(toListMarkdown(MarkdownFormatter.format(props.initValue || '') || '').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), {
        typewriter: props.typewriter && !props.isFinished,
        initValue: ""
    }));
};
