Skip to content

Commit

Permalink
Initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
sugarshin committed Apr 23, 2017
0 parents commit 92b8d59
Show file tree
Hide file tree
Showing 46 changed files with 5,334 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["es2016", "es2015"],
"plugins": ["transform-flow-strip-types"]
}
25 changes: 25 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"extends": ["eslint:recommended", "plugin:flowtype/recommended"],
"plugins": ["babel", "flowtype"],
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "module"
},
"env": {
"browser": true,
"node": true
},
"rules": {
"babel/new-cap": 0,
"babel/no-invalid-this": 1,
"semi": [2, "never"],
"comma-dangle": [2, {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "never",
"exports": "never",
"functions": "never"
}],
"no-extra-boolean-cast": 0
}
}
10 changes: 10 additions & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[ignore]

[include]

[libs]
flow/stub/__dev__.js

[options]
module.system=haste
suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(2[0-8]\\|1[0-9]\\|[0-9]\\).[0-9]\\)? *\\).*\n
65 changes: 65 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
### https://raw.github.com/github/gitignore/d4d2c86ccc0fa7e794793454c083c8bdb9657f13/Node.gitignore

# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

*.js
!/src/**
!/test/**
!/flow/**
157 changes: 157 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# draft-js-modifiers

[![CircleCI][circleci-image]][circleci-url]
[![Coverage Status][coveralls-image]][coveralls-url]
[![npm version][npm-image]][npm-url]
[![License][license-image]][license-url]

Modular state modifiers for [Draft.js](https://draftjs.org/)

```bash
yarn add draft-js-modifiers

# or

npm i draft-js-modifiers
```

## Usage

```js
import * as Modifiers from 'draft-js-modifiers'

const newEditorState = Modifiers.mergeBlockData(currentEditorState, { foo: 1 })
```

### Moduler importing

```js
import adjustBlockDepth from 'draft-js-modifiers/adjustBlockDepth'

// Support Tree Shaking for webpack, rollup.js
import { insertText } from 'draft-js-modifiers'
```

## Methods

### `adjustBlockDepth`

```js
adjustBlockDepth(editorState: EditorState, adjustment: number, maxDepth: number)
```

### `insertAtomicBlock`

```js
insertAtomicBlock(
editorState: EditorState,
entityType: string,
mutability: 'IMMUTABLE' | 'MUTABLE' | 'SEGMENTED',
data?: { [id: string]: any },
character?: ?string = ' '
)
```
### `insertEmptyBlock`
```js
insertEmptyBlock(editorState: EditorState, blockType?: DraftBlockType = 'unstyled')
```
### `insertNewBlock`
```js
insertNewBlock(
editorState: EditorState,
blockType?: DraftBlockType = 'unstyled',
text?: string = '',
data?: { [id: string]: any } = {}
)
```
### `insertText`
```js
insertText(editorState: EditorState, text: string, entity?: ?string = null)
```
### `mergeBlockData`
```js
mergeBlockData(editorState: EditorState, data: { [id: string]: any })
```
### `mergeBlockDataByKey`
```js
mergeBlockDataByKey(editorState: EditorState, blockKey: string, data: { [id: string]: any })
```
### `mergeEntityData`
```js
mergeEntityData(editorState: EditorState, entityKey: string, data: { [id: string]: any })
```
### `modifyBlock`
```js
modifyBlock(editorState: EditorState, blockData: ContentBlock)
```
### `modifyBlockByKey`
```js
modifyBlockByKey(editorState: EditorState, blockKey: string, blockData: ContentBlock)
```
### `removeBlockStyle`
```js
removeBlockStyle(editorState: EditorState)
```
### `removeInlineStyles`
```js
removeInlineStyles(editorState: EditorState, inlineStyles: Array<string> = [])
```
### `resetBlock`
```js
resetBlock(editorState: EditorState, block: ContentBlock)
```
### `toggleBlockType`
```js
toggleBlockType(editorState: EditorState, blockType: string)
```
### `toggleEntity`
```js
toggleEntity(editorState: EditorState, entityKey: ?string)
```
### `toggleInlineStyle`
```js
toggleInlineStyle(editorState: EditorState, inlineStyle: string)
```
## License
[MIT][license-url]
© sugarshin
[circleci-image]: https://circleci.com/gh/sugarshin/draft-js-modifiers/tree/master.svg?style=svg&circle-token=f80707ebb99977ec63649c41cb76202f05aa75e1
[circleci-url]: https://circleci.com/gh/sugarshin/draft-js-modifiers/tree/master
[coveralls-image]: https://coveralls.io/repos/github/sugarshin/draft-js-modifiers/badge.svg?branch=master
[coveralls-url]: https://coveralls.io/github/sugarshin/draft-js-modifiers?branch=master
[npm-image]: https://img.shields.io/npm/v/draft-js-modifiers.svg?style=flat-square
[npm-url]: https://www.npmjs.org/package/draft-js-modifiers
[license-image]: https://img.shields.io/:license-mit-blue.svg?style=flat-square
[license-url]: https://sugarshin.mit-license.org/
16 changes: 16 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
machine:
timezone: Asia/Tokyo
node:
version: 6.10.2
post:
- curl -o- -L https://yarnpkg.com/install.sh | bash
dependencies:
pre:
- yarn --version
override:
- yarn
cache_directories:
- ~/.cache/yarn
test:
override:
- yarn test:ci
3 changes: 3 additions & 0 deletions flow/stub/__dev__.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// @flow

declare var __DEV__: boolean
62 changes: 62 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "draft-js-modifiers",
"version": "0.0.0",
"description": "Modular state modifiers for Draft.js",
"main": "index.js",
"module": "es/index.js",
"jsnext:main": "es/index.js",
"files": [
"utils",
"*.js"
],
"keywords": [
"draft-js",
"draft-js-modifiers"
],
"repository": "git@github.com:sugarshin/draft-js-modifiers.git",
"author": "sugarshin",
"license": "MIT",
"scripts": {
"start": "npm run watch:test",
"lint": "eslint src test",
"type": "flow",
"check": "npm run lint && npm run type",
"test": "ava -v",
"test:coverage": "nyc npm test",
"test:coverage:report": "npm run test:coverage && nyc report --reporter=text-lcov | coveralls",
"test:ci": "npm run check && npm run test:coverage:report",
"watch:test": "npm test -- --watch",
"clean:build": "rm -rf ./*.js ./utils",
"prebuild": "npm run clean:build",
"build:commonjs": "BABEL_ENV=commonjs babel -d . src",
"build:es": "BABEL_ENV=es babel -d es src",
"build": "npm run build:commonjs && npm run build:es",
"prepublish": "npm run check && npm run test:coverage && npm run build"
},
"ava": {
"require": [
"babel-register"
]
},
"dependencies": {
"draft-js": "~0.10.0",
"immutable": "~3.7.4"
},
"devDependencies": {
"ava": "^0.19.1",
"babel-cli": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-plugin-transform-flow-strip-types": "^6.22.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-es2016": "^6.24.1",
"coveralls": "^2.13.0",
"eslint": "^3.19.0",
"eslint-plugin-ava": "^4.2.0",
"eslint-plugin-babel": "^4.1.1",
"eslint-plugin-flowtype": "^2.32.1",
"flow-bin": "^0.32.0",
"nyc": "^10.2.0",
"react": "^15.5.4",
"react-dom": "^15.5.4"
}
}
21 changes: 21 additions & 0 deletions src/adjustBlockDepth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// @flow

import { EditorState } from 'draft-js'
import adjustBlockDepthForContentState from 'draft-js/lib/adjustBlockDepthForContentState'

const adjustBlockDepth = (
editorState: EditorState,
adjustment: number,
maxDepth: number
): EditorState => {
const content = adjustBlockDepthForContentState(
editorState.getCurrentContent(),
editorState.getSelection(),
adjustment,
maxDepth
)

return EditorState.push(editorState, content, 'adjust-depth')
}

export default adjustBlockDepth
16 changes: 16 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export { default as adjustBlockDepth } from './adjustBlockDepth'
export { default as insertAtomicBlock } from './insertAtomicBlock'
export { default as insertEmptyBlock } from './insertEmptyBlock'
export { default as insertNewBlock } from './insertNewBlock'
export { default as insertText } from './insertText'
export { default as mergeBlockData } from './mergeBlockData'
export { default as mergeBlockDataByKey } from './mergeBlockDataByKey'
export { default as mergeEntityData } from './mergeEntityData'
export { default as modifyBlock } from './modifyBlock'
export { default as modifyBlockByKey } from './modifyBlockByKey'
export { default as removeBlockStyle } from './removeBlockStyle'
export { default as removeInlineStyles } from './removeInlineStyles'
export { default as resetBlock } from './resetBlock'
export { default as toggleBlockType } from './toggleBlockType'
export { default as toggleEntity } from './toggleEntity'
export { default as toggleInlineStyle } from './toggleInlineStyle'

0 comments on commit 92b8d59

Please sign in to comment.