1.1.7 • Published 3 years ago

styleit-api v1.1.7

Weekly downloads
403
License
MIT
Repository
github
Last release
3 years ago

StyleIt

StyleIt.js is A completely customizable for building rich text editors in the browser.

Keep the following in mind

  • StyleIt.js is an abstraction, please know that there is no UI.
  • This repo was built for study purposes.
  • Undo/Redo will come in the future

DEMO

try me

API Overview

Install

npm i styleit-api --save

Include the module in your application

import StyleIt from 'styleit-api';

StyleIt provides two working modes

ModeDescription
ToggleStyle elements with on/off functionality, like bold,underline,italic
ExtendOnly extends the currect style, font-size, color, backgorund

Basic Usage

Toggle

import StyleIt from 'styleit-api';
const styleIt = new StyleIt("editor-id");
1cont MODES = styleIt.MODES;

const underline =()=> styleIt.execCmd('text-decoration', 'underline', Modes.Toggle);
const bold =()=> styleIt.execCmd('font-weight', 'bold', MODES.Toggle);

Extend

import StyleIt from 'styleit-api';
const styleIt = new StyleIt("editor-id");
cont MODES = styleIt.MODES;

const changeColor =(color)=> styleIt.execCmd('color', color, MODES.Extend);
const changeSize =(size)=> styleIt.execCmd('font-size', size, MODES.Extend);

With Options

The textAlign, padding, margin, line-height and more property sets the horizontal alignment of text in a block level element. It must be used on a block level element (p, div, etc.)

import StyleIt from 'styleit-api';
const styleIt = new StyleIt("editor-id");
const MODES = styleIt.MODES;

const changeAlign =(align)=> styleIt.execCmd('text-align', align, MODES.Extend,{
target:'block'
});

Inspector

import StyleIt from 'styleit-api';
const styleIt = new StyleIt("editor-id");

styleIt.on("inspect",(collectedStyles) => {
// do something with the styles..
})

Format Block

Adds an HTML block-level element around the line containing the current selection.

Tags

Tag Name
H1
H2
H3
H4
H5
H6
P
PRE
ADDRESS

How to use

import StyleIt from 'styleit-api';
const styleIt = new StyleIt("editor-id");

const toggleClass = (tagName)=> styleIt.formatBlock(tagName);

Style with Tags (toggle mode)

Tag Name
B
STRONG
MARK
EM
I
S
STRIKE
DEL
U
SUB
SUP
SMALL
SUB

How to use

import StyleIt from 'styleit-api';
const styleIt = new StyleIt("editor-id");

styleIt.toggleWith("strong");

Css Class API

The Css Class API lets you create a Css class with your pre-made rules. You can pass this class to a StyleIt object and use it as a markup just like underline or bold.

How to use

import StyleIt from 'styleit-api';
const styleIt = new StyleIt("editor-id");

const toggleClass = (name)=> styleIt.toggleClass(name);

Links

How to use

import StyleIt from 'styleit-api';
const styleIt = new StyleIt("editor-id");

const createLink = () => styleIt.link({
href:'styleIt.com',
protocol:'https'
target:'_blank'
});

Links Inspector

import StyleIt from 'styleit-api';
const styleIt = new StyleIt("editor-id");

styleIt.on("inspectLink",(props) => {
// {href,protocl,target,element}
})

Save Function

import StyleIt from 'styleit-api';
const styleIt = new StyleIt("editor-id");

const contentAsJson = styleIt.save();

Load Function

import StyleIt from 'styleit-api';
const styleIt = new StyleIt("editor-id");

styleIt.load(contentAsJson);

Destroy

Will remove all StyleIt functionality.

import StyleIt from 'styleit-api';
const styleIt = new StyleIt("editor-id");

styleIt.destroy();

Contributing

All contributions are super welcome!

Home Page | Got questions?

1.1.7

3 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.1

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.0.99

4 years ago

1.0.98

4 years ago

1.0.95

4 years ago

1.0.97

4 years ago

1.0.96

4 years ago

1.0.94

4 years ago

1.0.93

4 years ago

1.0.92

4 years ago

1.0.91

4 years ago

1.0.90

4 years ago

1.0.88

4 years ago

1.0.89

4 years ago

1.0.87

4 years ago

1.0.84

4 years ago

1.0.83

4 years ago

1.0.82

4 years ago

1.0.81

4 years ago

1.0.86

4 years ago

1.0.85

4 years ago

1.0.79

4 years ago

1.0.78

4 years ago

1.0.80

4 years ago

1.0.77

4 years ago

1.0.76

4 years ago

1.0.75

4 years ago

1.0.73

4 years ago

1.0.72

4 years ago

1.0.71

4 years ago

1.0.74

4 years ago

1.0.69

4 years ago

1.0.68

4 years ago

1.0.66

4 years ago

1.0.65

4 years ago

1.0.64

4 years ago

1.0.67

4 years ago

1.0.62

4 years ago

1.0.63

4 years ago

1.0.61

4 years ago

1.0.60

4 years ago

1.0.59

4 years ago

1.0.58

4 years ago

1.0.57

4 years ago

1.0.56

4 years ago

1.0.55

4 years ago

1.0.49

4 years ago

1.0.51

4 years ago

1.0.50

4 years ago

1.0.54

4 years ago

1.0.53

4 years ago

1.0.52

4 years ago

1.0.48

4 years ago

1.0.44

4 years ago

1.0.43

4 years ago

1.0.42

4 years ago

1.0.47

4 years ago

1.0.46

4 years ago

1.0.45

4 years ago

1.0.39

4 years ago

1.0.40

4 years ago

1.0.41

4 years ago

1.0.38

4 years ago

1.0.37

4 years ago

1.0.36

4 years ago

1.0.35

4 years ago

1.0.34

4 years ago

1.0.33

4 years ago

1.0.32

4 years ago

1.0.31

4 years ago

1.0.29

4 years ago

1.0.28

4 years ago

1.0.30

4 years ago

1.0.27

4 years ago

1.0.26

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.23

4 years ago

1.0.22

4 years ago

1.0.21

4 years ago

1.0.20

4 years ago

1.0.19

4 years ago

1.0.18

4 years ago

1.0.17

5 years ago

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.1.0

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago