Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Convert to text if needed
let text
if (data.type === "fragment") {
text = data.fragment
.getTexts()
.map((t) => t.text)
.join("\n")
} else {
// eslint-disable-next-line prefer-destructuring
text = data.text
}
// Convert the text to code lines
const lines = deserializeCode(opts, text).nodes
const fragment = Document.create({ nodes: lines })
return change.insertFragment(fragment)
}
export const makeFragment = text => {
const lines = text.split('\n').map(line =>
Block.create({
type: 'paragraph',
nodes: [Text.create(line)],
} as any)
);
const fragment = Document.create({
nodes: lines,
});
return fragment;
};
export const makeFragment = text => {
const lines = text.split('\n').map(line =>
Block.create({
type: 'paragraph',
nodes: [Text.create(line)],
})
);
const fragment = Document.create({
nodes: lines,
});
return fragment;
};
export const makeFragment = (text: string) => {
const lines = text.split('\n').map((line: any) =>
Block.create({
type: 'paragraph',
nodes: [Text.create(line)],
} as any)
);
const fragment = Document.create({
nodes: lines,
});
return fragment;
};
const lines = text.split('\n').map(line =>
Block.create({
type: 'code_line',
nodes: [Text.create(line)],
})
);
const block = Block.create({
data: {
syntax,
},
type: 'code_block',
nodes: lines,
});
return Document.create({
nodes: [block],
});
};
export const merge = (states: Object[]): Object => {
const nodes = map(path(['editorState', 'document', 'nodes']), states)
const mergedNodes = reduce(
(a: List, b: List) => a.concat(b),
head(nodes),
tail(nodes)
)
const mergedDocument = Document.create({ nodes: mergedNodes })
const mergedEditorState = Value.create({ document: mergedDocument })
return { editorState: mergedEditorState }
}
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL license and that you accept its terms.
*/
import {State, Document} from 'slate';
import {actionTypes} from '../actions';
import {actionTypes as kernelActionTypes} from '../../kernel/actions';
import languages from '../components/Editor/languages';
import {getContent} from './cells';
const initialState = {
state: State.create({
document: Document.create({
nodes: [
{
kind: 'block',
type: 'code_block',
data: {syntax: languages[0]},
nodes: [
{
type: 'code_line',
nodes: [{
type: 'text',
text: '',
}],
},
],
},
],
const block = document.getClosestBlock(anchor.key);
const nextText = block.getNextText(anchor.key);
if (nextText) {
range = range.moveAnchorTo(nextText.key, 0);
}
}
if (focusInline && focus.offset == focusText.text.length) {
const block = document.getClosestBlock(focus.key);
const nextText = block.getNextText(focus.key);
if (nextText) {
range = range.moveFocusTo(nextText.key, 0);
}
}
let fragment = document.getFragmentAtRange(range);
let nodes = this.removeNullNode(fragment.nodes);
let newFragment = Document.create({
nodes: nodes
});
let newValue = Value.create({
document: newFragment
});
this.quote = serialize(newValue.toJSON());
let blockPath = document.createSelection(range).anchor.path.slice(0, 1);
let node = document.getNode(blockPath);
this.newIndex = node.data.get('new_index');
this.oldIndex = node.data.get('old_index');
}
export default function toSlate(array, context) {
if (array.length === 0) {
return State.create({
document: Document.create({
nodes: Block.createList([
Raw.deserializeNode({
kind: 'block',
type: SLATE_DEFAULT_NODE,
nodes: [
{kind: 'text', text: '', ranges: []}
]
})
])
})
})
}
return State.create({
document: Document.create({
nodes: Block.createList(array.map(node => DESERIALIZE.node(node, context)))
})