binhend 1.0.11 → 1.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.
Files changed (51) hide show
  1. package/example_webcomp/components/AnUserInterface.js +0 -0
  2. package/example_webcomp/components/common/InputText.js +14 -0
  3. package/example_webcomp/components/common/Link.js +16 -0
  4. package/example_webcomp/components/common/Link2.js +13 -0
  5. package/example_webcomp/components/index.html +18 -0
  6. package/example_webcomp/components/index.js +6 -0
  7. package/example_webcomp/components/layouts/AppMainLayout.js +22 -0
  8. package/example_webcomp/components/layouts/AppToDos.js +47 -0
  9. package/example_webcomp/components/layouts/PageContent.js +25 -0
  10. package/example_webcomp/components/layouts/PageHeader.js +49 -0
  11. package/example_webcomp/components/layouts/ToDoItem.js +25 -0
  12. package/example_webcomp/components/services/AnyService.js +6 -0
  13. package/example_webcomp/components/services/ServiceToDos.js +42 -0
  14. package/example_webcomp/components/styles/ToDoItemStyle.js +40 -0
  15. package/example_webcomp/components/styles/ToDoItemStyle2.js +2 -0
  16. package/example_webcomp/components/styles/temp.css +4 -0
  17. package/example_webcomp/components/styles/todo.css +31 -0
  18. package/example_webcomp/components/styles/todo.css.js +2 -0
  19. package/example_webcomp/config.js +13 -0
  20. package/example_webcomp/index.js +10 -0
  21. package/example_webcomp/public/AnUserInterface.js +0 -0
  22. package/example_webcomp/public/common/InputText.js +17 -0
  23. package/example_webcomp/public/common/Link.js +17 -0
  24. package/example_webcomp/public/common/Link2.js +13 -0
  25. package/example_webcomp/public/index.html +18 -0
  26. package/example_webcomp/public/index.js +6 -0
  27. package/example_webcomp/public/layouts/AppMainLayout.js +96 -0
  28. package/example_webcomp/public/layouts/AppToDos.js +100 -0
  29. package/example_webcomp/public/layouts/PageContent.js +29 -0
  30. package/example_webcomp/public/layouts/PageHeader.js +52 -0
  31. package/example_webcomp/public/layouts/ToDoItem.js +30 -0
  32. package/example_webcomp/public/services/AnyService.js +8 -0
  33. package/example_webcomp/public/services/ServiceToDos.js +46 -0
  34. package/example_webcomp/public/styles/ToDoItemStyle.js +44 -0
  35. package/example_webcomp/public/styles/ToDoItemStyle2.js +9 -0
  36. package/example_webcomp/public/styles/temp.css +4 -0
  37. package/example_webcomp/public/styles/todo.css +31 -0
  38. package/example_webcomp/public/styles/todo.css.js +9 -0
  39. package/package.json +12 -2
  40. package/src/binh.js +68 -1
  41. package/src/code.js +88 -0
  42. package/src/component.js +108 -0
  43. package/src/server.js +9 -0
  44. package/testa.js +28 -0
  45. /package/{example → example_api}/config.js +0 -0
  46. /package/{example → example_api}/index.js +0 -0
  47. /package/{example → example_api}/routes/test/bb.js +0 -0
  48. /package/{example → example_api}/routes/test/index.js +0 -0
  49. /package/{example → example_api}/routes/test/some.js +0 -0
  50. /package/{example → example_api}/routes/test.js +0 -0
  51. /package/{example → example_api}/routes/testa.js +0 -0
File without changes
@@ -0,0 +1,14 @@
1
+
2
+ function main() {
3
+ var inputbox = input({ type: 'text', placeholder: 'Enter to-do item' });
4
+
5
+ inputbox.on('keypress', function (event) {
6
+ if (event.key === "Enter") {
7
+ inputbox.does('submit', inputbox.element.value);
8
+ }
9
+ });
10
+
11
+ return inputbox;
12
+ }
13
+
14
+ binh.ui(module, main, ['input']);
@@ -0,0 +1,16 @@
1
+
2
+
3
+ function Link() {
4
+ var { a } = Binh.elements;
5
+
6
+ var text = arguments[0];
7
+ var path = arguments[1];
8
+
9
+ var link = a(text).on('click', function() {
10
+ Binh.Router.navigate(path);
11
+ });
12
+
13
+ return link;
14
+ }
15
+
16
+ binh.ui(module, Link);
@@ -0,0 +1,13 @@
1
+
2
+ Binh.ui(function() {
3
+ var { a } = Binh.elements;
4
+
5
+ var text = arguments[0];
6
+ var path = arguments[1];
7
+
8
+ var link = a(text).on('click', function() {
9
+ Binh.Router.navigate(path);
10
+ });
11
+
12
+ return link;
13
+ });
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>Binh Demo</title>
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <!-- <link rel="stylesheet" href="/lib/bootstrap.3.4.1.min.css"> -->
8
+ <!-- <link rel="stylesheet" href="style.css"> -->
9
+ <!-- <script src="/lib/jquery.3.5.1.min.js"></script>
10
+ <script src="/lib/bootstrap.3.4.1.min.js"></script> -->
11
+
12
+ <script src="http://localhost:1300/dev/binh.min.js"></script>
13
+ <!-- <script src="https://binhjs.pages.dev/dist/binh.min.js"></script> -->
14
+ <!-- <script src="https://cdn.jsdelivr.net/gh/penciless/binhjs/dist/binh.min.js"></script> -->
15
+ <script src="/index.js"></script>
16
+ </head>
17
+ <body></body>
18
+ </html>
@@ -0,0 +1,6 @@
1
+
2
+ Binh({
3
+ '': '/layouts/AppMainLayout.js',
4
+ '/todos': '/layouts/AppToDos.js'
5
+ });
6
+
@@ -0,0 +1,22 @@
1
+
2
+ require('./PageHeader');
3
+ require('./PageContent');
4
+ require('./../services/AnyService');
5
+
6
+ function AppMainLayout() {
7
+ var MainLayout = div({ id: 'app-main-layout' });
8
+
9
+ MainLayout(
10
+ PageHeader,
11
+ PageContent,
12
+ function (thisEl) {
13
+ setTimeout(function() {
14
+ console.log('>>> App Main Layout:', thisEl);
15
+ }, 1000);
16
+ }
17
+ );
18
+
19
+ return MainLayout;
20
+ }
21
+
22
+ binh.ui(module, AppMainLayout, ['div'], ['https://code.jquery.com/jquery-3.7.0.min.js']);
@@ -0,0 +1,47 @@
1
+
2
+ // require('./PageHeader');
3
+ // require('./ToDoItem');
4
+ require('./../common/InputText');
5
+ require('./../services/ServiceToDos');
6
+
7
+
8
+ function main() {
9
+ var PageHeader = this.ui('/layouts/PageHeader.js');
10
+ var ToDoItem = this.ui('/layouts/ToDoItem.js');
11
+ // var addTodoItem = ServiceToDos.does('add');
12
+ // var addTodoItem = ServiceToDos.debounce('add', 1500); // trailing only
13
+ var addTodoItem = ServiceToDos.debounce('add', 1500, true); // both leading & trailing
14
+ // var addTodoItem = ServiceToDos.debounce('add', 1500, true, true); // leading only
15
+ // var addTodoItem = ServiceToDos.throttle('add', 1500);
16
+ // var addTodoItem = ServiceToDos.once('add', 1500);
17
+
18
+ var inputbox = InputText().when('submit', addTodoItem);
19
+
20
+ var todolist = div({ class: 'todo-items' });
21
+
22
+ todolist.subscribe('todos', function(data) {
23
+ todolist.empty();
24
+ data.forEach(function(datum) {
25
+ todolist(
26
+ ToDoItem(datum).when('remove', ServiceToDos.instant('remove'))
27
+ );
28
+ });
29
+ });
30
+
31
+ var maindiv = div({ class: 'container' });
32
+ var left_section = div({ id: 'left-section' })('left section')(PageHeader);
33
+ var right_section = div({ id: 'right-section' })('right section');
34
+
35
+ maindiv(
36
+ left_section,
37
+ right_section(
38
+ div('To-Do List'),
39
+ inputbox,
40
+ todolist
41
+ )
42
+ );
43
+
44
+ return maindiv;
45
+ }
46
+
47
+ binh.ui(module, main, ['div', 'span']);
@@ -0,0 +1,25 @@
1
+
2
+ function PageContent() {
3
+ var { Router } = Binh;
4
+
5
+ var PageContent = div({ id: 'page-content' });
6
+
7
+ PageContent(
8
+ new Router({
9
+ '': div('default work!'),
10
+ '/abc': div('abc work!'),
11
+ '/haha': trans('haha work!')
12
+ })
13
+ )
14
+ (
15
+ function (thisEl) {
16
+ setTimeout(function() {
17
+ console.log('>>> Page Content:', thisEl);
18
+ }, 1000);
19
+ }
20
+ );
21
+
22
+ return PageContent;
23
+ }
24
+
25
+ binh.ui(module, PageContent, ['div', 'trans']);
@@ -0,0 +1,49 @@
1
+
2
+ // var { Link } = require('./../common/Link');
3
+
4
+ function PageHeader() {
5
+ var Link = this.ui('/common/Link2.js');
6
+
7
+ var PageHeader = div({ id: 'page-header' });
8
+
9
+ PageHeader(
10
+ div({ class: 'container' })(
11
+ div({ class: 'row' })(
12
+ nav({ class: 'navbar navbar-default' })(
13
+ div({ class: 'container-fluid' })([
14
+ div({ class: 'navbar-header' })(
15
+ a({ class: 'navbar-brand', href: '#' })(
16
+ 'Website Name'
17
+ )
18
+ ),
19
+ ul({ class: 'nav navbar-nav' })(
20
+ li({ class: 'active' })(
21
+ Link('Home', '/')
22
+ ),
23
+ li(
24
+ Link('Abc', '/abc')
25
+ ),
26
+ li(
27
+ Link('Haha', '/haha')
28
+ ),
29
+ li(
30
+ a('Page 3')
31
+ )
32
+ )
33
+ ])
34
+ )
35
+ )
36
+ ),
37
+ function (thisEl) {
38
+ setTimeout(function() {
39
+ console.log('>>> Page Header:', thisEl);
40
+ }, 1000);
41
+ }
42
+ );
43
+
44
+ return PageHeader;
45
+ }
46
+
47
+ var htmltags = ['div', 'nav', 'ul', 'li', 'a'];
48
+
49
+ binh.ui(module, PageHeader, htmltags);
@@ -0,0 +1,25 @@
1
+
2
+ // require('./../styles/ToDoItemStyle');
3
+ require('./../styles/ToDoItemStyle2');
4
+ // require('../styles/todo.css.js');
5
+
6
+ function main(props) {
7
+ // var ToDoItemStyle = this.style('/styles/todo.css');
8
+
9
+ var todoitem = div({ style: 'margin: 3px;' });
10
+
11
+ var remove_button = span({ class: 'btn-remove' })('X');
12
+
13
+ remove_button.on('click', function() {
14
+ todoitem.does('remove', props.id);
15
+ });
16
+
17
+ todoitem(span(props.text), span('-------'), remove_button);
18
+
19
+ // return todoitem.style(ToDoItemStyle);
20
+ // return todoitem.style('styles/todo.css');
21
+ return todoitem.style(ToDoItemStyle2);
22
+ // return todoitem.style(todo);
23
+ }
24
+
25
+ binh.ui(module, main, ['div', 'span']);
@@ -0,0 +1,6 @@
1
+
2
+ function AnyService() {
3
+
4
+ }
5
+
6
+ binh.service(module, AnyService);
@@ -0,0 +1,42 @@
1
+
2
+ binh.service(module, function(define, state, http) {
3
+ var todos = state.as('todos');
4
+
5
+ todos.schema(function(resolve) {
6
+ new http(api('get'))
7
+ .get(function(response) {
8
+ resolve(parseResponse(response));
9
+ });
10
+ });
11
+
12
+ function handleResponse(response) {
13
+ todos.set(parseResponse(response));
14
+ }
15
+
16
+ function parseResponse(response) {
17
+ var todoitems = [];
18
+
19
+ Object.keys(response).forEach(function(key) {
20
+ var each = response[key];
21
+ todoitems.push({ id: key, text: each.text });
22
+ });
23
+
24
+ return todoitems;
25
+ }
26
+
27
+ define('add', function(value) {
28
+ new http(api('add'))
29
+ .body({ text: value })
30
+ .post(handleResponse);
31
+ });
32
+
33
+ define('remove', function(id) {
34
+ new http(api('remove'))
35
+ .body({ id: id })
36
+ .post(handleResponse);
37
+ });
38
+
39
+ function api(relative_url) {
40
+ return 'https://todolist-of-binh.fly.dev/todos/' + relative_url;
41
+ }
42
+ });
@@ -0,0 +1,40 @@
1
+
2
+ binh.style(module, function(css) {
3
+ // css('@charset "utf-8";');
4
+
5
+ css(`@import url("styles/temp.css");`);
6
+
7
+
8
+ css('.btn-remove', [
9
+ 'color: purple;',
10
+ 'margin-left: 10px'
11
+ ]);
12
+
13
+ css(
14
+ `@media (min-width: 800px) {
15
+ .btn-remove {
16
+ color: red;
17
+ margin-left: '15px';
18
+ }
19
+ }`
20
+ );
21
+
22
+ css(`
23
+ @keyframes slidein {
24
+ from {
25
+ transform: translateX(0%);
26
+ }
27
+
28
+ to {
29
+ transform: translateX(100%);
30
+ }
31
+ }
32
+ `);
33
+
34
+ css(`
35
+ @page {
36
+ size: 8.5in 9in;
37
+ margin-top: 4in;
38
+ }
39
+ `);
40
+ });
@@ -0,0 +1,2 @@
1
+
2
+ binh.css(module, './todo.css');
@@ -0,0 +1,4 @@
1
+ .btn-remove {
2
+ color: purple;
3
+ margin-left: '15px';
4
+ }
@@ -0,0 +1,31 @@
1
+ @charset "utf-8";
2
+
3
+ @import url("/styles/temp.css");
4
+
5
+ /* .btn-remove {
6
+ color: blue;
7
+ margin-left: '15px';
8
+ } */
9
+
10
+ @media (min-width: 800px) {
11
+
12
+ .btn-remove {
13
+ color: red;
14
+ margin-left: '15px';
15
+ }
16
+ }
17
+
18
+ @keyframes slidein {
19
+ from {
20
+ transform: translateX(0%);
21
+ }
22
+
23
+ to {
24
+ transform: translateX(100%);
25
+ }
26
+ }
27
+
28
+ @page {
29
+ size: 8.5in 9in;
30
+ margin-top: 4in;
31
+ }
@@ -0,0 +1,2 @@
1
+
2
+ binh.css(module);
@@ -0,0 +1,13 @@
1
+
2
+ module.exports = function(loader) {
3
+ var sample = {
4
+ ABC: 123,
5
+ Text: 'Hello',
6
+ NAME: 'MyApp',
7
+ PORT: 1400
8
+ };
9
+
10
+ var { filter, object } = loader;
11
+
12
+ filter(object, sample, ['PORT', 'NAME']);
13
+ };
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ const { Binh } = require('../src/binh');
4
+
5
+ new Binh()
6
+ .web('public', 'components')
7
+ .port(1234)
8
+ .start(function(server, configs) {
9
+ console.log('### START >>> configs:', configs);
10
+ });
File without changes
@@ -0,0 +1,17 @@
1
+ !function(){
2
+
3
+ Binh.ui(function main() {
4
+ var inputbox = input({ type: 'text', placeholder: 'Enter to-do item' });
5
+
6
+ inputbox.on('keypress', function (event) {
7
+ if (event.key === "Enter") {
8
+ inputbox.does('submit', inputbox.element.value);
9
+ }
10
+ });
11
+
12
+ return inputbox;
13
+ });
14
+
15
+ var input = Binh.el('input');
16
+
17
+ }();
@@ -0,0 +1,17 @@
1
+ !function(){
2
+
3
+ Binh.ui(function Link() {
4
+ var { a } = Binh.elements;
5
+
6
+ var text = arguments[0];
7
+ var path = arguments[1];
8
+
9
+ var link = a(text).on('click', function() {
10
+ Binh.Router.navigate(path);
11
+ });
12
+
13
+ return link;
14
+ });
15
+
16
+
17
+ }();
@@ -0,0 +1,13 @@
1
+
2
+ Binh.ui(function() {
3
+ var { a } = Binh.elements;
4
+
5
+ var text = arguments[0];
6
+ var path = arguments[1];
7
+
8
+ var link = a(text).on('click', function() {
9
+ Binh.Router.navigate(path);
10
+ });
11
+
12
+ return link;
13
+ });
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <title>Binh Demo</title>
5
+ <meta charset="utf-8">
6
+ <meta name="viewport" content="width=device-width, initial-scale=1">
7
+ <!-- <link rel="stylesheet" href="/lib/bootstrap.3.4.1.min.css"> -->
8
+ <!-- <link rel="stylesheet" href="style.css"> -->
9
+ <!-- <script src="/lib/jquery.3.5.1.min.js"></script>
10
+ <script src="/lib/bootstrap.3.4.1.min.js"></script> -->
11
+
12
+ <script src="http://localhost:1300/dev/binh.min.js"></script>
13
+ <!-- <script src="https://binhjs.pages.dev/dist/binh.min.js"></script> -->
14
+ <!-- <script src="https://cdn.jsdelivr.net/gh/penciless/binhjs/dist/binh.min.js"></script> -->
15
+ <script src="/index.js"></script>
16
+ </head>
17
+ <body></body>
18
+ </html>
@@ -0,0 +1,6 @@
1
+
2
+ Binh({
3
+ '': '/layouts/AppMainLayout.js',
4
+ '/todos': '/layouts/AppToDos.js'
5
+ });
6
+
@@ -0,0 +1,96 @@
1
+ Binh.requires(['https://code.jquery.com/jquery-3.7.0.min.js'], function() {
2
+
3
+ var PageHeader = Binh.ui('/layouts/PageHeader.js', function PageHeader() {
4
+ var Link = this.ui('/common/Link2.js');
5
+
6
+ var PageHeader = div({ id: 'page-header' });
7
+
8
+ PageHeader(
9
+ div({ class: 'container' })(
10
+ div({ class: 'row' })(
11
+ nav({ class: 'navbar navbar-default' })(
12
+ div({ class: 'container-fluid' })([
13
+ div({ class: 'navbar-header' })(
14
+ a({ class: 'navbar-brand', href: '#' })(
15
+ 'Website Name'
16
+ )
17
+ ),
18
+ ul({ class: 'nav navbar-nav' })(
19
+ li({ class: 'active' })(
20
+ Link('Home', '/')
21
+ ),
22
+ li(
23
+ Link('Abc', '/abc')
24
+ ),
25
+ li(
26
+ Link('Haha', '/haha')
27
+ ),
28
+ li(
29
+ a('Page 3')
30
+ )
31
+ )
32
+ ])
33
+ )
34
+ )
35
+ ),
36
+ function (thisEl) {
37
+ setTimeout(function() {
38
+ console.log('>>> Page Header:', thisEl);
39
+ }, 1000);
40
+ }
41
+ );
42
+
43
+ return PageHeader;
44
+ });
45
+
46
+ var PageContent = Binh.ui('/layouts/PageContent.js', function PageContent() {
47
+ var { Router } = Binh;
48
+
49
+ var PageContent = div({ id: 'page-content' });
50
+
51
+ PageContent(
52
+ new Router({
53
+ '': div('default work!'),
54
+ '/abc': div('abc work!'),
55
+ '/haha': trans('haha work!')
56
+ })
57
+ )
58
+ (
59
+ function (thisEl) {
60
+ setTimeout(function() {
61
+ console.log('>>> Page Content:', thisEl);
62
+ }, 1000);
63
+ }
64
+ );
65
+
66
+ return PageContent;
67
+ });
68
+
69
+ var AnyService = Binh.service('/services/AnyService.js', function AnyService() {
70
+
71
+ });
72
+
73
+ Binh.ui(function AppMainLayout() {
74
+ var MainLayout = div({ id: 'app-main-layout' });
75
+
76
+ MainLayout(
77
+ PageHeader,
78
+ PageContent,
79
+ function (thisEl) {
80
+ setTimeout(function() {
81
+ console.log('>>> App Main Layout:', thisEl);
82
+ }, 1000);
83
+ }
84
+ );
85
+
86
+ return MainLayout;
87
+ });
88
+
89
+ var div = Binh.el('div'),
90
+ nav = Binh.el('nav'),
91
+ ul = Binh.el('ul'),
92
+ li = Binh.el('li'),
93
+ a = Binh.el('a'),
94
+ trans = Binh.el('trans');
95
+
96
+ });