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

draftjs-filters

Package Overview
Dependencies
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

draftjs-filters - npm Package Compare versions

Comparing version 2.2.0 to 2.2.1

7

CHANGELOG.md

@@ -7,2 +7,9 @@ # Changelog

## [2.2.1](https://github.com/thibaudcolas/draftjs-filters/compare/v2.2.0...v2.2.1) (2019-01-23)
### Bug Fixes
- **api:** auto-generate documentation using flow types. Fix [#19](https://github.com/thibaudcolas/draftjs-filters/issues/19) ([#26](https://github.com/thibaudcolas/draftjs-filters/issues/26)) ([a2da323](https://github.com/thibaudcolas/draftjs-filters/commit/a2da323))
- **api:** auto-update API docs in README ([aa40707](https://github.com/thibaudcolas/draftjs-filters/commit/aa40707))
# [2.2.0](https://github.com/thibaudcolas/draftjs-filters/compare/v2.1.0...v2.2.0) (2019-01-22)

@@ -9,0 +16,0 @@

9

dist/draftjs-filters.cjs.js

@@ -49,2 +49,3 @@ // @flow

* Resets atomic blocks to have a single-space char and no styles.
* This is how they are stored by Draft.js by default.
*/

@@ -295,3 +296,2 @@ var resetAtomicBlocks = function resetAtomicBlocks(content /*: ContentState*/) {

*/
/*:: import type { BlockNode } from "draft-js/lib/BlockNode.js.flow"*/
var cloneEntities = function cloneEntities(content /*: ContentState*/) {

@@ -353,2 +353,4 @@ var newContent = content;

/*:: import type { BlockNode } from "draft-js/lib/BlockNode.js.flow" */
/**

@@ -366,3 +368,3 @@ * Filters entity ranges (where entities are applied on text) based on the result of

/**
/*
* Removes entities from the character list if the entity isn't enabled.

@@ -445,2 +447,4 @@ * Also removes image entities placed outside of atomic blocks, which can happen

* Filters data on an entity to only retain what is whitelisted.
* This is crucial for IMAGE and LINK, where Draft.js adds a lot
* of unneeded attributes (width, height, etc).
*/

@@ -634,2 +638,3 @@ var filterEntityData = function filterEntityData(entityTypes /*: Array<Object>*/, content /*: ContentState*/) {

* to enforce it's shaped according to the options.
* Will not alter the editor state if there are no changes to make.
*/

@@ -636,0 +641,0 @@ var filterEditorState = function filterEditorState(options /*: FilterOptions*/, editorState /*: EditorStateType*/) {

@@ -44,2 +44,3 @@ // @flow

* Resets atomic blocks to have a single-space char and no styles.
* This is how they are stored by Draft.js by default.
*/

@@ -290,3 +291,2 @@ var resetAtomicBlocks = function resetAtomicBlocks(content /*: ContentState*/) {

*/
/*:: import type { BlockNode } from "draft-js/lib/BlockNode.js.flow"*/
var cloneEntities = function cloneEntities(content /*: ContentState*/) {

@@ -348,2 +348,4 @@ var newContent = content;

/*:: import type { BlockNode } from "draft-js/lib/BlockNode.js.flow" */
/**

@@ -361,3 +363,3 @@ * Filters entity ranges (where entities are applied on text) based on the result of

/**
/*
* Removes entities from the character list if the entity isn't enabled.

@@ -440,2 +442,4 @@ * Also removes image entities placed outside of atomic blocks, which can happen

* Filters data on an entity to only retain what is whitelisted.
* This is crucial for IMAGE and LINK, where Draft.js adds a lot
* of unneeded attributes (width, height, etc).
*/

@@ -629,2 +633,3 @@ var filterEntityData = function filterEntityData(entityTypes /*: Array<Object>*/, content /*: ContentState*/) {

* to enforce it's shaped according to the options.
* Will not alter the editor state if there are no changes to make.
*/

@@ -631,0 +636,0 @@ var filterEditorState = function filterEditorState(options /*: FilterOptions*/, editorState /*: EditorStateType*/) {

{
"name": "draftjs-filters",
"version": "2.2.0",
"version": "2.2.1",
"description": "Filter Draft.js content to preserve only the formatting you allow",

@@ -44,2 +44,3 @@ "author": "Thibaud Colas",

"danger": "^4.0.2",
"documentation": "^8.1.2",
"draft-js": "0.10.5",

@@ -52,3 +53,3 @@ "enzyme": "^3.6.0",

"normalize.css": "^7.0.0",
"prettier": "^1.14.3",
"prettier": "^1.16.1",
"prismjs": "^1.9.0",

@@ -65,3 +66,2 @@ "react": "^16.2.0",

},
"dependencies": {},
"peerDependencies": {

@@ -82,7 +82,8 @@ "draft-js": "^0.10.4"

"report:package": "npm pack --loglevel notice 2>&1 >/dev/null | sed -e 's/^npm notice //' | tee build/package.txt && rm *.tgz",
"lint": "prettier --list-different '**/*.{js,css,md,json,yaml,yml}'",
"format": "prettier --write '**/*.{js,css,md,json,yaml,yml}'",
"lint": "prettier --check '**/*.{js,css,md,json,yaml,yml,html}' && documentation lint src/**",
"format": "prettier --write '**/*.{js,css,md,json,yaml,yml,html}'",
"test:ci": "npm run lint -s && npm run dist -s && flow && npm run test:coverage -s -- --outputFile build/test-results.json --json",
"prepublishOnly": "npm run dist -s"
"prepublishOnly": "npm run dist -s",
"build:docs": "documentation readme src/lib/index.js -f md > docs/doc.md --section=API --markdown-toc=false && prettier --write README.md"
}
}

@@ -95,138 +95,178 @@ # [Draft.js filters](https://thibaudcolas.github.io/draftjs-filters/) [![npm](https://img.shields.io/npm/v/draftjs-filters.svg)](https://www.npmjs.com/package/draftjs-filters) [![Build Status](https://travis-ci.org/thibaudcolas/draftjs-filters.svg?branch=master)](https://travis-ci.org/thibaudcolas/draftjs-filters) [![Coverage Status](https://coveralls.io/repos/github/thibaudcolas/draftjs-filters/badge.svg)](https://coveralls.io/github/thibaudcolas/draftjs-filters) [<img src="https://cdn.rawgit.com/springload/awesome-wagtail/ac912cc661a7099813f90545adffa6bb3e75216c/logo.svg" width="104" align="right" alt="Wagtail">](https://wagtail.io/)

```jsx
/**
* Creates atomic blocks where they would be required for a block-level entity
* to work correctly, when such an entity exists.
* Note: at the moment, this is only useful for IMAGE entities that Draft.js
* injects on arbitrary blocks on paste.
*/
#### API
preserveAtomicBlocks((content: ContentState))
<!-- Generated by documentation.js. Update this documentation by updating the source code. -->
/**
* Resets atomic blocks to have a single-space char and no styles.
*/
##### preserveAtomicBlocks
resetAtomicBlocks((content: ContentState))
Creates atomic blocks where they would be required for a block-level entity
to work correctly, when such an entity exists.
Note: at the moment, this is only useful for IMAGE entities that Draft.js
injects on arbitrary blocks on paste.
/**
* Removes atomic blocks for which the entity isn't whitelisted.
*/
###### Parameters
removeInvalidAtomicBlocks((whitelist: Array<Object>), (content: ContentState))
- `content` **ContentState**
/**
* Removes blocks that have a non-zero depth, and aren't list items.
* Happens with Apple Pages inserting `unstyled` items between list items.
*/
##### resetAtomicBlocks
removeInvalidDepthBlocks((content: ContentState))
Resets atomic blocks to have a single-space char and no styles.
This is how they are stored by Draft.js by default.
/**
* Resets the depth of all the content to at most max.
*/
###### Parameters
limitBlockDepth((max: number), (content: ContentState))
- `content` **ContentState**
/**
* Changes block type and depth based on the block's text. – some word processors
* add a specific prefix within the text, eg. "· Bulleted list" in Word 2010.
* Also removes the matched text.
* This is meant first and foremost for list items where the list bullet or numeral
* ends up in the text. Other use cases may not be well covered.
*/
preserveBlockByText(
(rules: Array<{
test: string,
type: string,
depth: number,
}>),
(content: ContentState),
)
##### removeInvalidAtomicBlocks
/**
* Converts all block types not present in the whitelist to unstyled.
* Also sets depth to 0 (for potentially nested list items).
*/
Removes atomic blocks for which the entity isn't whitelisted.
filterBlockTypes((whitelist: Array<string>), (content: ContentState))
###### Parameters
/**
* Removes all styles not present in the whitelist.
*/
- `whitelist` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>**
- `content` **ContentState**
filterInlineStyles((whitelist: Array<string>), (content: ContentState))
##### removeInvalidDepthBlocks
/**
* Clones entities in the entityMap, so each range points to its own entity instance.
* This only clones entities as necessary – if an entity is only referenced
* in a single range, it won't be changed.
*/
cloneEntities((content: ContentState))
Removes blocks that have a non-zero depth, and aren't list items.
Happens with Apple Pages inserting `unstyled` items between list items.
/**
* Filters entity ranges (where entities are applied on text) based on the result of
* the callback function. Returning true keeps the entity range, false removes it.
* Draft.js automatically removes entities if they are not applied on any text.
*/
###### Parameters
filterEntityRanges(
(filterFn: (
content: ContentState,
entityKey: string,
block: ContentBlock,
) => boolean),
(content: ContentState),
)
- `content` **ContentState**
/**
* Keeps all entity types (images, links, documents, embeds) that are enabled.
*/
##### preserveBlockByText
shouldKeepEntityType((whitelist: Array<Object>), (type: string))
Changes block type and depth based on the block's text. – some word processors
add a specific prefix within the text, eg. "· Bulleted list" in Word 2010.
Also removes the matched text.
This is meant first and foremost for list items where the list bullet or numeral
ends up in the text. Other use cases may not be well covered.
/**
* Removes invalid images – they should only be in atomic blocks.
* This only removes the image entity, not the camera emoji (📷) that Draft.js inserts.
* If we want to remove this in the future, consider that:
* - It needs to be removed in the block text, where it's 2 chars / 1 code point.
* - The corresponding CharacterMetadata needs to be removed too, and it's 2 instances
*/
###### Parameters
shouldRemoveImageEntity((entityType: string), (blockType: string))
- `rules` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;{test: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), type: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), depth: [number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)}>**
- `content` **ContentState**
/**
* Filters entities based on the data they contain.
*/
##### limitBlockDepth
shouldKeepEntityByAttribute(
(entityTypes: Array<Object>),
(entityType: string),
(data: Object),
)
Resets the depth of all the content to at most max.
/**
* Filters data on an entity to only retain what is whitelisted.
*/
###### Parameters
filterEntityData((entityTypes: Array<Object>), (content: ContentState))
- `max` **[number](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number)**
- `content` **ContentState**
/**
* Replaces the given characters by their equivalent length of spaces, in all blocks.
*/
##### filterBlockTypes
replaceTextBySpaces((characters: Array<string>), (content: ContentState))
Converts all block types not present in the whitelist to unstyled.
Also sets depth to 0 (for potentially nested list items).
/**
* Applies the new content to the editor state, optionally moving the selection
* to be on a valid block (https://github.com/thibaudcolas/draftjs-filters/issues/27).
*/
###### Parameters
applyContentWithSelection = (
editorState: EditorStateType,
content: ContentState,
nextContent: ContentState,
)
```
- `whitelist` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
- `content` **ContentState**
##### filterInlineStyles
Removes all styles not present in the whitelist.
###### Parameters
- `whitelist` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
- `content` **ContentState**
##### cloneEntities
Clones entities in the entityMap, so each range points to its own entity instance.
This only clones entities as necessary – if an entity is only referenced
in a single range, it won't be changed.
###### Parameters
- `content` **ContentState**
##### filterEntityRanges
Filters entity ranges (where entities are applied on text) based on the result of
the callback function. Returning true keeps the entity range, false removes it.
Draft.js automatically removes entities if they are not applied on any text.
###### Parameters
- `filterFn` **function (content: ContentState, entityKey: [string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String), block: BlockNode): [boolean](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
- `content` **ContentState**
##### shouldKeepEntityType
Keeps all entity types (images, links, documents, embeds) that are enabled.
###### Parameters
- `whitelist` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>**
- `type` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
##### shouldRemoveImageEntity
Removes invalid images – they should only be in atomic blocks.
This only removes the image entity, not the camera emoji (📷) that Draft.js inserts.
###### Parameters
- `entityType` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `blockType` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
##### shouldKeepEntityByAttribute
Filters entities based on the data they contain.
###### Parameters
- `entityTypes` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>**
- `entityType` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)**
- `data` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)**
##### filterEntityData
Filters data on an entity to only retain what is whitelisted.
This is crucial for IMAGE and LINK, where Draft.js adds a lot
of unneeded attributes (width, height, etc).
###### Parameters
- `entityTypes` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)>**
- `content` **ContentState**
##### replaceTextBySpaces
Replaces the given characters by their equivalent length of spaces, in all blocks.
###### Parameters
- `characters` **[Array](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)>**
- `content` **ContentState**
##### applyContentWithSelection
Applies the new content to the editor state, optionally moving the selection
to be on a valid block, inserting one if needed.
See <https://github.com/thibaudcolas/draftjs-filters/issues/27>.
###### Parameters
- `editorState` **EditorState**
- `content` **ContentState**
- `nextContent` **ContentState**
##### filterEditorState
Applies whitelist and blacklist operations to the editor content,
to enforce it's shaped according to the options.
Will not alter the editor state if there are no changes to make.
###### Parameters
- `options` **FilterOptions**
- `editorState` **EditorStateType**
### Browser support and polyfills

@@ -233,0 +273,0 @@

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