npm start
ed
Using ProseMirror with data from the Grid API
Demo: the-grid.github.io/ed/, with fixture
The demo shows translating from ProseMirror to the the Grid API JSON and back.
purpose
ProseMirror provides a high-level schema-based interface for interacting with contenteditable
, taking care of that pain. Ed is focused on:
- Schema to translate between the Grid API data and ProseMirror doc type
- Coordinating widgets (block editors specialized by type) (example)
use
Using as a React ⚛ component
Ed exposes a React component by default.
import Ed from '@the-grid/ed'
export default class PostEditor extends React.Component {
render() {
return (
<Ed key='item-uuid' initialContent={...} onChange={...} ... />
)
}
}
Using as a stand-alone library in iframe or similar
Including dist/build.js
in your page exposes window.TheGridEd
<script src='dist/build.js'></script>
There are {mountApp, unmountApp}
helper methods
available to use like this:
var container = document.querySelector('#ed')
window.TheGridEd.mountApp(container, {
initialContent: [],
menuBar: true,
onChange: function () {
},
onShareFile: function (index) {
},
onRequestCoverUpload: function (id) {
},
onShareUrl: function ({block, url}) {
},
onPlaceholderCancel: function (id) {
},
onDropFiles: function (index, files) {
},
onDropFileOnBlock: function (id, file) {
},
onMount: function (mounted) {
window.ed = mounted
},
onCommandsChanged: function (commands) {
},
imgfloConfig: {
server: 'https://imgflo.herokuapp.com/',
key: 'key',
secret: 'secret'
},
widgetPath: './node_modules/',
coverPrefs: {
filter: false,
crop: true,
overlay: true
},
featureFlags: {
edCta: false,
edEmbed: false
}
})
ed.insertPlaceholders(index, count)
ed.updateProgress(id, metadata)
ed.setCover(id, cover)
ed.setCoverPreview(id, src)
ed.getContent()
ed.setContent(contentArray)
ed.execCommand(commandName)
Demo: ./demo/demo.js
commands
With onCommandsChanged
prop, app will get an object containing these commandName keys.
Values will be one of these strings: inactive
, active
, disabled
, flagged
.
Apps can apply formatting / editing commands with ed.execCommand(commandName)
Supported commandName
keys:
strong:toggle
em:toggle
link:toggle
paragraph:make
heading:make1
heading:make2
heading:make3
bullet_list:wrap
ordered_list:wrap
horizontal_rule:insert
lift
undo
redo
ed_upload_image
ed_add_code
ed_add_location
ed_add_userhtml
ed_add_cta
ed_add_quote
dev
server
npm start
and open http://localhost:8080/
In development mode, webpack builds and serves the targets in memory from /webpack/
Changes will trigger a browser refresh.
plugins
Plugins are ES2015 classes with 2 required methods:
constructor (ed) {}
gets a reference to the main ed
, where you can
- listen to PM events:
ed.pm.on('draw', ...)
- and set up UI:
ed.pluginContainer.appendChild(...)
teardown () {}
where all listeners and UI should be removed
widgets
Widgets are mini-editors built to edit specific media types
iframe
Run in iframe and communicate via postMessage
Example: ced - widget for code editing
native
Example: WIP
styling
- Primary: Rebass defaults and rebass-theme for global overrides
- Secondary: inlined JS
style
objects (example) - Deprecating:
require('./component-name.css')
style includes, but needed for some responsive hacks and ProseMirror overrides
code style
Feross standard checked by ESLint with npm test
or npm run lint
- no unneeded semicolons
- no trailing spaces
- single quotes
To automatically fix easy stuff like trailing whitespace: npm run lintfix
test
npm test
Karma is set up to run tests in local Chrome and Firefox.
Tests will also run in mobile platforms via BrowserStack, if you have these environment variables set up:
BROWSERSTACK_USERNAME
BROWSERSTACK_ACCESSKEY
build
npm run build
Outputs minified dist/ed.js and copies widgets defined in package.json.
deploying
npm version patch
- style tweaks, hot bug fixes
npm version minor
- adding features, backwards-compatible changes
npm version major
- removing features, non-backwards-compatible changes
These shortcuts will run tests, tag, change package version, and push changes and tags to GH.
Travis will then publish new tags to npm
and build the demo to publish to gh-pages.