🔰 Seule is a light-weight (19.3KB), blazing fast and feature-rich Javascript Framework. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers 🧙♂.
You can create an index.html file and include Seule with:
npm i seule --save
🔹 At the core of Seule.js is a system that enables us to declaratively render data to the DOM using straightforward template syntax:
<div id='app'>
{{message}}
</div>
import {Instance} from "seule";
new Instance({
el: '#app',
data: {
message : 'hello Seule'
}
})
We have already created Hello World Seule app! Click on the "Quick Start" 👆 button to see how it works.
Seule uses Shadow DOM, It allows us to ship self contained components along with their style and isolate the component from global style while "protecting" the host application from styles defined inside the component.
there are two ways of inserting a style sheet:
- Using _Css Method
- Adding Style property (only for components)
To use _Css Method, it should be included from the Model Module.
<div id='app'></div>
import css from "./assets/css/app.css";
import {Instance} from "seule";
import {_Css} from "seule/model";
new Instance({
el: '#app',
data: {
message : 'hello Seule'
},
async handlers($app){
_Css(css, $app);
}
})
To use _Css Method, it should be included from the Model Module.
🔹 you can add css to your application just by passing it into the style property.
import css from "./assets/css/app.css";
import {Instance} from "seule";
const app = new Seule({
el: '#app',
style: css,
data:{
message: "Hello World"
}
})
In addition to text interpolation, we can also bind element attributes like this:
<element data-attribute="[attribute: <String>]:[variable: <String>]"></element>
<div id='app'>
<p data-attribute="title:message"> Hover your mouse over me <br> for a few seconds </p>
</div>
import {Instance} from "seule";
new Instance({
el: '#app',
data: {
message : 'You visited this page on ' + new Date().toLocaleString()
}
})
Magic Happens here by invoking Methods inside the handlers(), using one parameter $app and let users interact with your app
<div id='app'>
<p>{{message}}</p>
<button>click-me</button>
</div>
import {Instance} from "seule";
import {Scope} from "seule/selectors";
new Instance({
el: '#app',
data:{message: "Hello my Friend"},
async handlers($app){
const scope = Scope($app);
scope.Native(e=>{
const btn = e.querySelector("button");
btn.addEventListener("click", ()=>
$app.data.message = $app.data.message.split('').reverse().join(''));
});
}
});
For more security, Seule uses Shadow DOM. The problem in that, is you can't get access to the DOM element(s) directly unless you use Css selectors inside the handlers() by invoking the Scoop Method.
Scope Method can accept one argument.
Scope Method has a function call Select returns all elements in the Seule app that matches a specified CSS selector(s), as a static Seule Object.
Scope([Seule_component])
Scope([Seule_component]).Select([CSS_selectors])
Parameter --> CSS selectors
Type --> String
Tip: For a list of all CSS Selectors, look at w3schools !CSS Selectors Reference
🔹 You can select all <p> elements on app like this:
Scope($app).Select("p")
When a user clicks on a button, all <p> elements will be hidden:
<div id='app'>
<p>{{message}} 1</p>
<p>{{message}} 2</p>
<p>{{message}} 3</p>
<button title="{{title}}">Hide All!</button>
</div>
import {Instance} from "seule";
import {Scope} from "seule/selectors";
import {Effects} from "seule/effects";
import {Events} from "seule/events";
new Instance({
el: '#app',
data:{message: "Hello my Friend"},
modules:{Effects, Events},
async handlers($app){
const
scope = Scope($app),
btn = scope.Select("button"),
p = scope.Select("p");
btn.Click(()=> p.Hide());
}
});
What is an Event?
An event represents the precise moment when something happens. Examples:
- moving a mouse over an element
- selecting a radio button
- clicking on an element
for mor details about !Event reference
Before using Events in Seule, we have to import the Events method from the events module and call it into the main component Single.
import {Instance} from "seule";
import {Events} from "seule/events";
new Instance({
el: '#app',
modules:{Events}
});
using the On Method to assign an event to an element.
Select([CSS selectors]).On([event:<String>], [handler:<Function>])
🔹 for exemple To assign a click event to all button on a Seule app, you can do this:
<div id='app'>
<img src="https://bit.ly/3mA0FbG" width="150">
<button>Change the picture</button>
<p>{{message}}</p>
</div>
import {Instance} from "seule";
import {Scope} from "seule/selectors";
import {Events} from "seule/events";
new Instance({
el: '#app',
data:{
message: "Click the button to see what happens!",
source: "https://bit.ly/3mA0FbG"
},
modules:{Events},
async handlers($app){
const
scope = Scope($app),
btn = scope.Select("button");
btn.On("click",()=> $app.data.source = "https://bit.ly/3Jb61VN"); }
});
The function is executed when the user clicks on the HTML element.
🔹 For example When a click event fires on an element show an alert box.
Select("button")
.Click(()=> alert('just a simple click'))
The function is executed when the user make a long presse on the HTML element.
Select([CSS selectors]).Hold([handler:<Function>], [time:<Integer>])
the time by default is 1500 => 1.5s
🔹 Show an alert box When user make a long presse on button for 3s.
<div id='app'>
<button>Hold Me for 3s</button>
</div>
import {Instance} from "seule";
import {Scope} from "seule/selectors";
import {Events} from "seule/events";
new Instance({
el: '#app',
data:{
message: "Click the button to see what happens!",
source: "https://bit.ly/3mA0FbG"
},
modules:{Events},
async handlers($app){
const
scope = Scope($app),
btn = scope.Select("button");
btn.Hold(()=> alert('Good Job!™ 🤩'), 1000);
}
});
Detecting a swipe (left, right, top or down) When a swipe event fires on an element.
Select([CSS selectors]).Swipe([event:<String>], [handler:<Function>])
- left
- right
- top
- bottom
🔹 Change the background When user swipe left 🤚 on screen
<div id='app'>
<p data-attribute="title:tooltip">{{message}}</p>
</div>
import {Instance} from "seule";
import {Hoisting} from "seule/selectors";
import {Events} from "seule/events";
import {Effects} from "seule/effects";
new Instance({
el: '#app',
data:{
message: "Swipe left to see what happens!",
tooltip : "See this demo on Mobile"
},
modules:{Events, Effects},
async handlers($app){
const body = Hoisting("body");
body.Swipe("left", e=> e
.Css('background')
.set = '#fed000');
}
});
The focus event occurs when an element gets focus (when selected by a mouse click or by "tab-navigating" to it).
The Focus() method triggers the focus event, or attaches a function to run when a focus event occurs.
Trigger the focus event for selected elements:
Select([CSS selectors]).Focus()
Attach a function to the focus event:
Select([CSS selectors]).Focus([handler:<Function>])
🔹 Attach a function to the focus event. The focus event occurs when the <input> field gets focus:
<div id='app'>
<input placeholder="Focus on me!" type="text">
<p>{{message}}</p>
</div>
import {Instance} from "seule";
import {Scope} from "seule/selectors";
import {Events} from "seule/events";
import {HtmlMethods} from "seule/htmlMethods";
new Instance({
el: '#app',
data: {
message: "Click in the input field to see what happens!"
},
modules:{Events, HtmlMethods},
async handlers($app){
const
scope = Scope($app),
input = scope.Select("input");
input
.Focus(e =>
e.Val().set = "Great work keep it up!");
}
})
The blur event occurs when an element loses focus.
The Blur() method triggers the blur event, or attaches a function to run when a blur event occurs.
Trigger the blur event for the selected elements:
Select([CSS selectors]).Blur()
Attach a function to the focus event:
Select([CSS selectors]).Blur([handler:<Function>])
🔹 Attach a function to the blur event. The blur event occurs when the <input> field loses focus:
<div id='app'>
<input placeholder="Write something!" type="text">
<p>{{message}}</p>
</div>
import {Instance} from "seule";
import {Scope} from "seule/selectors";
import {Events} from "seule/events";
import {HtmlMethods} from "seule/htmlMethods";
new Instance({
el: '#app',
data: {
message: "Click outside the field to lose focus (blur)."
},
modules:{Events, HtmlMethods},
async handlers($app){
const
scope = Scope($app),
input = scope.Select("input"),
p = scope.Select("p");
input
.Blur(() =>
p.Text().set = "This input field has lost its focus!");
}
});
With HotKey Method in Seule you can now handling keyboard shortcuts easly.
Select([CSS selectors]).Hotkey([keys:<String>], [handler:<Function>], [prevent:<Boolean>]);
For modifier keys you can use shift
, ctrl
, alt
or meta
You can substitute option
for alt
and command
for meta
Other special keys are backspace
, tab
, enter
, return
, capslock
, esc
, escape
, space
, pageup
, pagedown
, end
, home
, left
, up
, right
, down
, ins
, del
, and plus
Any other key you should be able to reference by name like a
, /
, $
, *
, or =
.
🔹 Hotkey event with Single key:
Select('input').HotKey('m',
()=> alert('M button is pressed on the Keyboard!'));
🔹 Combination of keys:
Select('input').HotKey('ctrl s',
()=> alert('You pressed ctrl+s!'));
🔹 Sequence of keys like Konami Style (:
Select('input').HotKey('Left Right Left Right A C',
()=> alert('Now you can play with Orochi Iori'));
🔹 Or you can specify keyboard events that will work anywhere including inside textarea/input fields like:
import {Instance} from "seule";
import {Hoisting} from "seule/selectors";
import {Events} from "seule/events"
new Instance({
el: '#app',
data: {
message: "Click outside the field to lose focus (blur)."
},
modules:{Events},
async handlers(){
const
wn = Hoisting("body");
wn.HotKey('ctrl r',
()=> alert('Global keyboard shortcuts'));
// if you want prevent the default refresh event under WINDOWS system
wn.HotKey('ctrl r',
()=> alert('Global keyboard shortcuts'), true);
}
});
There are so many things helpful in Seule like :
Do you want to simulate event with a single statement? Then you may use Fire Method for that:
Select([CSS selectors]).Fire([event:<String>]);
Simulate a mouse-click when moving the mouse pointer over a button:
<div id='app'>
<button onclick="alert('Clicked !')">Hover Me !</button>
</div>
import {Instance} from "./seule";
import {Scope} from "./seule/selectors";
import {Events} from "./seule/events";
new Instance({
el: '#app',
modules:{Events},
async handlers($app){
const
scope = Scope($app),
btn = scope.Select("button");
btn.On('mouseover', e=> e.Fire("click"))
}
});