0.5.0 • Published 8 months ago

@wunderwa/lexical-json v0.5.0

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

@wunderwa/lexical-json

Facebook Lexical: JSON to html convertor, TypeScript library

Library for converting lexical json state into html and text for a simple preview

Installing

npm i @wunderwa/lexical-json
# or
yarn add @wunderwa/lexical-json

Usage

http://localhost:5173/

import { setConfig, toHtml, toView, LexicalJson } from '@wunderwa/lexical-json'
import { asBlob } from 'html-docx-js-typescript'
const json: LexicalJson = [
  {
    root: {
      direction: 'ltr',
      format: '',
      indent: 0,
      type: 'root',
      version: 1,
      children: [...children]
    }
  }
]
const config: LexicalConfig = {
  h1: {
    style: {
      fontSize: '11px',
      fontWeight: 300,
    },
    class: 'class-name'
},
  h2: {
    style: {
      fontSize: '10px',
    },
  },
  h3: {
    class: 'class-name'
  }
}

setConfig(config)
// or set sepate config for current tag
setConfigItem(config.h1, 'h1')

const htmlStr = toHtml(json)
// or
const htmlStrShifted = toHtml(json, { chordsTonality: -6 }) // for chords plugin

saveAs(data, 'file.docx') // save as docx file

const text = toView(json)
const textShifted = toView(json, { chordsTonality: -6 }) // for chords plugin
import { numbering, toDocx, toDocxSection } from '@wunderwa/lexical-json'

const Download = useCallback(() => {
  const children = toDocxSection(json)
  toDocx([{ children }], numbering).then(blob => {
    downloadFile(blob, '1.docx', '')
  })
}, [])

Convert all block elements to paragraphs

import { clearBlocks, LexicalParagraph, LexicalElem, toParagraphs } from '@wunderwa/lexical-json'

const paragraps: LexicalParagraph[] = clearBlocks(json.root.children)
// see also inner function to convert single blok element to LexicalParagraph array
type toParagraphs = (block: LexicalElem) => LexicalParagraph[]

Releases (add tag)

git tag -a v0.1.0 2004632 -m 'v0.1.0'
git push origin v0.1.0

Releases (npm)

yarn build
npm login
npm publish --access public

npm unpublish @wunderwa/lexical-json@0.1.0
0.5.0

8 months ago

0.3.0

8 months ago

0.2.0

8 months ago

0.4.0

8 months ago

0.1.4

11 months ago

0.1.3

12 months ago

0.1.2

12 months ago

0.1.1

12 months ago

0.1.0

12 months ago