1.1.7 • Published 2 years ago

styleit-api v1.1.7

Weekly downloads
403
License
MIT
Repository
github
Last release
2 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

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

3 years ago

1.1.1

3 years ago

1.1.3

3 years ago

1.1.2

3 years ago

1.0.99

3 years ago

1.0.98

3 years ago

1.0.95

3 years ago

1.0.97

3 years ago

1.0.96

3 years ago

1.0.94

3 years ago

1.0.93

3 years ago

1.0.92

3 years ago

1.0.91

3 years ago

1.0.90

3 years ago

1.0.88

3 years ago

1.0.89

3 years ago

1.0.87

3 years ago

1.0.84

3 years ago

1.0.83

3 years ago

1.0.82

3 years ago

1.0.81

3 years ago

1.0.86

3 years ago

1.0.85

3 years ago

1.0.79

3 years ago

1.0.78

3 years ago

1.0.80

3 years ago

1.0.77

3 years ago

1.0.76

3 years ago

1.0.75

3 years ago

1.0.73

3 years ago

1.0.72

3 years ago

1.0.71

3 years ago

1.0.74

3 years ago

1.0.69

3 years ago

1.0.68

3 years ago

1.0.66

3 years ago

1.0.65

3 years ago

1.0.64

3 years ago

1.0.67

3 years ago

1.0.62

3 years ago

1.0.63

3 years ago

1.0.61

3 years ago

1.0.60

3 years ago

1.0.59

3 years ago

1.0.58

3 years ago

1.0.57

3 years ago

1.0.56

3 years ago

1.0.55

3 years ago

1.0.49

3 years ago

1.0.51

3 years ago

1.0.50

3 years ago

1.0.54

3 years ago

1.0.53

3 years ago

1.0.52

3 years ago

1.0.48

3 years ago

1.0.44

3 years ago

1.0.43

3 years ago

1.0.42

3 years ago

1.0.47

3 years ago

1.0.46

3 years ago

1.0.45

3 years ago

1.0.39

3 years ago

1.0.40

3 years ago

1.0.41

3 years ago

1.0.38

3 years ago

1.0.37

3 years ago

1.0.36

3 years ago

1.0.35

3 years ago

1.0.34

3 years ago

1.0.33

3 years ago

1.0.32

3 years ago

1.0.31

3 years ago

1.0.29

3 years ago

1.0.28

3 years ago

1.0.30

3 years ago

1.0.27

3 years ago

1.0.26

3 years ago

1.0.25

3 years ago

1.0.24

3 years ago

1.0.23

3 years ago

1.0.22

3 years ago

1.0.21

3 years ago

1.0.20

3 years ago

1.0.19

3 years ago

1.0.18

3 years ago

1.0.17

3 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.12

3 years ago

1.0.11

4 years ago

1.1.0

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago