enigmatic 0.9.11 → 0.9.15

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 (54) hide show
  1. package/.vscode/launch.json +15 -0
  2. package/elements/alert-box/alert-box.js +19 -0
  3. package/elements/alert-box/index.html +6 -0
  4. package/elements/block-maker/block-maker.js +15 -0
  5. package/elements/block-maker/index.html +7 -0
  6. package/elements/chart-progress-bar/chart-progress-bar.js +9 -0
  7. package/elements/chart-progress-bar/index.html +5 -0
  8. package/elements/chart-radial-progress/chart-radial-progress.css +39 -0
  9. package/elements/chart-radial-progress/chart-radial-progress.js +13 -0
  10. package/elements/chart-radial-progress/index.html +13 -0
  11. package/elements/chart-statistic/chart-statistic.js +34 -0
  12. package/elements/chart-statistic/index.html +13 -0
  13. package/elements/data-grid/data-grid.js +39 -0
  14. package/elements/data-grid/index.html +13 -0
  15. package/elements/data-source/data-source.js +36 -0
  16. package/elements/data-source/index.html +10 -0
  17. package/elements/data-stream/data-stream.js +28 -0
  18. package/elements/data-stream/index.html +7 -0
  19. package/elements/font-awesome/font-awesome.js +11 -0
  20. package/elements/font-awesome/index.html +7 -0
  21. package/elements/for-list/for-list.js +25 -0
  22. package/elements/for-list/index.html +11 -0
  23. package/elements/hello-world/hello-world.js +16 -0
  24. package/elements/hello-world/index.html +3 -0
  25. package/elements/index.mjs +20 -0
  26. package/elements/map-embed/index.html +4 -0
  27. package/elements/map-embed/map-embed.js +9 -0
  28. package/elements/monaco-editor/index.html +11 -0
  29. package/elements/monaco-editor/monaco-editor.mjs +33 -0
  30. package/elements/online-indicator/index.html +15 -0
  31. package/elements/online-indicator/online-indicator.js +20 -0
  32. package/elements/side-menu/index.html +10 -0
  33. package/elements/side-menu/side-menu.js +16 -0
  34. package/elements/tailwind-css/index.html +11 -0
  35. package/elements/tailwind-css/tailwind-css.js +11 -0
  36. package/elements/test-runner/test-runner.js +59 -0
  37. package/elements/time-ago/index.html +11 -0
  38. package/elements/time-ago/time-ago.js +22 -0
  39. package/elements/toggle-switch/index.html +8 -0
  40. package/elements/toggle-switch/toggle-switch.js +86 -0
  41. package/elements/view-panel/index.html +18 -0
  42. package/elements/view-panel/view-panel.js +22 -0
  43. package/elements/you-tube/index.html +7 -0
  44. package/elements/you-tube/you-tube.js +9 -0
  45. package/enigmatic.css +315 -0
  46. package/enigmatic.js +132 -0
  47. package/package.json +3 -3
  48. package/readme.md +99 -0
  49. package/test.html +173 -37
  50. package/elements/hello-world.mjs +0 -6
  51. package/elements/monaco-editor.mjs +0 -32
  52. package/main.css +0 -372
  53. package/main.js +0 -78
  54. package/maker.html +0 -16
package/readme.md ADDED
@@ -0,0 +1,99 @@
1
+ <<<<<<< HEAD
2
+ # enigmatic
3
+ ![version](https://d25lcipzij17d.cloudfront.net/badge.svg?id=js&type=6&v=0.8.5&x2=0)
4
+ ![size](http://img.badgesize.io/digplan/enigmatic/master/main.js)
5
+
6
+ Enigmatic is a JavaScript micro-library for creating web applications using lightweight web components.
7
+ It aspires to enable faster web app peformance, better reliabilty, and faster development process.
8
+
9
+ Enigmatic uses HTML attributes (directives) with a simple component model and data binding - all on existing HTML, JS, and CSS functionality.
10
+ - No special tooling, compilation or preprocessing, or new languages to learn
11
+ - Minimal JS and CSS core, includes basic components and two way data binding
12
+
13
+ ## Quick Start
14
+ Just create an HTML page
15
+ ````
16
+ <script src='//unpkg.com/enigmatic'></script>
17
+ <link href='//unpkg.com/enigmatic.css' rel='stylesheet'>
18
+ ````
19
+
20
+ ## Enigmatic also includes some helpers
21
+ ````
22
+ window.$ -- $([body])[0] // Query Selector All
23
+ window.load -- ('mycontrol.js') // Load JS or CSS
24
+ Element.css -- e.css('color:red') // Add css to an element
25
+ Element.child -- body.child('span') // Add a child element
26
+
27
+ ````
28
+
29
+ ## window.data
30
+ window.data is a single data object, that holds all the data for the app. It's a JS object, with each key being an identifier, or *channel* to use with controls that have the data attribute.
31
+
32
+ Controls interact with the data object to send and receive data, using a data attribute and .set() method.
33
+ ````
34
+ <!-- Just use the *data* attribute
35
+ <hellodata data='mykey'></hellodata>
36
+
37
+ window.data.set('mykey', 'Hello world!')
38
+ ````
39
+
40
+ One may also create a simple counter, interacting with plain ole (non-control) HTML elements.
41
+ In this example, the window.data object and control's data attribute take care of the binding.
42
+ ````
43
+ <button onclick='data.count++'>Click me</button>
44
+ <counter data='count'></counter>
45
+
46
+ data.count = 0
47
+ const counter = e =>
48
+ e.innerHTML = 'Ready'
49
+ ````
50
+ =======
51
+ # enigmatic
52
+ [![npm version](https://badge.fury.io/js/enigmatic.svg)](https://badge.fury.io/js/enigmatic)
53
+
54
+
55
+ Enigmatic is a JavaScript micro-library for creating web applications using lightweight web components.
56
+ It aspires to enable faster web app peformance, better reliabilty, and faster development process.
57
+
58
+ Enigmatic uses HTML attributes (directives) with a simple component model and data binding - all on existing HTML, JS, and CSS functionality.
59
+ - No special tooling, compilation or preprocessing, or new languages to learn
60
+ - Minimal JS and CSS core, includes basic components and two way data binding
61
+
62
+ ## Quick Start
63
+ Just create an HTML page
64
+ ````
65
+ <script src='//unpkg.com/enigmatic'></script>
66
+ <link href='//unpkg.com/enigmatic.css' rel='stylesheet'>
67
+ ````
68
+
69
+ ## Enigmatic also includes some helpers
70
+ ````
71
+ window.$ -- $([body])[0] // Query Selector All
72
+ window.load -- ('mycontrol.js') // Load JS or CSS
73
+ Element.css -- e.css('color:red') // Add css to an element
74
+ Element.child -- body.child('span') // Add a child element
75
+
76
+ ````
77
+
78
+ ## window.data
79
+ window.data is a single data object, that holds all the data for the app. It's a JS object, with each key being an identifier, or *channel* to use with controls that have the data attribute.
80
+
81
+ Controls interact with the data object to send and receive data, using a data attribute and .set() method.
82
+ ````
83
+ <!-- Just use the *data* attribute
84
+ <hellodata data='mykey'></hellodata>
85
+
86
+ window.data.set('mykey', 'Hello world!')
87
+ ````
88
+
89
+ One may also create a simple counter, interacting with plain ole (non-control) HTML elements.
90
+ In this example, the window.data object and control's data attribute take care of the binding.
91
+ ````
92
+ <button onclick='data.count++'>Click me</button>
93
+ <counter data='count'></counter>
94
+
95
+ data.count = 0
96
+ const counter = e =>
97
+ e.innerHTML = 'Ready'
98
+ ````
99
+ >>>>>>> 4f836882c656008703aad8afc30997772829f574
package/test.html CHANGED
@@ -1,40 +1,176 @@
1
- <script src='main.js'></script>
2
- <link rel='stylesheet' href='main.css'>
1
+ <script src='index.js'></script>
2
+ <script type='module' src='elements/index.mjs'></script>
3
+ <link rel='stylesheet' href='index.css'>
3
4
 
4
- <style>
5
- body {
6
- display: grid;
7
- grid-template-columns: 1fr 1fr 1fr;
8
- grid-template-rows: 1fr 1fr 1fr 1fr;
9
- grid-gap: 1px;
10
- }
11
- </style>
12
-
13
- <body>
14
- <div class='bg-white'>
15
- All data: <e-e data='ALL'>data</e-e>
16
- <br>
17
- Element data: <e-e id='ds' data='targetkey.method' class='bg-aqua'></e-e>
18
- <br>
19
- <button onclick='data.set("targetkey", {method: "a value"})''>set</button>
20
- </div>
21
- <div class='bg-green'></div>
22
- <div class='bg-red'></div>
23
- <div class='bg-yellow'></div>
24
- <e-e id='b' class='bg-black'></e-e>
25
- <div class='bg-gray'></div>
26
- <div class='bg-orange'></div>
27
- <div class='bg-maroon'></div>
5
+ <body style='display: grid; place-items: center;'>
6
+ <test-runner></test-runner>
7
+ </body>
28
8
 
29
- <script>
30
- class mySubclass extends EnigmaticElement {
31
- connectedCallback() {
32
- this.set('<h1>This is a subclass!</h1>')
9
+ <script>
10
+ main = async () => {
11
+ const runner = $('test-runner')
12
+ const display = $('tr-display')
13
+ runner.createTests({
14
+ // dom
15
+ 'Window exists': () => typeof window !== 'undefined',
16
+ 'Document exists': () => typeof document !== 'undefined',
17
+ 'Body exists': () => typeof document.body !== 'undefined',
18
+ // core js
19
+ 'fetch exists': () => { return fetch },
20
+ 'localStorage exists': () => { return localStorage },
21
+ // enigmatic core
22
+ '$ selector': () => { return $.name == 'bound querySelector' },
23
+ '$$ selector': () => { return $$.name == 'bound querySelectorAll' },
24
+ 'window.loadJS': () => { return window.loadJS },
25
+ 'window.loadCSS': () => { return window.loadCSS },
26
+ 'window.data': () => { return window.data },
27
+ 'window.data object': () => { return window.data._ },
28
+ 'window.data set': () => { return window.data.set },
29
+ 'window.wait': async () => {
30
+ return new Promise(async (r, j) => {
31
+ const time = +new Date()
32
+ await wait(100)
33
+ const timetaken = +new Date() - time
34
+ timetaken > 99 ? r(timetaken) : j(`Wait took ${timetaken}ms`)
35
+ })
36
+ },
37
+ 'window.ready': () => { return window.ready },
38
+ // EE
39
+ 'EnigmaticElement': () => { return EnigmaticElement },
40
+ 'EnigmaticElement create': async () => {
41
+ return new Promise(async (r, j) => {
42
+ const e = $('#trdisplay').child('e-e')
43
+ e.id = 'testelement'
44
+ e.innerHTML = '<h1>Hello e-e element</h1>'
45
+ e.hide()
46
+ e.show()
47
+ e.setAttribute('data', 'mykey')
48
+ r(e)
49
+ })
50
+ },
51
+ 'EE-childHTML': () => {
52
+ const e = $('#trdisplay').childHTML('<span>Im a test</span>')
53
+ const ret = (e.innerHTML === '<span>Im a test</span>')
54
+ e.remove()
55
+ return ret
56
+ },
57
+ // Data
58
+ 'window.data set': () => { return window.data.set },
59
+ 'window.data.set(val)': () => { return window.data.set('mykey', 'myval') },
60
+ 'Element data subscribe': () => { return $('#testelement').innerHTML === 'myval' },
61
+ // Custom elements
62
+ 'Hello World element': async () => {
63
+ $('#testelement').remove()
64
+ return new Promise(async (r, j) => {
65
+ const hw = $('#trdisplay').child('hello-world')
66
+ await wait(500)
67
+ $('hello-world').hide()
68
+ await wait(500)
69
+ $('hello-world').show()
70
+ await wait(500)
71
+ $('hello-world').hide()
72
+ $('hello-world').remove()
73
+ r(true)
74
+ })
75
+ },
76
+ 'you-tube': async () => {
77
+ const r = $('#trdisplay').child('you-tube')
78
+ await wait(1500)
79
+ r.hide()
80
+ r.remove()
81
+ return r
82
+ },
83
+ 'monaco-editor': async () => {
84
+ const r = $('#trdisplay').child('monaco-editor')
85
+ r.set('javascript', 'console.log(1)')
86
+ await wait(500)
87
+ await r.hide()
88
+ r.remove()
89
+ return r
90
+ },
91
+ 'online-indicator': async () => {
92
+ const r = $('#trdisplay').child('online-indicator')
93
+ await wait(500)
94
+ if (navigator.onLine && r.innerHTML !== '🟢')
95
+ throw Error('online-indicator not online')
96
+ runner.set('Disconnect your network connection to continue')
97
+ //await r.wentOffline()
98
+ if (!navigator.onLine && r.innerHTML !== '🔴')
99
+ throw Error('online-indicator not offline')
100
+ runner.set('Connect your network connection to continue')
101
+ //await r.wentOnline()
102
+ await r.hide()
103
+ r.remove()
104
+ return true
105
+ },
106
+ 'font-awesome': async () => {
107
+ const r = $('#trdisplay').child('font-awesome')
108
+ r.set('fas fa-heart')
109
+ await wait(500)
110
+ r.set('fas fa-check')
111
+ await wait(1000)
112
+ const ret = getComputedStyle($('font-awesome')).fontFamily.match(/Font/i)
113
+ r.remove()
114
+ return ret
115
+ },
116
+ 'view-panel': async () => {
117
+ const display = $('#trdisplay')
118
+ const vp = display.child('view-panel')
119
+ vp.classList.add('show')
120
+ vp.style.display = 'grid'
121
+ vp.style.gridTemplate = '1fr / 1fr'
122
+ const x = vp.child('e-e', 'one')
123
+ x.style.backgroundColor = 'red'
124
+ x.innerHTML = '!'
125
+ const xx = vp.child('div', 'two')
126
+ xx.style.backgroundColor = 'green'
127
+ xx.innerHTML = '!'
128
+ const xxx = vp.child('div', 'three')
129
+ xxx.style.backgroundColor = 'blue'
130
+ xxx.innerHTML = '!'
131
+ const b = display.child('button', 'four')
132
+ b.textContent = 'Show only one'
133
+ b.onclick = () => {
134
+ vp.showOnly('#one')
135
+ }
136
+ const c = display.child('button', 'five')
137
+ c.textContent = 'Show all'
138
+ c.onclick = () => {
139
+ vp.showAll()
140
+ $('#one').hide()
141
+ }
142
+ await wait(500)
143
+ b.click()
144
+ await wait(500)
145
+ c.click()
146
+ await wait(500)
147
+ b.remove()
148
+ c.remove()
149
+ vp.remove()
150
+ return true
151
+ },
152
+ 'side-menu': async () => {
153
+ $('#trdisplay').childHTML(`
154
+ <button id='opener' onclick="$('#me').toggle()" style='position: absolute; left: 400px'>Open</button>
155
+ <side-menu id='me' toggle-classes='slide-in slide-out'>
156
+ <li class=''>
157
+ <font-awesome class='fa fa-check'></font-awesome> one
158
+ </li>
159
+ <li class=''>
160
+ <font-awesome class='fa fa-check'></font-awesome> one
161
+ </li>
162
+ <li class=''>
163
+ <font-awesome class='fa fa-check'></font-awesome> one
164
+ </li>
165
+ <li class=''>
166
+ <font-awesome class='fa fa-check'></font-awesome> one
167
+ </li>
168
+ <li class=''>
169
+ <font-awesome class='fa fa-check'></font-awesome> one
170
+ </li>
171
+ </side-menu>`)
172
+ return true
33
173
  }
34
- }
35
- customElements.define('my-subclass', mySubclass);
36
- </script>
37
- <my-subclass class='bg-yellow'>&lt;my-subclass class='bg-yellow'></my-subclass>
38
-
39
- <button onclick='b.hide()'>Hide</button>
40
- </body>
174
+ })
175
+ }
176
+ </script>
@@ -1,6 +0,0 @@
1
- class HelloWorld extends EnigmaticElement {
2
- connectedCallback() {
3
- this.innerHTML = `<h1>Hello World!</h1>`;
4
- }
5
- }
6
- customElements.define('hello-world', HelloWorld);
@@ -1,32 +0,0 @@
1
- class MonacoEditor extends HTMLElement {
2
- async connectedCallback() {
3
- await loadJS('https://unpkg.com/monaco-editor@0.30.1/min/vs/loader.js')
4
- this.innerHTML = `<div id="m-container" style="${this.getAttribute('estyle')}"></div>`
5
- require.config({ paths: { vs: 'min/vs' } })
6
- const id = this.getAttribute('id'), that = this
7
- require(['vs/editor/editor.main'], function () {
8
- const editor = monaco.editor.create(document.getElementById('m-container'), {
9
- value: $(`code[for=${id}]`).innerHTML,
10
- language: 'javascript'
11
- })
12
- that.editor = editor
13
- })
14
- }
15
- }
16
- customElements.define('monaco-editor', MonacoEditor)
17
-
18
- /*
19
-
20
- example..
21
-
22
- <monaco-editor id='me1' estyle="width: 600px; height: 400px; border: 1px solid gray"></monaco-editor>
23
- <code for='me1' hidden>
24
- class HelloWorld extends HTMLElement {
25
- connectedCallback() {
26
- this.innerHTML = '<div>Hello World!</div>'
27
- }
28
- }
29
- customElements.define('hello-world', HelloWorld)
30
- </code>
31
-
32
- */