@the-grid/ed
Advanced tools
Comparing version 0.9.3 to 0.10.0
## dev | ||
## 0.10.0 - 2016-04-15 | ||
* NEW -- `options.onCommandsChanged` to get changing commands in a native toolbar (#173) | ||
* NEW -- `ed.execCommand` to apply a command from an app | ||
## 0.9.3 - 2016-04-15 | ||
@@ -4,0 +9,0 @@ |
@@ -28,7 +28,7 @@ /* eslint no-console: 0 */ | ||
, onChange: () => { console.log('change') } | ||
, onAutosave: () => { console.log('autosave') } | ||
, autosaveInterval: 1000 | ||
, onMount: () => { console.log('mount') } | ||
, onShareFile: onShareFileDemo | ||
, onShareUrl: onShareUrlDemo | ||
, onPlaceholderCancel: onPlaceholderCancelDemo | ||
, onCommandsChanged: (commands) => {} | ||
, imgfloConfig: null | ||
@@ -35,0 +35,0 @@ } |
@@ -5,3 +5,3 @@ { | ||
"license": "MIT", | ||
"version": "0.9.3", | ||
"version": "0.10.0", | ||
"description": "the grid api with prosemirror", | ||
@@ -8,0 +8,0 @@ "main": "dist/ed.js", |
@@ -68,2 +68,5 @@ `npm start` | ||
/* Called once PM and widgets are mounted */ | ||
}, | ||
onCommandsChanged: function (commands) { | ||
/* Object with commandName keys and one of inactive, active, disabled */ | ||
} | ||
@@ -86,2 +89,5 @@ }) | ||
ed.setContent(contentArray) | ||
// Returns true if command applies successfully with current selection | ||
ed.execCommand(commandName) | ||
``` | ||
@@ -91,2 +97,26 @@ | ||
## commands | ||
Apps can apply formatting / editing commands with `ed.execCommand(commandName)` | ||
Supported `commandName` keys: | ||
``` | ||
strong:toggle | ||
em:toggle | ||
link:unset | ||
link:set | ||
paragraph:make | ||
heading:make1 | ||
heading:make2 | ||
heading:make3 | ||
bullet_list:wrap | ||
ordered_list:wrap | ||
blockquote:wrap | ||
lift | ||
ed_upload_image | ||
undo | ||
redo | ||
``` | ||
# dev | ||
@@ -93,0 +123,0 @@ |
@@ -94,3 +94,4 @@ require('./app.css') | ||
, menuBar, menuTip | ||
, onChange, onShareFile, onShareUrl} = this.props | ||
, onChange, onShareFile, onShareUrl | ||
, onCommandsChanged } = this.props | ||
@@ -111,2 +112,3 @@ return el('div' | ||
, onShareUrl | ||
, onCommandsChanged | ||
} | ||
@@ -113,0 +115,0 @@ ) |
@@ -18,2 +18,3 @@ require('./editable.css') | ||
import FixedMenuBarHack from '../plugins/fixed-menu-hack' | ||
import CommandsInterface from '../plugins/commands-interface' | ||
@@ -40,3 +41,4 @@ function noop () { /* noop */ } | ||
, menuBar, menuTip | ||
, onChange, onShareFile} = this.props | ||
, onChange, onShareFile | ||
, onCommandsChanged} = this.props | ||
const {store} = this.context | ||
@@ -82,2 +84,5 @@ | ||
this.pm.on('ed.menu.file', (onShareFile || noop)) | ||
if (onCommandsChanged) { | ||
pluginsToInit.push(CommandsInterface) | ||
} | ||
@@ -84,0 +89,0 @@ const pluginOptions = |
@@ -56,2 +56,3 @@ import {createElement as el} from 'react' | ||
this.onPlaceholderCancel = options.onPlaceholderCancel || noop | ||
this.onCommandsChanged = options.onCommandsChanged | ||
@@ -175,2 +176,8 @@ // Listen for first render | ||
} | ||
execCommand (commandName) { | ||
if (!this.pm || !this.pm.commands || !this.pm.commands[commandName] || !this.pm.commands[commandName].exec) { | ||
throw new Error('Can not exec this commandName: ' + commandName) | ||
} | ||
this.pm.commands[commandName].exec(this.pm) | ||
} | ||
on (eventName, func) { | ||
@@ -177,0 +184,0 @@ let events = this._events[eventName] |
@@ -33,2 +33,3 @@ import {expect} from 'chai' | ||
ed.teardown() | ||
mount.parentNode.removeChild(mount) | ||
}) | ||
@@ -35,0 +36,0 @@ |
@@ -124,2 +124,3 @@ import {expect} from 'chai' | ||
ed.teardown() | ||
mount.parentNode.removeChild(mount) | ||
}) | ||
@@ -353,2 +354,3 @@ | ||
ed.teardown() | ||
mount.parentNode.removeChild(mount) | ||
}) | ||
@@ -379,2 +381,58 @@ | ||
}) | ||
describe('Command interface', function () { | ||
let mount, ed | ||
const fixture = | ||
[ {type: 'h1', html: '<h1>Title</h1>'} | ||
, {type: 'text', html: '<p><a href="moo">link</a></p>'} | ||
] | ||
afterEach(function () { | ||
ed.teardown() | ||
mount.parentNode.removeChild(mount) | ||
}) | ||
it('returns commands on mount', function (done) { | ||
mount = document.createElement('div') | ||
document.body.appendChild(mount) | ||
function onCommandsChanged (commands) { | ||
expect(commands['heading:make1']).to.equal('disabled') | ||
expect(commands['paragraph:make']).to.equal('inactive') | ||
done() | ||
} | ||
ed = new Ed( | ||
{ container: mount | ||
, initialContent: fixture | ||
, onChange: function () {} | ||
, onShareUrl: function () {} | ||
, onShareFile: function () {} | ||
, onCommandsChanged | ||
} | ||
) | ||
}) | ||
it('correctly executes command', function (done) { | ||
mount = document.createElement('div') | ||
document.body.appendChild(mount) | ||
function onMount () { | ||
ed.execCommand('paragraph:make') | ||
const content = ed.getContent() | ||
expect(content[0].type).to.equal('text') | ||
done() | ||
} | ||
ed = new Ed( | ||
{ container: mount | ||
, initialContent: fixture | ||
, onChange: function () {} | ||
, onShareUrl: function () {} | ||
, onShareFile: function () {} | ||
, onMount | ||
} | ||
) | ||
}) | ||
}) | ||
}) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6315866
85
8078
190