Giter Site home page Giter Site logo

plarson / richeditorview-swift Goto Github PK

View Code? Open in Web Editor NEW

This project forked from andrew-chen-wang/richeditorview

0.0 0.0 0.0 15.85 MB

Rich Text Editor in Swift. Newly Featured Code and Swift 5 compatible of cjwirth/RichEditorView.

License: BSD 3-Clause "New" or "Revised" License

JavaScript 25.83% CSS 2.44% Swift 69.76% HTML 1.97%

richeditorview-swift's Introduction

RichEditorView

This is the Swift 5 version of cjwirth/RichEditorView using WKWebView that added several awesome functionalities.

Table of Contents:

  • Usage Instructions
  • Added Features
  • Credits and License

Usage Instructions:

You can use SPM to install this package. If you're using Pods or Carthage, since I haven't created a package for those yet, you'll need to do this manually.

  1. In order to import the RichEditorView package, you need to create a new group/folder by going to the bottom left of XCode and clicking on the + button. Create a new group called RichEditorView.
  2. Then, manually create new files and copy and paste accordingly from the RichEditorView directory in the source code. There is currently no plan to go to CocoaPods or Carthage or any other package manager.
  3. For resources, if you download this repository via ZIP and then unzip the file, you can right click on YOUR newly created Resources directory and selecting "Add Files to" then select the Resource files from the unzipped package. DO NOT USE Assets!!!

Added Features:

Most features are the same from the parent repo, but I have added some other functionalities and some directions in the sample. Other features can be found in cjwirth's repo.

The following edited features assumes you have a property let editorView = RichEditorView()

  1. You can get selected text by doing editorView.getSelectedText
  2. runJS and other functions in the RichEditorView does NOT work like cjwirth's. This is due to the JavaScript bridging for WKWebView; unlike WK, UIWebView had a string be returned. In order to run JavaScript and other functionalities return Void, you must do the following:
editorView.getSelectedText() { r in
    // r is just a variable.
}

or

editorView.runJS("document.getElementById('editor')") { r in 
    print(r)
}

NOTE That these might run asynchronously. This might be due to WKWebView's memory efficiency feature. Don't quote me on that though, since I'm not too sure if that's true. Just an observation. This is because the function is: public func getSelectedText(handler: @escaping (String) -> Void). Notice the (String) -> Void. The variable r is the string value returned by JavaScript.

  1. The insertLink functionality has also changed. Normal tags in HTML are layed out like this: <a href="https://github.com/" title="GitHub">The TEXT that user sees</a>. When you insert a link, the following arguments are required: href and text. If there is a range selection, the text in the range selection will be cleared!
  2. Dark mode is included via the CSS and HTML files.

Credits and License

License is under BSD-3 Clause

cjwirth - Original iOS-RichEditorView Creator

C. Bess - WKWebView Support

YoomamaFTW - Repository Maintainer

Andrew-Chen-Wang - Repository Maintainer

richeditorview-swift's People

Contributors

yoomamaftw avatar andrew-chen-wang avatar plarson avatar leeonardoo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.