A non-official iOS Framework for Editor.js - block styled editor. It's purpose to make easy use of rendering and parsing of blocks.
Converts clean json blocks data like this into native views like that 👇
- 🎩 Header
- 🥑 Raw HTML
- 📷 Image
- 🖌 Delimiter
- 💌 Paragraph
- 🕸 Link
- 🌿 List
- 📋 Table block support
UITableView
rendering- Documentation on how to apply custom styles
- Documentation on how to create custom blocks
- Documentation on how to create custom renderers
Essentially the Kit is built on multiple levels of abstractions. It is pretty handy since it provides an ability to customize the behavior of rendering clean json data and adding custom blocks.
Note that the framework has a built-in protocol-oriented tools to implement your own renderers and custom blocks. These features are not documented yet, we're working on it.
For now we only support blocks rendering within a UICollectionView
out of the box. We called it EJCollectionRenderer
. That's how you gonna use it:
-
Decode your data (array of json blocks) with
EJBLockList
type (which isCodable
). -
Store decoded list somewhere in blockList variable
var blockList: EJBlockList
-
Inside of your ViewController create a
collectionView
:
lazy var collectionView = UICollectionView(frame: view.bounds, collectionViewLayout: UICollectionViewFlowLayout())
- Create a renderer:
let renderer = EJCollectionRenderer(collectionView: collectionView)
- Implement and assign data source and delegate methods.
///
extension ViewController: UICollectionViewDataSource {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return blockList.blocks.count
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return blockList.blocks[section].data.numberOfItems
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
do {
return try renderer.render(block: blockList.blocks[indexPath.section], itemIndexPath: indexPath)
}
catch {
// Ensure you won't ever get here
return UICollectionViewCell()
}
}
}
///
extension ViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
do {
return try renderer.size(forBlock: blockList.blocks[indexPath.section], itemIndexPath: indexPath, style: nil, superviewSize: collectionView.frame.size)
} catch {
return .zero
}
}
}
To run the example project, clone the repo, and run pod install
from the Example directory first.
EditorJSKit is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'EditorJSKit'
Vadim Popov - Architecture, code review
Ivan Glushko - Implementation