npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@seafile/seafile-editor

v1.0.132

Published

SeaMarkdown editor is a WYSIWYG Markdown editor based on slate.js. It is used in Seafile and SeaTable project.

Downloads

3,541

Readme

sea-markdown-editor

SeaMarkdown editor is a WYSIWYG Markdown editor based on slate.js. It is used in Seafile and SeaTable project.

Markdown editor UI

markdown editor

Integrated markdown editor UI

An integrated demo. You can customize it according to the style you design.

markdown editor

Simple editor UI

simple editor

Integrated simple editor UI

An integrated demo. You can customize it according to the style you design.

simple editor

Installation

To install via npm:

npm install @seafile/seafile-editor --save

Import the library into your project:

import { MarkdownEditor } from '@seafile/seafile-editor';

Provide components and functions

Components

|Name|Explain| |-|-| |MarkdownEditor|Markdown rich text editor component| |SimpleEditor|Simple markdown editor component| |MarkdownViewer|Markdown content preview component|

Functions

|Name|Explain| |-|-| |mdStringToSlate|Convert markdown strings to the data format used by the editor| |slateToMdString|Convert the data format used by the editor to a markdown string| |processor|Convert markdown string to html format content|

MarkdownEditor usage

Define api

import axios from 'axios';

class API {

  getFileContent() {
    const fileUrl = '';
    return axios.get(fileUrl);
  }

  saveFileContent(content) {
    const updateLink = '';
    const formData = new FormData();
    const blob = new Blob([data], { type: 'text/plain' });
    formData.append('file', blob);
    axios.post(updateLink, formData);
  }

  uploadLocalImage(file) {
    const uploadLink = '';
    const formData = new FormData();
    formData.append('file', file);
    return axios.post(uploadLink, formData);
  }

}

const editorApi = new API();

export default editorApi;

Integrate simple into your own page

import React, { useCallback, useEffect, useRef, useState } from 'react';
import { Button } from 'reactstrap';
import { MarkdownEditor } from '@seafile/seafile-editor';
import editorApi from './api';

export default function MarkdownEditorDemo() {

  const editorRef = useRef(null);
  const [fileContent, setFileContent] = useState('');
  const [isFetching, setIsFetching] = useState(true);
  const [contentVersion, setContentVersion] = useState(0);

  const mathJaxSource = '';

  useEffect(() => {
    editorApi.getFileContent().then(res => {
      setFileContent(res.data);
      setIsFetching(false);
    });
  }, []);

  const onSave = useCallback(() => {
    const content = editorRef.current.getValue();
     editorApi.saveFileContent(content).then(res => {
      window.alert('Saved successfully')
    });
  }, []);

  const onContentChanged = useCallback(() => {
    setContentVersion(contentVersion + 1);
  }, [contentVersion]);

  return (
    <div className='seafile-editor'>
      <MarkdownEditor
        ref={editorRef}
        isFetching={isFetching}
        value={fileContent}
        initValue={''}
        editorApi={editorApi}
        onSave={onSave}
        onContentChanged={onContentChanged}
        mathJaxSource={mathJaxSource}
      />
    </div>
  );
}

Props

Common props you may want to specify include:

  • ref: A reference to the editor, used to obtain the current content in the editor
    • ref.current.getValue: Get the current markdown string value in the editor
    • ref.current.getSlateValue: Get the value of the current slate data format in the editor
  • isFetching: Whether the value of the editor is being obtained, if the loading effect is displayed while obtaining, and if the acquisition is completed, the corresponding content obtained is displayed in the editor.
  • value: The text content obtained
  • initValue: If value does not exist, a default value can be provided via initValue
  • onSave: When the editor content changes, the onSave callback event is triggered externally. The user can save the document by implementing this callback function.
  • onContentChanged: When the editor content changes, a change event is triggered to facilitate the user to record whether the document
  • mathJaxSource: Supports inserting formulas. If you want to support inserting formulas, please provide a path that can load formula resources. If support is not required, you can ignore this parameter. math-jax document

SimpleEditor usage

Define api

import axios from 'axios';

class API {

  getFileContent() {
    const fileUrl = '';
    return axios.get(fileUrl);
  }

  saveFileContent(content) {
    const updateLink = '';
    const formData = new FormData();
    const blob = new Blob([data], { type: 'text/plain' });
    formData.append('file', blob);
    axios.post(updateLink, formData);
  }

  uploadLocalImage(file) {
    const uploadLink = '';
    const formData = new FormData();
    formData.append('file', file);
    return axios.post(uploadLink, formData);
  }

}

const editorApi = new API();

export default editorApi;

Integrate simple into your own page

import React, { useCallback, useEffect, useRef, useState } from 'react';
import { Button } from 'reactstrap';
import { SimpleEditor } from '@seafile/seafile-editor';
import editorApi from './api';

export default function SimpleEditorDemo() {

  const editorRef = useRef(null);
  const [fileContent, setFileContent] = useState('');
  const [isFetching, setIsFetching] = useState(true);
  const [contentVersion, setContentVersion] = useState(0);

  const mathJaxSource = '';

  useEffect(() => {
    editorApi.getFileContent().then(res => {
      setFileContent(res.data);
      setIsFetching(false);
    });
  }, []);

  const onSave = useCallback(() => {
    const content = editorRef.current.getValue();
     editorApi.saveFileContent(content).then(res => {
      window.alert('Saved successfully')
    });
  }, []);

  const onContentChanged = useCallback(() => {
    setContentVersion(contentVersion + 1);
  }, [contentVersion]);

  return (
    <div className='seafile-editor'>
      <SimpleEditor
        ref={editorRef}
        isFetching={isFetching}
        value={fileContent}
        initValue={''}
        editorApi={editorApi}
        onSave={onSave}
        onContentChanged={onContentChanged}
        mathJaxSource={mathJaxSource}
      />
    </div>
  );
}

Props

Common props you may want to specify include:

  • ref: A reference to the editor, used to obtain the current content in the editor
    • ref.current.getValue: Get the current markdown string value in the editor
    • ref.current.getSlateValue: Get the value of the current slate data format in the editor
  • isFetching: Whether the value of the editor is being obtained, if the loading effect is displayed while obtaining, and if the acquisition is completed, the corresponding content obtained is displayed in the editor.
  • value: The text content obtained
  • onSave: When the editor content changes, the onSave callback event is triggered externally. The user can save the document by implementing this callback function.
  • onContentChanged: When the editor content changes, a change event is triggered to facilitate the user to record whether the document
  • mathJaxSource: Supports inserting formulas. If you want to support inserting formulas, please provide a path that can load formula resources. If support is not required, you can ignore this parameter. math-jax document

Functions

mdStringToSlate(mdString)

Convert markdown string to data structure supported by editor (slate)

Params

  • mdString: markdown string

Returns

  Slate nodes

slateToMdString(slateNodes)

Convert editor (slate) supported data structures to markdown string

Params

  • slateNodes: slate nodes

Returns

  Markdown string

processor processor.process(mdString)

Convert markdown string to html

Params

  • mdString: markdown string

Returns

 Promise

Demo

const string = '# Hello, I am first level title'
processor.process(string).then(result => {
  const html = String(result);
  ...
})

🖥 Environment Support

  • Modern browsers

Modern browsers

| Edge | Firefox | Chrome | Safari | | --- | --- | --- | --- | | Edge | false | last 2 versions | false |