Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
render = () => {
const { children, showUndo, onChange, readOnly, marks, nodes, plugins, className, spellcheck, style, blockTypes, ...rest } = this.props;
const value = this.props.value || Plain.deserialize('');
const undo = !!value && !!value.history && !!value.history.undos && !!value.history.undos['_head'] && value.history.undos['_head'].value;
// console.log(undo);
return (
<div style="{{">
{false && undo && undo.length ? (
<button size="large" shape="circle"> onChange(value.transform().undo().apply())}>
<i aria-hidden="true">
</i></button><i aria-hidden="true">
) : null}
</i><i aria-hidden="true">
{children}
{readOnly !== true && }
{readOnly !== true && }</i></div>
constructor(props) {
super(props);
// Create markdown plugin
const markdown = MarkdownPlugin();
this.state = {
state: Plain.deserialize(
'# slate-markdown\nAdd **live markdown preview** to your Slate editor.\n## Usage\n### Installation\n`npm install slate-markdown`\n### Demo\nThis is a [Slate editor](https://slatejs.org) with the plugin enabled, try typing some markdown in here!\n## Links\n- Contribute on [GitHub](https://github.com/withspectrum/slate-markdown)\n- Made by the folks at [Spectrum](https://spectrum.chat)'
),
plugins: [markdown],
};
}
return null
}
// Always handle raw values.
// Make it easier to migrate between raw and html.
if (typeof value === 'object' && value.nodes) {
return Raw.deserialize(value, { terse: true })
}
if (typeof value !== 'string') {
return null
}
switch (format) {
case 'plain':
return Plain.deserialize(value)
// If value is string and format raw,
case 'raw':
case 'html':
return Html.deserialize(value)
default:
throw new Error(`Don't know how to deserialize ${format}`)
}
}
const parseValue = (v, initialState, terse) => {
resetKeyGenerator();
if (!v) return Plain.deserialize('');
const value = JSON.parse(JSON.stringify(v));
try { return Raw.deserialize(value, { terse }); }
catch (err1) {
try { return Raw.deserialize(value, { terse: !terse }); }
catch (err2) {
console.error('Couldnt parse value in slate', err1, err2);
return initialState ? parseValue(initialState, undefined, { terse }) : Plain.deserialize('');
}
}
};
const parseValue = (v, initialState, terse) => {
resetKeyGenerator();
if (!v) {
return Plain.deserialize('');
}
const value = JSON.parse(JSON.stringify(v));
try {
return Raw.deserialize(value, { terse });
} catch (err1) {
try {
return Raw.deserialize(value, { terse: !terse });
} catch (err2) {
console.error('Couldnt parse value in slate', err1, err2);
return initialState
? parseValue(initialState, undefined, { terse })
: Plain.deserialize('');
}
}
};
var parseValue = function (v, initialState, terse) {
resetKeyGenerator();
if (!v) {
return Plain.deserialize('');
}
var value = JSON.parse(JSON.stringify(v));
try {
return Raw.deserialize(value, { terse: terse });
}
catch (err1) {
try {
return Raw.deserialize(value, { terse: !terse });
}
catch (err2) {
console.error('Couldnt parse value in slate', err1, err2);
return initialState
? parseValue(initialState, undefined, { terse: terse })
: Plain.deserialize('');
}
}
const parseValue = (v, initialState, terse) => {
resetKeyGenerator();
if (!v) return Plain.deserialize('');
const value = JSON.parse(JSON.stringify(v));
try { return Raw.deserialize(value, { terse }); }
catch (err1) {
try { return Raw.deserialize(value, { terse: !terse }); }
catch (err2) {
console.error('Couldnt parse value in slate', err1, err2);
return initialState ? parseValue(initialState, undefined, { terse }) : Plain.deserialize('');
}
}
};
const parseValue = (v, initialState, terse) => {
resetKeyGenerator();
if (!v) {
return Plain.deserialize('');
}
const value = JSON.parse(JSON.stringify(v));
try {
return Raw.deserialize(value, { terse });
} catch (err1) {
try {
return Raw.deserialize(value, { terse: !terse });
} catch (err2) {
console.error('Couldnt parse value in slate', err1, err2);
return initialState
? parseValue(initialState, undefined, { terse })
: Plain.deserialize('');
}
}
};
constructor(props, ...rest) {
super(props, ...rest)
const empty = Plain.deserialize('')
this.state = {
slateState: empty.set('document', props.value.document)
}
}