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

draftjs-utils

Package Overview
Dependencies
Maintainers
1
Versions
48
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

draftjs-utils - npm Package Compare versions

Comparing version 0.2.9 to 0.3.0

js/__test__/.eslintrc

7

config/test-setup.js

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

require('babel-register')();
const jsdom = require('jsdom').jsdom;

@@ -5,6 +7,7 @@

require('babel-register')();
global.document = jsdom('');
global.window = document.defaultView;
global.HTMLElement = window.HTMLElement;
global.HTMLAnchorElement = window.HTMLAnchorElement;
Object.keys(document.defaultView).forEach((property) => {

@@ -11,0 +14,0 @@ if (typeof global[property] === 'undefined') {

@@ -11,3 +11,3 @@ var path = require('path');

path: path.join(__dirname, '../lib'),
filename: 'index.js',
filename: 'draftjs-utils.js',
libraryTarget: 'commonjs2',

@@ -14,0 +14,0 @@ },

import { assert } from 'chai';
import {
EditorState,
convertFromHTML,
ContentState,
} from 'draft-js';
import {
getAllBlocks,

@@ -13,7 +18,2 @@ getSelectedBlock,

} from '../block';
import {
EditorState,
convertFromHTML,
ContentState,
} from 'draft-js';

@@ -20,0 +20,0 @@ describe('BlockUtils test suite', () => {

import { assert } from 'chai';
import { spy } from 'sinon';
import { forEach, size } from '../common';
import { spy } from 'sinon';

@@ -5,0 +5,0 @@ describe('forEach test suite', () => {

@@ -0,1 +1,2 @@

import { assert } from 'chai';
import {

@@ -21,3 +22,2 @@ Entity,

import { forEach, size } from '../common';
import { assert } from 'chai';

@@ -130,3 +130,3 @@ describe('getSelectionInlineStyle test suite', () => {

});
assert.equal(size(customStyleMap), size(colors) * 2 + size(fontSizes) + size(fontFamilies));
assert.equal(size(customStyleMap), (size(colors) * 2) + size(fontSizes) + size(fontFamilies));
});

@@ -133,0 +133,0 @@ });

@@ -64,3 +64,3 @@ /* @flow */

const blocks = getSelectedBlocksList(editorState);
const hasMultipleBlockTypes = blocks.some((block) => block.type !== blocks.get(0).type);
const hasMultipleBlockTypes = blocks.some(block => block.type !== blocks.get(0).type);
if (!hasMultipleBlockTypes) {

@@ -96,3 +96,3 @@ return blocks.get(0).type;

}
for (let i = 0; i < selectedBlocks.size; i++) {
for (let i = 0; i < selectedBlocks.size; i += 1) {
const blockStart = i === 0 ? start : 0;

@@ -178,3 +178,3 @@ const blockEnd =

if (selectedBlocks && selectedBlocks.size > 0) {
for (let i = 0; i < selectedBlocks.size; i++) {
for (let i = 0; i < selectedBlocks.size; i += 1) {
const data = selectedBlocks.get(i).getData();

@@ -181,0 +181,0 @@ if (!data || data.size === 0) {

@@ -9,3 +9,3 @@ /* @flow */

for (const key in obj) { // eslint-disable-line no-restricted-syntax
if (obj.hasOwnProperty(key)) {
if ({}.hasOwnProperty.call(obj, key)) {
callback(key, obj[key]);

@@ -24,3 +24,3 @@ }

forEach(object, () => {
count++;
count += 1;
});

@@ -27,0 +27,0 @@ return count;

@@ -28,6 +28,4 @@ /* @flow */

} from './block';
import handleNewLine from './keyPress';
import {
handleNewLine,
} from './keyPress';
import {
isListBlock,

@@ -34,0 +32,0 @@ changeDepth,

@@ -37,3 +37,3 @@ /* @flow */

};
for (let i = 0; i < selectedBlocks.size; i++) {
for (let i = 0; i < selectedBlocks.size; i += 1) {
let blockStart = i === 0 ? start : 0;

@@ -48,5 +48,5 @@ let blockEnd =

}
for (let j = blockStart; j < blockEnd; j++) {
for (let j = blockStart; j < blockEnd; j += 1) {
const inlineStylesAtOffset = selectedBlocks.get(i).getInlineStyleAt(j);
['BOLD', 'ITALIC', 'UNDERLINE', 'STRIKETHROUGH', 'CODE'].forEach(style => {
['BOLD', 'ITALIC', 'UNDERLINE', 'STRIKETHROUGH', 'CODE'].forEach((style) => {
inlineStyles[style] = inlineStyles[style] && inlineStylesAtOffset.get(style) === style;

@@ -77,3 +77,3 @@ });

for (let i = start; i < end; i++) {
for (let i = start; i < end; i += 1) {
const currentEntity = block.getEntityAt(i);

@@ -86,7 +86,5 @@ if (!currentEntity) {

entity = currentEntity;
} else {
if (entity !== currentEntity) {
entity = undefined;
break;
}
} else if (entity !== currentEntity) {
entity = undefined;
break;
}

@@ -109,3 +107,3 @@ }

block.findEntityRanges(
(value) => value.get('entity') === entityKey,
value => value.get('entity') === entityKey,
(start, end) => {

@@ -217,3 +215,3 @@ entityRange = {

const styles = block.getInlineStyleAt(offset).toList();
const style = styles.filter((s) => s.startsWith(stylePrefix.toLowerCase()));
const style = styles.filter(s => s.startsWith(stylePrefix.toLowerCase()));
if (style && style.size > 0) {

@@ -239,3 +237,3 @@ return style.get(0);

const inlineStyles = {};
for (let i = 0; i < selectedBlocks.size; i++) {
for (let i = 0; i < selectedBlocks.size; i += 1) {
let blockStart = i === 0 ? start : 0;

@@ -250,9 +248,9 @@ let blockEnd =

}
for (let j = blockStart; j < blockEnd; j++) {
for (let j = blockStart; j < blockEnd; j += 1) {
if (j === blockStart) {
styles.forEach(s => {
styles.forEach((s) => {
inlineStyles[s] = getStyleAtOffset(selectedBlocks.get(i), s, j);
});
} else {
styles.forEach(s => {
styles.forEach((s) => {
if (inlineStyles[s] &&

@@ -259,0 +257,0 @@ inlineStyles[s] !== getStyleAtOffset(selectedBlocks.get(i), s, j)) {

@@ -63,3 +63,3 @@ /* @flow */

*/
export function handleNewLine(editorState: EditorState, event: Object): EditorState {
export default function handleNewLine(editorState: EditorState, event: Object): EditorState {
if (isSoftNewlineEvent(event)) {

@@ -66,0 +66,0 @@ const selection = editorState.getSelection();

/* @flow */
import { getSelectedBlocksMap } from './block';
import {

@@ -9,2 +8,3 @@ ContentState,

} from 'draft-js';
import { getSelectedBlocksMap } from './block';

@@ -36,3 +36,3 @@ /**

let blockMap = contentState.getBlockMap();
const blocks = getSelectedBlocksMap(editorState).map(block => {
const blocks = getSelectedBlocksMap(editorState).map((block) => {
let depth = block.getDepth() + adjustment;

@@ -39,0 +39,0 @@ depth = Math.max(0, Math.min(depth, maxDepth));

{
"name": "draftjs-utils",
"version": "0.2.9",
"version": "0.3.0",
"description": "Collection of utility function for use with Draftjs.",
"main": "lib/index.js",
"main": "lib/draftjs-utils.js",
"peerDependencies": {
"draft-js": "^0.x.x",
"draft-js": "^0.9.x",
"immutable": "^3.x.x"

@@ -29,2 +29,3 @@ },

"immutable": "^3.8.1",
"jsdom": "^9.8.0",
"mocha": "^3.1.2",

@@ -31,0 +32,0 @@ "react": "^15.3.2",

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