eyjs 8.0.0 → 8.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/readme.md CHANGED
@@ -1,213 +1,213 @@
1
- # Eye.js
2
- Fasten your production and unleash the power of `eye` or `e`, manipulate DOM elements with ease while keeping your code organized and well readable.
3
-
4
- yeap that's me! [@yousef_neji](https://github.com/yousef312)
5
-
6
- ## CHANGELOG
7
-
8
- Check changelog for more informations
9
- [check](/changelog.md)
10
-
11
- ## How to?
12
- Import first
13
-
14
- ```JavaScript
15
- // commonjs
16
- var e = require('eyjs');
17
-
18
- // ESM
19
- import e from "eyjs";
20
- ```
21
-
22
- Selecting an element
23
- ```JavaScript
24
- // div id="bar"
25
- let bar = e("div#bar");
26
- // all spans with class="list-item"
27
- let listItem = e("span.list-item");
28
- // all elements with class ".fools"
29
- let fools = e(".fools");
30
- // using ! only return the first occurence
31
- let firstButton = e(".btns!");
32
- ```
33
-
34
- Creating elements
35
- ```JavaScript
36
- let baron = e("<div>",{
37
- text: "leave",
38
- parent: bar,
39
- class: "btn button_dark", // also accepts array for multiple class setting at once or string concatenation of them with spaces between
40
- data: { // setting dataset values
41
- index: 12,
42
- manMap: "off"
43
- }
44
- },{
45
- backgroundColor: "red",
46
- color: "white"
47
- })
48
- ```
49
-
50
- Extra functionalities
51
- ```JavaScript
52
- // the most amazing functionalities is that u can chain calls
53
- baron
54
- .hide() // display: none
55
- .show(customStyle); // display: inline-block or custom style
56
-
57
- baron
58
- .data("name","yousef neji"), // more powerfull than dataset, using WeakMaps!
59
- .data("name"); // deleting a key
60
-
61
- baron.attr("contentEditable","true"); // manipulating atributes
62
- baron.attr("style",false); // `false` will remove the attribute `style`
63
- baron.rAttr("style"); // or you could simply use rAttr
64
- baron.attr("data-index"); // setting or getting dataset values
65
-
66
- baron.on("click",cb); // events handling
67
- baron.delegate("click",".body", cb); // events delegation
68
- baron.click(cb); // triggering or handling events
69
-
70
- baron.child(0); // getting child number 0
71
- baron.childlen // getting children length
72
-
73
- baron.client("width") // get client specific informations "width" "height" "left" or "top"
74
- ```
75
-
76
- ## Redefine set/get features of .text and .val
77
-
78
- You can modify the way you use `.text` and `.val` using `.redefine`
79
-
80
- ```JavaScript
81
- let customInp = e('div',{ class: "custom-inp", parent: form });
82
-
83
- customInp.redefine("text",(action, value, elm)=>{
84
- if(action == "set"){
85
- return value.join(" || ");
86
- } else if(action === "get") {
87
- return value.split(" || ");
88
- }
89
- })
90
- ```
91
-
92
- ## Serializing form elements fn `.serialize`( param : opts )
93
-
94
- Serializing is transcoding form inputs data into an appropriate string format that you can send over the network to the server.
95
-
96
- The function will select all sub inputs, select, textarea elements and return their values, in order to narrow the selection you can pre-define the inputs you want to select in `opts.inputs`, which also offers `custom-input` & `custom-getter` as follow:
97
- - `custom-inputs`: When your form contains custom inputs(div with special input features for example), you define them in the `opts.inputs` by a selector like `.special-input`, `#specialinp`... etc.
98
- - `custom-getters`: the naming convention is only for explainatory purpose, this feature basically nameless, It's the ability to provide a custom way to subtract the data of certain input/custom, by defining a function with the name of that input/custom, here's how u do it:
99
- - `opts.[fieldname]`: (inp) => inp.child(0).val();
100
-
101
- ```html
102
- <form class="createUser">
103
- <input type="text" name="username">
104
- <input type="password" name="password">
105
- <div data-name="hooby" class="custom-input" contentEditable>
106
- user hobbies:
107
- <div class="list">
108
- <span>singing</span>
109
- <span>dancing</span>
110
- <span>writing</span>
111
- </div>
112
- </div>
113
- <button>submit</button>
114
- </form>
115
- ```
116
- ```javascript
117
- let form = e('form.createUser');
118
-
119
- let opts = {
120
- // optionally identify the inputs to serialize adding custom inputs
121
- inputs: ['input','select','.custom-input'],
122
- hobby: (inp)=>{
123
- let v = [];
124
- // this will select the custom-input .list>span spans
125
- // get their values and push it into `v` array.
126
- e(inp.find(".list>span")).each(span => v.push(span.textContext));
127
- // then return the value as string by joining it using ','
128
- return v.join(',');
129
- }
130
- }
131
-
132
- let data = form.serialize(opts);
133
- // send data over network using jcall/fetch/axios ...
134
- ```
135
-
136
- ## `~Models~`
137
-
138
- - **description**: models used to create elements similar to react components except easier to manager, you can create basic blueprint using `e("model:youModelName", blueprint)`, later on, you use the returned constructor over and over when ever the need calls!
139
- - **how it works**:
140
- - include the "model:\_model_name\_".
141
- - define your `blueprint`:
142
- - a `blueprint` is an object containing nested objects that defines each component of your model,
143
- - a `blueprint` element is formed by
144
-
145
- [`tagname`.`classname1`.`classname2`: `_index - default_value`],
146
-
147
- where `_index`(must contain the `_`) represent a datacell to display data later, and `default_value` will be set if no data passed.
148
- - **Usuage**:
149
- ```javascript
150
- let failMessage = e("model:FailMessage", {
151
- "div.head": {
152
- "div.title: _title - Big Fancy Title": {},
153
- "div.close": {}
154
- },
155
- "div.body": {
156
- "p.message: _message - no message": {},
157
- "div.details: _details - no details": {},
158
- "div.actions": {
159
- "button.ok: _ok - OK": {},
160
- "button.cancel: _cancel - Cancel": {}
161
- }
162
- }
163
- })
164
-
165
- // do ajax stuff
166
- fetch()
167
- .then()
168
- .catch((e)=>{
169
- // create a new instance
170
- let error = failMessage({
171
- parent: document.body // append using parent attribute
172
- _title: "Backend error - " + e.name,
173
- _message: e.message,
174
-
175
- // try to avoid using this attribute unless
176
- // you want to mess up with your model
177
- // text: "some text",
178
- // html: "some html",
179
- });
180
- // or append later
181
- error.appendTo(document.body);
182
- // you may pre-create the error in earlier stage! before the fetch()
183
- // and refresh it content using .refresh function
184
- error.refresh({
185
- _title: "Backend error - " + e.name,
186
- _message: e.message
187
- })
188
- // refresh also accepts an attribute `default`(set true by default)
189
- // which adjut whether to update all datacells of the model
190
- // or only update the one passed through the function
191
- // EXAMPLE:
192
- error.refresh({
193
- _title: "Other Error - " + e.name
194
- })
195
- // this will update _title to the new value and also update
196
- // the other datacells like `_message` `_details` ...
197
- // but since they're not passed they will display the default values
198
- // from the constructor up at the top!
199
- // `_message` => no message
200
- // `_details` => no details
201
- // ...
202
- // unless you passed (default: false)
203
- error.refresh({
204
- _title: "Other error - " + e.name,
205
- default: true
206
- })
207
- // in this case only _title will be changed!
208
- })
209
- ```
210
-
211
-
212
- ## Copyrights
213
- Reserved under MIT license
1
+ # Eye.js
2
+ Fasten your production and unleash the power of `eye` or `e`, manipulate DOM elements with ease while keeping your code organized and well readable.
3
+
4
+ yeap that's me! [@yousef_neji](https://github.com/yousef312)
5
+
6
+ ## CHANGELOG
7
+
8
+ Check changelog for more informations
9
+ [check](/changelog.md)
10
+
11
+ ## How to?
12
+ Import first
13
+
14
+ ```JavaScript
15
+ // commonjs
16
+ var e = require('eyjs');
17
+
18
+ // ESM
19
+ import e from "eyjs";
20
+ ```
21
+
22
+ Selecting an element
23
+ ```JavaScript
24
+ // div id="bar"
25
+ let bar = e("div#bar");
26
+ // all spans with class="list-item"
27
+ let listItem = e("span.list-item");
28
+ // all elements with class ".fools"
29
+ let fools = e(".fools");
30
+ // using ! only return the first occurence
31
+ let firstButton = e(".btns!");
32
+ ```
33
+
34
+ Creating elements
35
+ ```JavaScript
36
+ let baron = e("<div>",{
37
+ text: "leave",
38
+ parent: bar,
39
+ class: "btn button_dark", // also accepts array for multiple class setting at once or string concatenation of them with spaces between
40
+ data: { // setting dataset values
41
+ index: 12,
42
+ manMap: "off"
43
+ }
44
+ },{
45
+ backgroundColor: "red",
46
+ color: "white"
47
+ })
48
+ ```
49
+
50
+ Extra functionalities
51
+ ```JavaScript
52
+ // the most amazing functionalities is that u can chain calls
53
+ baron
54
+ .hide() // display: none
55
+ .show(customStyle); // display: inline-block or custom style
56
+
57
+ baron
58
+ .data("name","yousef neji"), // more powerfull than dataset, using WeakMaps!
59
+ .data("name"); // deleting a key
60
+
61
+ baron.attr("contentEditable","true"); // manipulating atributes
62
+ baron.attr("style",false); // `false` will remove the attribute `style`
63
+ baron.rAttr("style"); // or you could simply use rAttr
64
+ baron.attr("data-index"); // setting or getting dataset values
65
+
66
+ baron.on("click",cb); // events handling
67
+ baron.delegate("click",".body", cb); // events delegation
68
+ baron.click(cb); // triggering or handling events
69
+
70
+ baron.child(0); // getting child number 0
71
+ baron.childlen // getting children length
72
+
73
+ baron.client("width") // get client specific informations "width" "height" "left" or "top"
74
+ ```
75
+
76
+ ## Redefine set/get features of .text and .val
77
+
78
+ You can modify the way you use `.text` and `.val` using `.redefine`
79
+
80
+ ```JavaScript
81
+ let customInp = e('div',{ class: "custom-inp", parent: form });
82
+
83
+ customInp.redefine("text",(action, value, elm)=>{
84
+ if(action == "set"){
85
+ return value.join(" || ");
86
+ } else if(action === "get") {
87
+ return value.split(" || ");
88
+ }
89
+ })
90
+ ```
91
+
92
+ ## Serializing form elements fn `.serialize`( param : opts )
93
+
94
+ Serializing is transcoding form inputs data into an appropriate string format that you can send over the network to the server.
95
+
96
+ The function will select all sub inputs, select, textarea elements and return their values, in order to narrow the selection you can pre-define the inputs you want to select in `opts.inputs`, which also offers `custom-input` & `custom-getter` as follow:
97
+ - `custom-inputs`: When your form contains custom inputs(div with special input features for example), you define them in the `opts.inputs` by a selector like `.special-input`, `#specialinp`... etc.
98
+ - `custom-getters`: the naming convention is only for explainatory purpose, this feature basically nameless, It's the ability to provide a custom way to subtract the data of certain input/custom, by defining a function with the name of that input/custom, here's how u do it:
99
+ - `opts.[fieldname]`: (inp) => inp.child(0).val();
100
+
101
+ ```html
102
+ <form class="createUser">
103
+ <input type="text" name="username">
104
+ <input type="password" name="password">
105
+ <div data-name="hooby" class="custom-input" contentEditable>
106
+ user hobbies:
107
+ <div class="list">
108
+ <span>singing</span>
109
+ <span>dancing</span>
110
+ <span>writing</span>
111
+ </div>
112
+ </div>
113
+ <button>submit</button>
114
+ </form>
115
+ ```
116
+ ```javascript
117
+ let form = e('form.createUser');
118
+
119
+ let opts = {
120
+ // optionally identify the inputs to serialize adding custom inputs
121
+ inputs: ['input','select','.custom-input'],
122
+ hobby: (inp)=>{
123
+ let v = [];
124
+ // this will select the custom-input .list>span spans
125
+ // get their values and push it into `v` array.
126
+ e(inp.find(".list>span")).each(span => v.push(span.textContext));
127
+ // then return the value as string by joining it using ','
128
+ return v.join(',');
129
+ }
130
+ }
131
+
132
+ let data = form.serialize(opts);
133
+ // send data over network using jcall/fetch/axios ...
134
+ ```
135
+
136
+ ## `~Models~`
137
+
138
+ - **description**: models used to create elements similar to react components except easier to manager, you can create basic blueprint using `e("model:youModelName", blueprint)`, later on, you use the returned constructor over and over when ever the need calls!
139
+ - **how it works**:
140
+ - include the "model:\_model_name\_".
141
+ - define your `blueprint`:
142
+ - a `blueprint` is an object containing nested objects that defines each component of your model,
143
+ - a `blueprint` element is formed by
144
+
145
+ [`tagname`.`classname1`.`classname2`: `_index - default_value`],
146
+
147
+ where `_index`(must contain the `_`) represent a datacell to display data later, and `default_value` will be set if no data passed.
148
+ - **Usuage**:
149
+ ```javascript
150
+ let failMessage = e("model:FailMessage", {
151
+ "div.head": {
152
+ "div.title: _title - Big Fancy Title": {},
153
+ "div.close": {}
154
+ },
155
+ "div.body": {
156
+ "p.message: _message - no message": {},
157
+ "div.details: _details - no details": {},
158
+ "div.actions": {
159
+ "button.ok: _ok - OK": {},
160
+ "button.cancel: _cancel - Cancel": {}
161
+ }
162
+ }
163
+ })
164
+
165
+ // do ajax stuff
166
+ fetch()
167
+ .then()
168
+ .catch((e)=>{
169
+ // create a new instance
170
+ let error = failMessage({
171
+ parent: document.body // append using parent attribute
172
+ _title: "Backend error - " + e.name,
173
+ _message: e.message,
174
+
175
+ // try to avoid using this attribute unless
176
+ // you want to mess up with your model
177
+ // text: "some text",
178
+ // html: "some html",
179
+ });
180
+ // or append later
181
+ error.appendTo(document.body);
182
+ // you may pre-create the error in earlier stage! before the fetch()
183
+ // and refresh it content using .refresh function
184
+ error.refresh({
185
+ _title: "Backend error - " + e.name,
186
+ _message: e.message
187
+ })
188
+ // refresh also accepts an attribute `default`(set true by default)
189
+ // which adjut whether to update all datacells of the model
190
+ // or only update the one passed through the function
191
+ // EXAMPLE:
192
+ error.refresh({
193
+ _title: "Other Error - " + e.name
194
+ })
195
+ // this will update _title to the new value and also update
196
+ // the other datacells like `_message` `_details` ...
197
+ // but since they're not passed they will display the default values
198
+ // from the constructor up at the top!
199
+ // `_message` => no message
200
+ // `_details` => no details
201
+ // ...
202
+ // unless you passed (default: false)
203
+ error.refresh({
204
+ _title: "Other error - " + e.name,
205
+ default: true
206
+ })
207
+ // in this case only _title will be changed!
208
+ })
209
+ ```
210
+
211
+
212
+ ## Copyrights
213
+ Reserved under MIT license
package/rollup.config.mjs CHANGED
@@ -1,38 +1,38 @@
1
- import resolve from '@rollup/plugin-node-resolve';
2
- import commonjs from '@rollup/plugin-commonjs';
3
- import terser from '@rollup/plugin-terser';
4
-
5
- export default [
6
- {
7
- input: 'src/eye.js',
8
- output: [
9
- {
10
- file: 'dist/eye.umd.js',
11
- format: 'umd',
12
- name: 'eye',
13
- sourcemap: true,
14
- },
15
- {
16
- file: 'dist/eye.umd.min.js',
17
- format: 'umd',
18
- name: 'eye',
19
- plugins: [terser()],
20
- sourcemap: true,
21
- },
22
- {
23
- file: 'dist/eye.esm.js',
24
- format: 'es',
25
- sourcemap: true,
26
- },
27
- {
28
- file: 'dist/eye.cjs.js',
29
- format: 'cjs',
30
- sourcemap: true,
31
- }
32
- ],
33
- plugins: [
34
- resolve(),
35
- commonjs()
36
- ]
37
- }
1
+ import resolve from '@rollup/plugin-node-resolve';
2
+ import commonjs from '@rollup/plugin-commonjs';
3
+ import terser from '@rollup/plugin-terser';
4
+
5
+ export default [
6
+ {
7
+ input: 'src/eye.js',
8
+ output: [
9
+ {
10
+ file: 'dist/eye.umd.js',
11
+ format: 'umd',
12
+ name: 'eye',
13
+ sourcemap: true,
14
+ },
15
+ {
16
+ file: 'dist/eye.umd.min.js',
17
+ format: 'umd',
18
+ name: 'eye',
19
+ plugins: [terser()],
20
+ sourcemap: true,
21
+ },
22
+ {
23
+ file: 'dist/eye.esm.js',
24
+ format: 'es',
25
+ sourcemap: true,
26
+ },
27
+ {
28
+ file: 'dist/eye.cjs.js',
29
+ format: 'cjs',
30
+ sourcemap: true,
31
+ }
32
+ ],
33
+ plugins: [
34
+ resolve(),
35
+ commonjs()
36
+ ]
37
+ }
38
38
  ];