Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import { isKeyHotkey } from "is-hotkey"
import { getCurrentCode } from "../utils"
import { onTab } from "./on-tab"
import { onShiftTab } from "./on-shift-tab"
import { onEnter } from "./on-enter"
import { onModEnter } from "./on-mod-enter"
import { onBackspace } from "./on-backspace"
import { onSelectAll } from "./on-select-all"
const isModA = isKeyHotkey("mod+a")
const isShiftTab = isKeyHotkey("shift+tab")
const isTab = isKeyHotkey("tab")
const isModZ = isKeyHotkey("mod+z")
const isModEnter = isKeyHotkey("mod+enter")
const isEnter = isKeyHotkey("enter")
const isBackspace = isKeyHotkey("backspace")
/**
* User is pressing a key in the editor
*/
export function onKeyDown(opts, event, change, editor) {
const { value } = change
const currentCode = getCurrentCode(opts, value)
// Inside code ?
if (!currentCode) {
return editor()
}
// @flow
import { isKeyHotkey } from 'is-hotkey';
import { type Change } from '@gitbook/slate';
import { getCurrentCode } from '../utils';
import type Options from '../options';
import onTab from './onTab';
import onShiftTab from './onShiftTab';
import onEnter from './onEnter';
import onModEnter from './onModEnter';
import onBackspace from './onBackspace';
import onSelectAll from './onSelectAll';
const isModA = isKeyHotkey('mod+a');
const isShiftTab = isKeyHotkey('shift+tab');
const isTab = isKeyHotkey('tab');
const isModEnter = isKeyHotkey('mod+enter');
const isEnter = isKeyHotkey('enter');
const isBackspace = isKeyHotkey('backspace');
/**
* User is pressing a key in the editor
*/
function onKeyDown(
opts: Options,
event: *,
change: Change,
editor: *
): void | Change {
const { value } = change;
import { RangeJSON, Range as SlateRange, Editor as CoreEditor } from 'slate';
import { Plugin } from '@grafana/slate-react';
import { isKeyHotkey } from 'is-hotkey';
const isIndentLeftHotkey = isKeyHotkey('mod+[');
const isShiftTabHotkey = isKeyHotkey('shift+tab');
const isIndentRightHotkey = isKeyHotkey('mod+]');
const SLATE_TAB = ' ';
const handleTabKey = (event: KeyboardEvent, editor: CoreEditor, next: Function): void => {
const {
startBlock,
endBlock,
selection: {
start: { offset: startOffset, key: startKey },
end: { offset: endOffset, key: endKey },
},
} = editor.value;
const first = startBlock.getFirstText();
const COLLAPSE_LINE_BACKWARD_MAC = isKeyHotkey('option+up')
const COLLAPSE_LINE_FORWARD_MAC = isKeyHotkey('option+down')
const COLLAPSE_LINE_BACKWARD = e => IS_APPLE && COLLAPSE_LINE_BACKWARD_MAC(e)
const COLLAPSE_LINE_FORWARD = e => IS_APPLE && COLLAPSE_LINE_FORWARD_MAC(e)
const EXTEND_CHAR_FORWARD = isKeyHotkey('shift+right')
const EXTEND_CHAR_BACKWARD = isKeyHotkey('shift+left')
const EXTEND_LINE_BACKWARD_MAC = isKeyHotkey('option+shift+up')
const EXTEND_LINE_FORWARD_MAC = isKeyHotkey('option+shift+down')
const EXTEND_LINE_BACKWARD = e => IS_APPLE && EXTEND_LINE_BACKWARD_MAC(e)
const EXTEND_LINE_FORWARD = e => IS_APPLE && EXTEND_LINE_FORWARD_MAC(e)
const UNDO = isKeyHotkey('mod+z')
const REDO_MAC = isKeyHotkey('mod+shift+z')
const REDO_PC = isKeyHotkey('mod+y')
const REDO = e => (IS_APPLE ? REDO_MAC(e) : REDO_PC(e))
const TRANSPOSE_CHARACTER_MAC = isKeyHotkey('ctrl+t')
const TRANSPOSE_CHARACTER = e => IS_APPLE && TRANSPOSE_CHARACTER_MAC(e)
const CONTENTEDITABLE = e =>
BOLD(e) ||
DELETE_CHAR_BACKWARD(e) ||
DELETE_CHAR_FORWARD(e) ||
DELETE_LINE_BACKWARD(e) ||
DELETE_LINE_FORWARD(e) ||
DELETE_WORD_BACKWARD(e) ||
DELETE_WORD_FORWARD(e) ||
ITALIC(e) ||
REDO(e) ||
SPLIT_BLOCK(e) ||
const DELETE_WORD_FORWARD_MAC = e =>
isKeyHotkey('shift+option+delete', e) || isKeyHotkey('option+delete', e)
const DELETE_WORD_FORWARD_PC = isKeyHotkey('ctrl+delete')
import React from 'react'
import initialValue from './value.json'
import { css } from 'emotion'
import { isKeyHotkey } from 'is-hotkey'
import { Button, Icon, Toolbar } from '../components'
/**
* Hotkey matchers.
*
* @type {Function}
*/
const isBoldHotkey = isKeyHotkey('mod+b')
const isItalicHotkey = isKeyHotkey('mod+i')
const isUnderlinedHotkey = isKeyHotkey('mod+u')
const isCodeHotkey = isKeyHotkey('mod+`')
/**
* A simple editor component to demo syncing with.
*
* @type {Component}
*/
class SyncingEditor extends React.Component {
/**
* Deserialize the initial editor value.
*
* @type {Object}
*/
state = {
value: Value.fromJSON(initialValue),
const RIGHT_ARROW = isKeyHotkey('right')
const LEFT_ARROW = isKeyHotkey('left')
const COLLAPSE_CHAR_FORWARD = e => RIGHT_ARROW(e) && !EXTEND_CHAR_FORWARD(e)
const COLLAPSE_CHAR_BACKWARD = e => LEFT_ARROW(e) && !EXTEND_CHAR_BACKWARD(e)
const COLLAPSE_LINE_BACKWARD_MAC = isKeyHotkey('option+up')
const COLLAPSE_LINE_FORWARD_MAC = isKeyHotkey('option+down')
const COLLAPSE_LINE_BACKWARD = e => IS_APPLE && COLLAPSE_LINE_BACKWARD_MAC(e)
const COLLAPSE_LINE_FORWARD = e => IS_APPLE && COLLAPSE_LINE_FORWARD_MAC(e)
const EXTEND_CHAR_FORWARD = isKeyHotkey('shift+right')
const EXTEND_CHAR_BACKWARD = isKeyHotkey('shift+left')
const EXTEND_LINE_BACKWARD_MAC = isKeyHotkey('option+shift+up')
const EXTEND_LINE_FORWARD_MAC = isKeyHotkey('option+shift+down')
const EXTEND_LINE_BACKWARD = e => IS_APPLE && EXTEND_LINE_BACKWARD_MAC(e)
const EXTEND_LINE_FORWARD = e => IS_APPLE && EXTEND_LINE_FORWARD_MAC(e)
const UNDO = isKeyHotkey('mod+z')
const REDO_MAC = isKeyHotkey('mod+shift+z')
const REDO_PC = isKeyHotkey('mod+y')
const REDO = e => (IS_APPLE ? REDO_MAC(e) : REDO_PC(e))
const TRANSPOSE_CHARACTER_MAC = isKeyHotkey('ctrl+t')
const TRANSPOSE_CHARACTER = e => IS_APPLE && TRANSPOSE_CHARACTER_MAC(e)
const CONTENTEDITABLE = e =>
BOLD(e) ||
DELETE_CHAR_BACKWARD(e) ||
DELETE_CHAR_FORWARD(e) ||
DELETE_LINE_BACKWARD(e) ||
import { isKeyHotkey } from 'is-hotkey'
import MarkStrategy from '../strategies/MarkStrategy'
import ColorStrategy from '../strategies/ColorStrategy'
import TopicColors from '../TopicColors'
const markHotkeys = Object.entries({
bold: isKeyHotkey('mod+b'),
italic: isKeyHotkey('mod+i'),
underline: isKeyHotkey('mod+u'),
})
const colorHotkeys = Object.entries(TopicColors)
.filter(([color, colorProps]) => colorProps.hotkey)
.map(([color, colorProps]) => [color, isKeyHotkey(colorProps.hotkey)])
const lastColorHotkey = isKeyHotkey('mod+shift+x')
const KeyPlugin = () => ({
onKeyDown (event, data, editor) {
const markMatch = markHotkeys.find(([mark, hotkey]) => hotkey(event))
if (markMatch) {
event.preventDefault()
return editor.onChange(MarkStrategy(editor.state.value, markMatch[0]))
}
/**
* Hotkeys.
*
* @type {Function}
*/
const BOLD = isKeyHotkey('mod+b')
const ITALIC = isKeyHotkey('mod+i')
const ENTER = isKeyHotkey('enter')
const SHIFT_ENTER = isKeyHotkey('shift+enter')
const SPLIT_BLOCK = e => ENTER(e) || SHIFT_ENTER(e)
const BACKSPACE = isKeyHotkey('backspace')
const SHIFT_BACKSPACE = isKeyHotkey('shift+backspace')
const DELETE = isKeyHotkey('delete')
const SHIFT_DELETE = isKeyHotkey('shift+delete')
const DELETE_BACKWARD = e => BACKSPACE(e) || SHIFT_BACKSPACE(e)
const DELETE_FORWARD = e => DELETE(e) || SHIFT_DELETE(e)
const DELETE_CHAR_BACKWARD_MAC = isKeyHotkey('ctrl+h')
const DELETE_CHAR_FORWARD_MAC = isKeyHotkey('ctrl+d')
const DELETE_CHAR_BACKWARD = e =>
DELETE_BACKWARD(e) || (IS_APPLE && DELETE_CHAR_BACKWARD_MAC(e))
const DELETE_CHAR_FORWARD = e =>
DELETE_FORWARD(e) || (IS_APPLE && DELETE_CHAR_FORWARD_MAC(e))
const DELETE_LINE_BACKWARD_MAC = e =>
isKeyHotkey('cmd+shift+backspace', e) || isKeyHotkey('cmd+backspace', e)
const DELETE_LINE_FORWARD_MAC = isKeyHotkey('ctrl+k')
const DELETE_LINE_BACKWARD = e => IS_APPLE && DELETE_LINE_BACKWARD_MAC(e)
const DELETE_LINE_FORWARD = e => IS_APPLE && DELETE_LINE_FORWARD_MAC(e)
Button,
Table,
Input,
Grid
} from "semantic-ui-react";
import { Header as SemanticHeader } from "semantic-ui-react";
import initialTimeline from "./initialTimeline.json";
const single = require("../../helpers/singleDoc");
const tline = require("../../helpers/timelineHandlers");
const PluginDeepTable = require("slate-deep-table/dist");
const DEFAULT_NODE = "paragraph";
const isBoldHotkey = isKeyHotkey("mod+b");
const isItalicHotkey = isKeyHotkey("mod+i");
const isUnderlinedHotkey = isKeyHotkey("mod+u");
const isCodeHotkey = isKeyHotkey("mod+`");
const isStrikeHotKey = isKeyHotkey("mod+shift+s");
var initialLoad = false;
const plugins = [PluginDeepTable()];
let thisMark;
let timelineEmbedded = false;
//TODO: Move these into their own plugin modules
//Links
function wrapLink(editor, href) {
editor.wrapInline({