Skip to content

Commit 9020191

Browse files
committed
Major release 1.0.0
1 parent 97ed3df commit 9020191

File tree

9 files changed

+29
-157
lines changed

9 files changed

+29
-157
lines changed

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ npm install @jimmycode/draft-js-unsplash-plugin
1414
## Usage
1515

1616
```js
17-
import createUnsplashPlugin from 'draft-js-unsplash-plugin';
17+
import createUnsplashPlugin from '@jimmycode/draft-js-unsplash-plugin';
1818
const unsplashPlugin = createUnsplashPlugin({
1919
options: {
2020
accessKey: 'my-access-key'
@@ -27,7 +27,7 @@ const { UnsplashButton } = unsplashPlugin;
2727

2828
| Param | Default | Description |
2929
|-------------------|-------------------------------------|-------------------------------------------------------------------|
30-
| theme | Default styles | draft-js-unsplash-plugin/lib/plugin.css |
30+
| theme | Default styles | @jimmycode/draft-js-unsplash-plugin/lib/plugin.css |
3131
| options | Default behavior | List of options. |
3232
| explorerType | 'draft-js-unsplash-plugin-explorer' | Type of entity created when inserting the explorer block. |
3333
| unsplashType | 'unsplash' | Type of entity created when inserting the image. |
@@ -46,7 +46,7 @@ const { UnsplashButton } = unsplashPlugin;
4646
| getMetadata | - | Function to determine the metadata inserted along with the image selected. It MUST return an object with at least the following keys: - src - width - height - user |
4747

4848
## Theming
49-
The plugin ships with a default styling available at this location in the installed package: `node_modules/draft-js-unsplash-plugin/lib/plugin.css`
49+
The plugin ships with a default styling available at this location in the installed package: `node_modules/@jimmycode/draft-js-unsplash-plugin/lib/plugin.css`
5050

5151
*Webpack Usage*
5252
1. Install Webpack loaders: `npm i style-loader css-loader --save-dev`
@@ -71,7 +71,7 @@ module.exports = {
7171

7272

7373
```js
74-
import 'draft-js-unsplash-plugin/lib/plugin.css';
74+
import '@jimmycode/draft-js-unsplash-plugin/lib/plugin.css';
7575
```
7676

7777
## Example
@@ -84,10 +84,10 @@ import Editor from 'draft-js-plugins-editor';
8484
import { EditorState } from 'draft-js';
8585
import createSideToolbarPlugin from 'draft-js-side-toolbar-plugin';
8686
import BlockTypeSelect from 'draft-js-side-toolbar-plugin/lib/components/BlockTypeSelect';
87-
import createUnsplashPlugin from 'draft-js-unsplash-plugin';
87+
import createUnsplashPlugin from '@jimmycode/draft-js-unsplash-plugin';
8888

8989
import 'draft-js-side-toolbar-plugin/lib/plugin.css';
90-
import 'draft-js-unsplash-plugin/lib/plugin.css';
90+
import '@jimmycode/draft-js-unsplash-plugin/lib/plugin.css';
9191

9292
const unsplashPlugin = createUnsplashPlugin({
9393
unsplashPlugin: {
@@ -158,12 +158,12 @@ import BlockTypeSelect from 'draft-js-side-toolbar-plugin/lib/components/BlockTy
158158
import createResizeablePlugin from 'draft-js-resizeable-plugin';
159159
import createAlignmentPlugin from 'draft-js-alignment-plugin';
160160
import createFocusPlugin from 'draft-js-focus-plugin';
161-
import createUnsplashPlugin from 'draft-js-unsplash-plugin';
161+
import createUnsplashPlugin from '@jimmycode/draft-js-unsplash-plugin';
162162

163163
import 'draft-js-side-toolbar-plugin/lib/plugin.css';
164164
import 'draft-js-alignment-plugin/lib/plugin.css';
165165
import 'draft-js-focus-plugin/lib/plugin.css';
166-
import 'draft-js-unsplash-plugin/lib/plugin.css';
166+
import '@jimmycode/draft-js-unsplash-plugin/lib/plugin.css';
167167

168168
const focusPlugin = createFocusPlugin();
169169
const resizeablePlugin = createResizeablePlugin();
@@ -234,7 +234,6 @@ class MyEditor extends React.Component {
234234
<AlignmentTool />
235235
</div>
236236
</div>
237-
238237
</div>
239238
);
240239
}

package-lock.json

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@jimmycode/draft-js-unsplash-plugin",
3-
"version": "0.5.3",
3+
"version": "1.0.0",
44
"description": "Add Unsplash images in your draft-js editor.",
55
"keywords": [
66
"draft-js",
@@ -74,6 +74,7 @@
7474
"webpack-node-externals": "^1.7.2"
7575
},
7676
"dependencies": {
77+
"@jimmycode/draft-js-toolbox": "^1.0.0",
7778
"decorate-component-with-props": "^1.1.0",
7879
"prop-types": "^15.6.1",
7980
"react-photo-gallery": "^6.0.27",

src/components/Button/index.js

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import unionClassNames from 'union-class-names';
4+
import { isCurrentBlockType } from '@jimmycode/draft-js-toolbox';
45

56
/**
67
* Icon by: https://www.iconfinder.com/icons/115759/camera_icon
@@ -19,19 +20,9 @@ class UnsplashButton extends React.PureComponent {
1920
event.preventDefault();
2021
}
2122

22-
blockTypeIsActive = () => {
23-
const editorState = this.props.getEditorState();
24-
const blockType = editorState
25-
.getCurrentContent()
26-
.getBlockForKey(editorState.getSelection().getStartKey())
27-
.getType();
28-
29-
return blockType === this.props.entityType;
30-
};
31-
3223
render () {
33-
const { theme } = this.props;
34-
const className = this.blockTypeIsActive()
24+
const { theme, getEditorState, entityType } = this.props;
25+
const className = isCurrentBlockType(getEditorState(), entityType)
3526
? unionClassNames(theme.button, theme.active)
3627
: theme.button;
3728

src/components/Unsplash/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
import unionClassNames from 'union-class-names';
23

34
export default class Unsplash extends React.PureComponent {
45
render() {
@@ -23,7 +24,7 @@ export default class Unsplash extends React.PureComponent {
2324
...elementProps
2425
} = otherProps;
2526

26-
const combinedClassName = `${theme.unsplash} ${className || ''}`;
27+
const combinedClassName = unionClassNames(theme.unsplash, className);
2728
const { src, user, description, source } = contentState.getEntity(block.getEntityAt(0)).getData();
2829

2930
const captionPrefix = description ?

src/createUnsplashPlugin.js

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import decorateComponentWithProps from 'decorate-component-with-props';
22
import { getDefaultKeyBinding } from 'draft-js';
3+
import { isBlockWithEntityType, getCurrentBlock, addBlock, addAtomicBlock, removeBlock } from '@jimmycode/draft-js-toolbox';
34
import { UnsplashButton, UnsplashExplorer, Unsplash } from './components';
4-
import { addBlock, addAtomicBlock, removeBlock, getCurrentBlock } from './modifiers';
55
import { buildSearchPhotosUrl } from './utils';
66
import defaultTheme from './plugin.css';
77

@@ -55,20 +55,11 @@ export default ({
5555

5656
return {
5757
blockRendererFn: (block, { getEditorState, setEditorState, setReadOnly }) => {
58-
if (block.getType () === ATOMIC) {
59-
const contentState = getEditorState().getCurrentContent();
60-
const entityKey = block.getEntityAt(0);
61-
62-
if (!entityKey) {
63-
return null;
64-
}
65-
66-
if (contentState.getEntity(entityKey).getType() === unsplashType) {
67-
return {
68-
component: ThemedUnsplash,
69-
editable
70-
};
71-
}
58+
if (isBlockWithEntityType(getEditorState(), block, unsplashType)) {
59+
return {
60+
component: ThemedUnsplash,
61+
editable
62+
};
7263
}
7364
else if (block.getType() === explorerType) {
7465
return {
@@ -96,8 +87,7 @@ export default ({
9687
// When select the picture.
9788
onSelect: (block, data) => {
9889
let editorState = removeBlock(getEditorState(), block.key);
99-
editorState = addUnsplash(editorState, data);
100-
setEditorState(editorState);
90+
setEditorState(addUnsplash(editorState, data));
10191
}
10292
}
10393
};

src/modifiers/addBlock.js

Lines changed: 0 additions & 55 deletions
This file was deleted.

src/modifiers/index.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/modifiers/removeBlock.js

Lines changed: 0 additions & 58 deletions
This file was deleted.

0 commit comments

Comments
 (0)