Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

slate-edit-blockquote

Package Overview
Dependencies
Maintainers
6
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

slate-edit-blockquote - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

.flowconfig

5

CHANGELOG.md

@@ -6,2 +6,7 @@ # Change Log

### [0.5.0] - 2017-11-08
- Upgrade to slate ^0.29.0
### [0.4.0] - 2017-09-19

@@ -8,0 +13,0 @@

15

dist/changes/unwrapBlockquote.js

@@ -1,9 +0,11 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
require('slate');
/**
* Unwrap from blockquote.
*
* @param {PluginOptions} opts
* @param {Slate.Change} change
* @return {Change} change
*/

@@ -13,3 +15,2 @@ function unwrapBlockquote(opts, change) {

}
module.exports = unwrapBlockquote;
exports.default = unwrapBlockquote;

@@ -1,9 +0,11 @@

"use strict";
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
require('slate');
/**
* Wrap the block in a new blockquote.
*
* @param {PluginOptions} opts
* @param {Slate.Change} change
* @return {Change} change
*/

@@ -13,3 +15,2 @@ function wrapInBlockquote(opts, change) {

}
module.exports = wrapInBlockquote;
exports.default = wrapInBlockquote;
'use strict';
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
Object.defineProperty(exports, "__esModule", {
value: true
});
var onEnter = require('./onEnter');
var onTab = require('./onTab');
var onBackspace = require('./onBackspace');
var makeSchema = require('./makeSchema');
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var getCurrentBlockquote = require('./getCurrentBlockquote');
var wrapInBlockquote = require('./changes/wrapInBlockquote');
var unwrapBlockquote = require('./changes/unwrapBlockquote');
var _options = require('./options');
var KEY_ENTER = 'enter';
var KEY_TAB = 'tab';
var KEY_BACKSPACE = 'backspace';
var _options2 = _interopRequireDefault(_options);
/**
* A Slate plugin to handle keyboard events in lists.
* @param {Object} [opts] Options for the plugin
* @param {String} [opts.type='blockquote'] The type for quote blocks
* @param {String} [opts.type='paragraph'] The default type for blocks inside quotes
* @return {Object}
*/
var _handlers = require('./handlers');
function EditBlockquote(opts) {
opts = opts || {};
opts.type = opts.type || 'blockquote';
opts.typeDefault = opts.typeDefault || 'paragraph';
var _core = require('./core');
/**
* Is the selection in a blockquote
*/
function isSelectionInBlockquote(state) {
return Boolean(getCurrentBlockquote(opts, state));
}
var _core2 = _interopRequireDefault(_core);
/**
* Bind a change to be only applied in list
*/
function bindChange(fn) {
return function (change) {
var state = change.state;
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
* A Slate plugin to handle keyboard events in lists.
*/
if (!isSelectionInBlockquote(state)) {
return change;
}
function EditBlockquote() {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
opts = new _options2.default(opts);
return fn.apply(undefined, _toConsumableArray([opts, change].concat(args)));
};
}
var corePlugin = (0, _core2.default)(opts);
/**
* User is pressing a key in the editor
*/
function onKeyDown(e, data, change) {
// Build arguments list
var args = [e, data, change, opts];
switch (data.key) {
case KEY_ENTER:
return onEnter.apply(undefined, args);
case KEY_TAB:
return onTab.apply(undefined, args);
case KEY_BACKSPACE:
return onBackspace.apply(undefined, args);
}
}
var schema = makeSchema(opts);
return {
onKeyDown: onKeyDown,
schema: schema,
utils: {
isSelectionInBlockquote: isSelectionInBlockquote
},
changes: {
wrapInBlockquote: wrapInBlockquote.bind(null, opts),
unwrapBlockquote: bindChange(unwrapBlockquote)
}
};
return _extends({}, corePlugin, {
onKeyDown: _handlers.onKeyDown.bind(null, opts)
});
}
module.exports = EditBlockquote;
exports.default = EditBlockquote;

@@ -1,56 +0,54 @@

/* eslint-disable react/prop-types */
// @flow
/* eslint-disable import/no-extraneous-dependencies */
/* global document */
import React from 'react';
import ReactDOM from 'react-dom';
import { Editor } from 'slate-react';
import PluginEditBlockquote from '../lib/';
const React = require('react');
const ReactDOM = require('react-dom');
const Slate = require('slate');
const { Editor } = require('slate-react');
const PluginEditBlockquote = require('../lib/');
import INITIAL_VALUE from './value';
const stateJson = require('./state');
const plugin = PluginEditBlockquote();
const plugins = [
plugin
];
const plugins = [plugin];
const SCHEMA = {
nodes: {
blockquote: props => <blockquote {...props.attributes}>{props.children}</blockquote>,
paragraph: props => <p {...props.attributes}>{props.children}</p>,
heading: props => <h1 {...props.attributes}>{props.children}</h1>
function renderNode(props: *) {
const { node, children, attributes } = props;
switch (node.type) {
case 'blockquote':
return <blockquote {...attributes}>{children}</blockquote>;
case 'paragraph':
return <p {...attributes}>{children}</p>;
case 'heading':
return <h1 {...attributes}>{children}</h1>;
default:
return null;
}
};
}
const Example = React.createClass({
getInitialState() {
return {
state: Slate.State.fromJSON(stateJson)
};
},
class Example extends React.Component<*, *> {
state = {
value: INITIAL_VALUE
};
onChange({ state }) {
onChange = ({ value }) => {
this.setState({
state
value
});
},
};
onWrapInBlockquote(e) {
const { state } = this.state;
onWrapInBlockquote = e => {
const { value } = this.state;
this.onChange(
plugin.changes.wrapInBlockquote(state.change())
);
},
this.onChange(plugin.changes.wrapInBlockquote(value.change()));
};
onUnwrapBlockquote(e) {
const { state } = this.state;
onUnwrapBlockquote = e => {
const { value } = this.state;
this.onChange(
plugin.changes.unwrapBlockquote(state.change())
);
},
this.onChange(plugin.changes.unwrapBlockquote(value.change()));
};
render() {
const { state } = this.state;
const inBlockquote = plugin.utils.isSelectionInBlockquote(state);
const { value } = this.state;
const inBlockquote = plugin.utils.isSelectionInBlockquote(value);

@@ -60,4 +58,11 @@ return (

<div>
<button onClick={this.onWrapInBlockquote}>Blockquote</button>
<button onClick={this.onUnwrapBlockquote} disabled={!inBlockquote}>Unwrap</button>
<button onClick={this.onWrapInBlockquote}>
Blockquote
</button>
<button
onClick={this.onUnwrapBlockquote}
disabled={!inBlockquote}
>
Unwrap
</button>
</div>

@@ -67,5 +72,5 @@ <Editor

plugins={plugins}
state={state}
value={value}
onChange={this.onChange}
schema={SCHEMA}
renderNode={renderNode}
/>

@@ -75,7 +80,5 @@ </div>

}
});
}
ReactDOM.render(
<Example />,
document.getElementById('example')
);
// $FlowFixMe
ReactDOM.render(<Example />, document.getElementById('example'));
{
"name": "slate-edit-blockquote",
"description": "A Slate plugin to handle keyboard events in blockquotes.",
"version": "0.4.0",
"version": "0.5.0",
"license": "Apache-2.0",

@@ -9,15 +9,21 @@ "repository": "git://github.com/GitbookIO/slate-edit-blockquote.git",

"peerDependencies": {
"slate": "^0.23.0"
"slate": "^0.29.0",
"immutable": "^3.8.1"
},
"devDependencies": {
"babel-cli": "^6.11.4",
"babel-core": "^6.11.4",
"babel-preset-es2015": "^6.9.0",
"babel-preset-react": "^6.11.1",
"babelify": "^7.3.0",
"browserify": "^13.1.0",
"eslint": "^3.1.1",
"eslint-config-gitbook": "1.1.2",
"babel-cli": "^6.26.0",
"babel-core": "^6.26.0",
"babel-eslint": "^8.0.2",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babelify": "^8.0.0",
"browserify": "^13.3.0",
"eslint": "^4.10.0",
"eslint-config-gitbook": "^2.0.3",
"eslint-plugin-import": "^2.8.0",
"expect": "^1.20.2",
"gh-pages": "^0.11.0",
"flow-bin": "^0.57.3",
"http-server": "^0.9.0",

@@ -29,4 +35,5 @@ "immutable": "^3.8.1",

"read-metadata": "^1.0.0",
"slate": "^0.24.0",
"slate-react": "^0.1.4"
"slate": "^0.29.0",
"slate-hyperscript": "^0.4.6",
"slate-react": "^0.10.0"
},

@@ -37,7 +44,7 @@ "scripts": {

"lint": "eslint ./",
"build-example": "browserify ./example/main.js -o ./example/bundle.js -t [ babelify --presets [ es2015 react ] ]",
"build-example": "browserify ./example/main.js -o ./example/bundle.js -t [ babelify --presets [ es2015 react stage-0 ] ]",
"serve-example": "http-server ./example/ -p 8080",
"start": "npm run build-example && npm run serve-example",
"deploy-example": "npm run build-example && gh-pages -d ./example",
"test": "./node_modules/.bin/mocha ./tests/all.js --compilers js:babel-register --bail --reporter=list"
"test": "./node_modules/.bin/mocha ./tests/all.js --compilers js:babel-register --reporter=list"
},

@@ -44,0 +51,0 @@ "keywords": [

@@ -44,3 +44,3 @@ # slate-edit-blockquote

`plugin.utils.isSelectionInBlockquote(state: State) => Boolean`
`plugin.utils.isSelectionInBlockquote(value: Value) => Boolean`

@@ -47,0 +47,0 @@ Return true if selection is inside a blockquote (and it can be unwrap).

@@ -1,37 +0,43 @@

const expect = require('expect');
const fs = require('fs');
const path = require('path');
const Slate = require('slate');
const readMetadata = require('read-metadata');
import expect from 'expect';
import fs from 'fs';
import path from 'path';
import Slate from 'slate';
import readMetadata from 'read-metadata';
const EditBlockquote = require('../lib');
import EditBlockquote from '../lib';
describe('slate-edit-blockquote', function() {
const PLUGIN = EditBlockquote();
const SCHEMA = Slate.Schema.create({
plugins: [PLUGIN]
});
function deserializeValue(json) {
return Slate.Value.fromJSON(
{ ...json, schema: SCHEMA },
{ normalize: false }
);
}
describe('slate-edit-blockquote', () => {
const tests = fs.readdirSync(__dirname);
const plugin = EditBlockquote();
tests.forEach(function(test) {
tests.forEach((test, index) => {
if (test[0] === '.' || path.extname(test).length > 0) return;
it(test, function() {
it(test, () => {
const dir = path.resolve(__dirname, test);
const inputPath = path.resolve(dir, 'input.yaml');
const input = readMetadata.sync(inputPath);
const input = readMetadata.sync(path.resolve(dir, 'input.yaml'));
const expectedPath = path.resolve(dir, 'expected.yaml');
let expected;
if (fs.existsSync(expectedPath)) {
expected = Slate.State.fromJSON(readMetadata.sync(expectedPath)).toJSON();
}
const expected =
fs.existsSync(expectedPath) && readMetadata.sync(expectedPath);
const runChange = require(path.resolve(dir, 'change.js'));
// eslint-disable-next-line
const runChange = require(path.resolve(dir, 'change.js')).default;
const stateInput = Slate.State.fromJSON(input);
const valueInput = deserializeValue(input);
const newChange = runChange(plugin, stateInput.change());
const newChange = runChange(PLUGIN, valueInput.change());
if (expected) {
const newDocJSon = newChange.state.toJSON();
expect(newDocJSon).toEqual(expected);
const newDocJSon = newChange.value.toJSON();
expect(newDocJSon).toEqual(deserializeValue(expected).toJSON());
}

@@ -38,0 +44,0 @@ });

@@ -1,4 +0,3 @@

module.exports = function(plugin, change) {
const selectedBlock = change.state.document.getDescendant('_selection_key');
export default function(plugin, change) {
const selectedBlock = change.value.document.getDescendant('_selection_key');
change.collapseToStartOf(selectedBlock);

@@ -9,9 +8,10 @@

preventDefault() {},
stopPropagation() {}
stopPropagation() {},
key: 'Backspace'
},
{ key: 'backspace' },
change
change,
{}
);
return change;
};
}

@@ -1,4 +0,3 @@

module.exports = function(plugin, change) {
const selectedBlock = change.state.document.getDescendant('_selection_key');
export default function(plugin, change) {
const selectedBlock = change.value.document.getDescendant('_selection_key');
change.collapseToStartOf(selectedBlock);

@@ -9,9 +8,10 @@

preventDefault() {},
stopPropagation() {}
stopPropagation() {},
key: 'Enter'
},
{ key: 'enter' },
change
change,
{}
);
return change;
};
}

@@ -1,5 +0,5 @@

const expect = require('expect');
import expect from 'expect';
module.exports = function(plugin, change) {
const selectedBlock = change.state.document.getDescendant('_selection_key');
export default function(plugin, change) {
const selectedBlock = change.value.document.getDescendant('_selection_key');
change.collapseToStartOf(selectedBlock);

@@ -10,11 +10,12 @@

preventDefault() {},
stopPropagation() {}
stopPropagation() {},
key: 'Enter'
},
{ key: 'enter' },
change
change,
{}
);
expect(newChange).toBeFalsy();
expect(newChange).toBe(undefined);
return change;
};
}

@@ -1,6 +0,3 @@

const Slate = require('slate');
module.exports = function(plugin, change) {
const schema = new Slate.Schema(plugin.schema);
return change.normalize(schema);
};
export default function(plugin, change) {
return change.normalize();
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc