GithubHelp home page GithubHelp logo

lkmill / spytext Goto Github PK

View Code? Open in Web Editor NEW
3.0 6.0 1.0 490 KB

An HTML5 editor using contentEditable.

License: MIT License

JavaScript 72.52% SCSS 27.48%
html5-editor contenteditable rte rich-text-editor rich-text javascript

spytext's Introduction

Spytext - The Tiny HTML5 Editor

Spytext is an HTML5 editor, not a Rich Text Editor, weighing in at 8.6 kb.

Spytext is built contentEditable, but most browsers handle handling line breaks, new sections, backspaces, deletes, formatting etc very differently. As a result, Spytext uses it's own DOM manipulating commands (through dollr), selection management (through selektr) and DOM undo/redo (through snapback). The only parts contentEditable still handles are actual type inputs and text traversal (arrow buttons, page up, etc).

Despite all this, the entire library (including ALL dependencies) is tiny.

Demo

There is a Plunker demo at: https://embed.plnkr.co/sJNI4kVqX7VEgA0mY2UJ/

Usage

NPM

$ npm install spytext
import Spytext from 'spytext'

const spytext = new Spytext({ el: document.getElementById('#spytext-field') })

spytext.deactivate()

spytext.activate()

CDN (UMD build)

<div id='spytext-field'></div>

<script src='https://unpkg.com/[email protected]/dist/spytext.min.js'></script>

<script>
document.addEventListener('DOMContentLoaded', () => {
  const spytext = new Spytext({ el: document.getElementById('#spytext-field') })
}, false)
</script>

Functionality

  • Styling text with italic, bold, underline or strike-trough
  • Change between P, H1, H2, H3, H4, H5 and H6 blocks for text
  • Align/justify text blocks
  • Create ordered and unordered lists
  • Indent/outdent these lists and
  • Selection management
  • Undo/redo (including remembering selections positions)

Spytext is Tiny

Minified Compressed
Spytext (UMD build, all deps) 29 kb 8.6 kb

Compatibility

Quirky Without Undo Full
Chrome 9 16 18
IE N/A 9 N/A
Firefox 1 3.6 14
Safari Unknown Unknown 6
Opera Unknown Unknown 15

spytext's People

Contributors

lkmill avatar niklasgrahl avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

spytext's Issues

Non breaking active styles error

Only outputs error in console, does not break any functionality.

caught TypeError: Cannot read property 'formats' of undefined
format.active @ commands.js:507(anonymous function)
@ toolbar.js:60m.extend.each
@ jquery.js:384m.fn.m.each
@ jquery.js:136module.exports.require.extend.setActiveStyles
@ toolbar.js:52(anonymous function)
@ events.js:187

Deleting from empty section, then calling block command gets undefined rng.

This does not seem to break anything, including the undo/redo. However, the selection gets unset (user needs to click in spytext field again to continue working).

Uncaught TypeError: Cannot read property 'commonAncestorContainer' of null
module.exports.updateContained @ selectron.js:558
module.exports.update @ selectron.js:499
module.exports.restore @ selectron.js:453
block @ commands.js:122
module.exports.require.extend.command @ field.js:132
module.exports.require.extend.listCommand @ toolbar.js:90
m.event.dispatch @ jquery.js:4670
r.handle @ jquery.js:4338
selectron.js:282

Formatting algorithm is far from optimal.

When adding formatting it has a tendency of creating to many formatting (eg. <strong>) elements. When removing formatting of a perticular type it sometimes removes other types of formatting.

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.