prosemirror-compress

0.0.2 • Public • Published

prosemirror-compress

documentation

[('compress' || 'uncompress') + ('State' || 'Selection' || 'Step') + 'JSON']()

Renames known keys and values. Maintains JSON structure.

let compressedStateJSON = compressStateJSON(/*editorState*/.toJSON())
let editorState = EditorState.fromJSON(/*config*/, uncompressStateJSON(compressedStateJSON))

let compressedSelectionJSON = compressSelectionJSON(/*selection*/.toJSON())
let selection = Selection.fromJSON(/*doc*/, uncompressSelectionJSON(compressedSelectionJSON))

let compressedStepsJSON = /*steps array*/.map(step => compressStepJSON(step.toJSON()))
let steps = compressedStepsJSON.map(json => Step.fromJSON(/*schema*/, uncompressStepJSON(json))

uncompressed vs compressed

{"selection":{"head":0,"anchor":0}},"doc":{"type":"doc","content":[{"type":"heading","attrs":{"level":3},
{"s":{"h":0,"a":0}},"d":{"t":"d","c":[{"t":"h","a":{"l":3},

compressStepsLossy()

Merges all the steps that can be merged.

let steps = compressStepsLossy(/*steps array*/)

keysMappers()

For compressing and uncompressing using custom keys maps.

let [ keysMapper, inverseKeysMapper ] = keysMappers(/*keysMap*/)
let compressedJSON = keysMapper(/*json*/)
let json = inverseKeysMapper(compressedJSON)

license

MIT license.

Readme

Keywords

none

Package Sidebar

Install

npm i prosemirror-compress

Weekly Downloads

9

Version

0.0.2

License

MIT

Unpacked Size

11.7 kB

Total Files

7

Last publish

Collaborators

  • xylk