neobiz 4.7.2 → 5.0.1

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_v4.md ADDED
@@ -0,0 +1,735 @@
1
+ <!-- @format -->
2
+
3
+ # Documentation Neobiz.js 5.0.x
4
+
5
+ > A simple view engine that has 100% JS features
6
+
7
+ Neobiz.js is pure in JS lang, transform Object into HTML
8
+
9
+ fix error `outFIle`
10
+
11
+ ## Updates:
12
+
13
+ - fix event bugs
14
+ - Boolean attributes / non-value attribute (example: disabled, readonly)
15
+
16
+ ## prev update:
17
+
18
+ - `render` method change to `**\_render**`to avoid conflict with another library and add safety check
19
+ - render option props improve
20
+ - fix bug on child order
21
+
22
+ features:
23
+
24
+ - eventHandler
25
+ - Reusable & editable style/css
26
+ - Altering object
27
+ - Registering component
28
+ - Explicit tag name supported
29
+
30
+ `read /example dir to better understanding`
31
+
32
+ for browser usage use `browser.js` file.
33
+
34
+ [link to usage in express.js](https://www.npmjs.com/package/neobiz-express?activeTab=dependencies)
35
+
36
+ ---
37
+
38
+ ## Example with `vue` in browser
39
+
40
+ page.js
41
+
42
+ ```js
43
+ import "neobiz";
44
+
45
+ ({
46
+ div: {
47
+ script: [
48
+ { src: "https://unpkg.com/vue@3/dist/vue.global.js" },
49
+ { src: "https://unpkg.com/neobiz@3.1.0/browser.js" },
50
+ { src: "./my-component.js" },
51
+ ],
52
+ id: "app",
53
+ },
54
+ script: {
55
+ html() {
56
+ const { createApp } = Vue;
57
+
58
+ createApp(myComponent).mount("#app");
59
+ },
60
+ },
61
+ }).outFile("./welcome.html");
62
+ ```
63
+
64
+ my-component.js
65
+
66
+ ```js
67
+ const myComponent = {
68
+ data() {
69
+ return { msg: "hi, this is example" };
70
+ },
71
+ template: { h1: { text: "{{msg}}" } }._render,
72
+ };
73
+ ```
74
+
75
+ <br>
76
+
77
+ | properties | caller | return-type | description |
78
+ | -------------- | ------------------------------------- | ----------- | --------------------------------------- |
79
+ | \_render | Object | string | rendering to HTML |
80
+ | outFile | Object @params destination[string] | void | generate static HTML file |
81
+ | range | Array @params length[int], start[int] | Array | shortcut for looping in a range |
82
+ | repulse | String | Object | generate object from HTML string |
83
+ | css | Object | Object | generate css from object |
84
+ | cssText | Object | Object | inline css |
85
+ | alter [trials] | Object @params cb[function] | Object | altering object before rendering |
86
+ | reg | Object | void | registring an object |
87
+ | regm | Object | void | updating the existing registered object |
88
+ | load | Object | Object | read an existing registered object |
89
+ | unred | Object | void | removing an existing registered object |
90
+ | renderOption | Object @params option[Object] | void | set the option for rendering |
91
+
92
+ #### Why use this?
93
+
94
+ - Easy maintance innerHTML rather than literal string
95
+ - Generate static html file
96
+ - Full control of view. Such as filtering, encrypting the data before serve, or just like conditional and loop case
97
+ - Almost no need to learn anything. Just need to learn how to render
98
+ - Limitless potential, because it's just js. Almost all library should be compatible
99
+
100
+ ## Basic syntax
101
+
102
+ How to use? just import this:
103
+
104
+ ```js
105
+ import "neobiz";
106
+ ```
107
+
108
+ It's just an Object! `wrap in () to create a statement or just assign to a var`
109
+
110
+ ```js
111
+ {
112
+ // text property is same as innerText
113
+ h1: {
114
+ text: "Hello World!",
115
+ },
116
+ }._render;
117
+ // <h1>Hello World!</h1>
118
+ ```
119
+
120
+ or use call method
121
+
122
+ ```js
123
+ _render.call({
124
+ // text property is same as innerText
125
+ h1: {
126
+ text: "Hello World!",
127
+ },
128
+ });
129
+ ```
130
+
131
+ Comments:
132
+
133
+ ```js
134
+ {
135
+ // this is comment
136
+ /*
137
+ this is multi line
138
+ */
139
+ h1: {
140
+ text: "This is heading";
141
+ }
142
+ }
143
+ ```
144
+
145
+ properties dom
146
+
147
+ ```js
148
+ {
149
+ h1: {
150
+ class:"heading",
151
+ text: "Hello World!",
152
+ style:"color: #DC1E1E",
153
+ }
154
+ }
155
+ // <h1 class="heading" style="color: #DC1E1E">Hello World!</h1>
156
+ ```
157
+
158
+ boolean attributes
159
+
160
+ use `Null` to indicate non-value attributes, do not confuse `Null` to `null`
161
+
162
+ ```js
163
+ {
164
+ button: { text: "Hello World!", disabled: Null },
165
+ }._render
166
+ ```
167
+
168
+ innerText & innerHTML:
169
+
170
+ ```js
171
+ {
172
+ h1: { text: "<b>this is a text</b>" },
173
+ ul: { html: "<li>this will be render as html</li>" },
174
+ }
175
+ ```
176
+
177
+ nested dom:
178
+
179
+ ```js
180
+ {
181
+ body: {
182
+ h1: {
183
+ text: "Hello World!",
184
+ }
185
+ }
186
+ }
187
+ ```
188
+
189
+ expression & operator
190
+
191
+ ```js
192
+ {
193
+ span: [
194
+ { text: 24 + 12 / 6 },
195
+ { text: !false },
196
+ ],
197
+ }
198
+ ```
199
+
200
+ siblings dom:
201
+
202
+ There is a case like this:
203
+
204
+ ```html
205
+ <li>orange</li>
206
+ <li>banana</li>
207
+ ```
208
+
209
+ Object can not use 2 keys with the same name
210
+
211
+ ```js
212
+ // Don't do this
213
+ {
214
+ li:{text:"orange"},
215
+ li:{text:"banana"},
216
+ }
217
+
218
+ // Do this
219
+ {
220
+ li:[
221
+ {text:"orange"},
222
+ {text:"banana"},
223
+ ]
224
+ }
225
+ ```
226
+
227
+ ## Render Option
228
+
229
+ ```js
230
+ renderOption({
231
+ camelCase: false,
232
+ once: false,
233
+ nodoctype: false,
234
+ ignoreTag: false,
235
+ prefixTag: false,
236
+ prefixAttr: false,
237
+ });
238
+ ```
239
+
240
+ set once to `true` to use option only for once,
241
+ <br>
242
+ <br>
243
+
244
+ set nodoctype to `true` to remove `<!doctype html>` in the beninging,
245
+ <br>
246
+ <br>
247
+
248
+ set ignoreTag to `true` to unused `tag` properties,
249
+ <br>
250
+ <br>
251
+
252
+ set prefixTag to `something` to add text before `tag`,
253
+ <br>
254
+ use `noprefix:true` to skip on specific object
255
+ <br>
256
+
257
+ set prefixAttr to `something` to add text before `attribute`,
258
+ <br>
259
+ use `nopAttr:true` to skip in specific object
260
+ <br>
261
+
262
+ set `camelCase` `true` to convert **camelCase** properties to **kebab-case**
263
+
264
+ make sure to set the option before rendering
265
+
266
+ ```js
267
+ renderOption({
268
+ camelCase: true,
269
+ });
270
+
271
+ render.call({
272
+ ionRouter: {},
273
+ });
274
+ ```
275
+
276
+ result
277
+
278
+ ```html
279
+ <ion-router></ion-router>
280
+ ```
281
+
282
+ ## Explicit tag name
283
+
284
+ What if there is somethings in the middle of list?
285
+
286
+ ```html
287
+ <li>orange</li>
288
+ <p>
289
+ <span>This is in the middle</span>
290
+ </p>
291
+ <li>banana</li>
292
+ ```
293
+
294
+ if we use an array there will share the tag name right? just use this:
295
+
296
+ > use string as key could distinc an element with just a space
297
+ > no need to worry, it will render without space
298
+
299
+ ```js
300
+ {
301
+ li:{text:"orange"},
302
+ p:{span:{text:"This is in the middle"}},
303
+ "li ":{text:"banana"},
304
+ }
305
+ ```
306
+
307
+ or write the tag name:
308
+
309
+ ```js
310
+ {
311
+ li: [
312
+ { text: "orange" },
313
+ { tag: "p", span: { text: "This is in the middle" } },
314
+ { text: "banana" },
315
+ ],
316
+ }
317
+ ```
318
+
319
+ also with specifying tag name, we can name it differently:
320
+
321
+ ```js
322
+ {
323
+ PersonList: ["Arthur", "Zoro"].map((person) => ({
324
+ tag: "li",
325
+ text: person,
326
+ })),
327
+ }
328
+ ```
329
+
330
+ ### Modify an Object
331
+
332
+ use `alter` properties, with function as params. no need to return a value
333
+
334
+ ```js
335
+ const y = {
336
+ h1: { text: "Hello World!" },
337
+ p: { text: "this is a p" }.alter((e) => (e.class = "lorem")),
338
+ }.alter((e) => {
339
+ e.h1.text = "thi is altered text";
340
+ e.h1.style = { color: "red", fontSize: "150%" }.cssText;
341
+ });
342
+
343
+ console.log(y.render);
344
+ ```
345
+
346
+ ### Components / Partials
347
+
348
+ ```js
349
+ import header from "./header.v.js"; //function type
350
+ import footer from "./footer.v.js"; //object type
351
+
352
+ {
353
+ div: header({ user: "dim24" }),
354
+ p: { text: "this is text" },
355
+ div: footer,
356
+ }.render;
357
+ ```
358
+
359
+ header.v.js
360
+
361
+ ```js
362
+ export default ({ user }) => ({ h1: { text: `Hi, ${user}` } });
363
+ ```
364
+
365
+ footer.v.js
366
+
367
+ ```js
368
+ export default {
369
+ script: { src: "/assets/js/main.js" },
370
+ span: { text: "this is footer" },
371
+ };
372
+ ```
373
+
374
+ ### reg, regm, load & unreg Components
375
+
376
+ The idea is to make object has resuability
377
+
378
+ #### reg & load
379
+
380
+ > this function need a single argument to set a name of registering object,
381
+
382
+ there is 2 ways to registering an component:
383
+
384
+ - through properties method:
385
+
386
+ ```js
387
+ { name:"viewport"}.reg("viewport")
388
+ ```
389
+
390
+ - via call method:
391
+
392
+ ```js
393
+ reg.call({ name: "viewport" }, "viewport");
394
+ ```
395
+
396
+ now we can load it's value whenever we want
397
+
398
+ ```js
399
+ {
400
+ meta:load("viewport"),
401
+ body: {
402
+ }
403
+ }
404
+ ```
405
+
406
+ #### regm
407
+
408
+ this function will replace an existing registered object with a new value:
409
+
410
+ ```js
411
+ const newValue = load("viewport");
412
+ newValue.content = "width=device-width, initial-scale=1.0";
413
+
414
+ newValue.regm("viewport");
415
+ ```
416
+
417
+ #### unreg
418
+
419
+ when we the object doesn't needed anymore, just unreg it:
420
+
421
+ ```js
422
+ unreg("viewport");
423
+ ```
424
+
425
+ ### Style
426
+
427
+ use camel case to css properties
428
+
429
+ #### inline CSS:
430
+
431
+ ```js
432
+ {
433
+ h1:{
434
+ text:"Hello World",
435
+ style:{
436
+ color:"#1B73F8",
437
+ fontSize:"150%"
438
+ }.cssText
439
+ }
440
+ }
441
+ ```
442
+
443
+ use style :
444
+
445
+ `global-style.js`:
446
+
447
+ ```js
448
+ export default {
449
+ h1: {
450
+ color: "red",
451
+ },
452
+ body: {
453
+ margin: "0px",
454
+ textAlign: "center",
455
+ },
456
+ };
457
+ ```
458
+
459
+ why should use object css rather than direct css?
460
+
461
+ we can easily modify the style
462
+
463
+ `main-page.js`:
464
+
465
+ ```js
466
+ import style from "./global-style.js";
467
+
468
+ style.body.margin = "12px";
469
+
470
+ {
471
+ style:style.css,
472
+ div:{
473
+ h1:{text:"Hello World!"}
474
+ }
475
+ }.render
476
+ ```
477
+
478
+ reusable style / mixin
479
+
480
+ ```js
481
+ const flex = (justify, align, direction = "row") => ({
482
+ display: "flex",
483
+ justifyContent: justify,
484
+ alignItems: align,
485
+ flexDirection: direction,
486
+ });
487
+
488
+ const space = {
489
+ padding: "6px 8px",
490
+ margin: "6px 10px",
491
+ };
492
+
493
+ console.log({
494
+ style: { div: flex("center", "center"), button: { border: "none", ...space } }
495
+ .css,
496
+ });
497
+ ```
498
+
499
+ ### Interacting with DOM
500
+
501
+ use `script` to interact with browser with **html** property
502
+
503
+ wrap the script with a function, or use string
504
+
505
+ ```js
506
+ {
507
+ button:{onclick:"sayHi(this)",id:"hi-button"},
508
+ script:{
509
+ html(){
510
+ document.getElementById("hi-button").innerText="Click me!";
511
+
512
+ function sayHi(el){
513
+ el.innerText="Hi!";
514
+ }
515
+ }
516
+ }
517
+ }
518
+
519
+ ```
520
+
521
+ ### Event
522
+
523
+ you can add an event `this` keyword always refered to the node itseft
524
+
525
+ ```js
526
+ {
527
+ input:{type:"password",onkeypress(){
528
+ if(event.keyCode==13)
529
+ alert(this.value)
530
+ }},
531
+ button:{text:"Click me!",onclick(){
532
+ this.innerText = this.innerText=="clicked"?"Click me!":"clicked";
533
+ }}
534
+ }
535
+ ```
536
+
537
+ ## Repulse
538
+
539
+ If you already have an html file and want to modify it, or make it as a template, just use this
540
+
541
+ > this function is still has a lot issues, use only in a simple case
542
+
543
+ - need to wrap all tag into a single parent
544
+ - recommended to use external script and css
545
+ - repetitive / nested could caused weird behavior (help me, please!)
546
+
547
+ I still try to improve this feature. **if you can provide some help** just tell me please... :)
548
+
549
+ ```js
550
+ const { div } = `
551
+ <div>
552
+ <h1>Hello dims!</h1>
553
+ </div>
554
+ `.repulse;
555
+
556
+ div.id = "main";
557
+ div.h1.class = "heading";
558
+ div.p = { text: "this is a whole text" };
559
+
560
+ console.log({ div }.render);
561
+ ```
562
+
563
+ result
564
+
565
+ ```html
566
+ <div id="main">
567
+ <h1 class="heading">Hello dims!</h1>
568
+ <p>this is a whole text</p>
569
+ </div>
570
+ ```
571
+
572
+ ## Pass Value
573
+
574
+ use shorthand anonym function
575
+
576
+ ```js
577
+ console.log(((user) => ({ h1: { text: `Hello, ${user}` } }))("Vins").render);
578
+ ```
579
+
580
+ or
581
+
582
+ ```js
583
+ const greeting = (user) => ({ h1: `Hello, ${user}` });
584
+
585
+ console.log(greeting("Vins").render);
586
+ ```
587
+
588
+ ## Control Flow
589
+
590
+ ternary:
591
+
592
+ ```js
593
+ {
594
+ h1: status
595
+ ? { text: "Hello World!" }
596
+ : {
597
+ a: { href: "#", text: "You are offline!" },
598
+ },
599
+ }
600
+ ```
601
+
602
+ IIFE if-else
603
+
604
+ ```js
605
+ {
606
+ h1: (() => {
607
+ let result;
608
+ if (status) result = { text: "Hello World!" };
609
+ else
610
+ result = {
611
+ a: { href: "#", text: "You are offline!" },
612
+ };
613
+ return result;
614
+ })(),
615
+ }
616
+ ```
617
+
618
+ normal if else
619
+
620
+ ```js
621
+ let result;
622
+ if (status) result = { text: "Hello World!" };
623
+ else
624
+ result = {
625
+ a: { href: "#", text: "You are offline!" },
626
+ };
627
+
628
+ //use
629
+ {
630
+ h1: result,
631
+ }
632
+ ```
633
+
634
+ IIFE switch-case
635
+
636
+ ```js
637
+ {
638
+ h1: (() => {
639
+ let result;
640
+ switch (status) {
641
+ case true:
642
+ result = { text: "Hello World!" };
643
+ break;
644
+ case false:
645
+ result = {
646
+ a: { href: "#", text: "You are offline!" },
647
+ };
648
+ }
649
+ return result;
650
+ })(),
651
+ }
652
+ ```
653
+
654
+ ## Loop & array manipulation
655
+
656
+ range & map:
657
+
658
+ ```js
659
+
660
+ {
661
+ ul: {
662
+ li: [].range(8, 1).map((item) => ({ text: "data-" + item })),
663
+ },
664
+ }
665
+ ```
666
+
667
+ map
668
+
669
+ ```js
670
+ {
671
+ ul: {
672
+ li: ["grape", "banana", "apple"].map((text) => ({ text })),
673
+ },
674
+ }
675
+ ```
676
+
677
+ filter
678
+
679
+ ```js
680
+ {
681
+ ul: {
682
+ li: [].range(8, 1).filter( num => num % 2 == 0 ).map((item) => ({ text: "data-" + item })),
683
+ },
684
+ }
685
+ ```
686
+
687
+ for
688
+
689
+ ```js
690
+ {
691
+ ul: {
692
+ li: (() => {
693
+ const result = [];
694
+ for (let i = 1; i < 9; i++) result.push({ text: "data-" + i });
695
+ return result;
696
+ })(),
697
+ },
698
+ }
699
+ ```
700
+
701
+ while
702
+
703
+ ```js
704
+ {
705
+ ul: {
706
+ li: (() => {
707
+ const result = [];
708
+ let i = 0;
709
+ while (++i < 9) result.push({ text: "data-" + i });
710
+ return result;
711
+ })(),
712
+ },
713
+ }
714
+ ```
715
+
716
+ ## templating
717
+
718
+ this example use single file usage. for modular usage leave to you, or just read the example dir
719
+
720
+ ```js
721
+ //template file
722
+ const template = (content) => ({
723
+ div: {
724
+ class: "main wrapper",
725
+ div: content,
726
+ },
727
+ });
728
+
729
+ //content file
730
+ template({
731
+ h1: { text: "Hello World!" },
732
+ });
733
+ ```
734
+
735
+ ### Thank you for read until here.