Skip to content

编辑器or富文本

Posted on:September 18, 2023 at 09:35 AM
预计阅读时长:1 min read 字数:122

start demo use blocksuite (notion 风格)

import '@blocksuite/editor/themes/affine.css';
import { useEffect, useRef } from 'react';

export default () => {
    const ref = useRef<HTMLDivElement>(null);
    useEffect(() => {
        import('@blocksuite/editor').then((res) => {
            const editor = new res.SimpleAffineEditor();
            ref.current?.appendChild(editor)
        })
    })
    return <>
        <div className="editor" ref={ref}></div>
    </>
}

blocksuite全屏

codemirror

vue

<script setup  name="javascript">
import useJavaScript from './cJavascript';
useJavaScript();
</script>

<template>
    <div id="editor">
    </div>
</template>

composition api

let useJavascript ;

import { EditorView, basicSetup } from "codemirror"
import { javascript } from "@codemirror/lang-javascript"
import { ref, shallowRef, nextTick } from 'vue'


export default  useJavascript = ()=>{
    nextTick(() => {
        const parent = document.querySelector("#editor");
        let view = new EditorView({
            extensions: [basicSetup, javascript()],
            parent: parent || document.body
        })
    })
}

链接