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

@the-grid/ed

Package Overview
Dependencies
Maintainers
18
Versions
138
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@the-grid/ed - npm Package Compare versions

Comparing version 0.9.3 to 0.10.0

src/plugins/commands-interface.js

5

CHANGES.md
## 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 @@

4

demo/demo.js

@@ -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

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