0.0.2 • Published 6 years ago
prosemirror-compress v0.0.2
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)