enigmatic 0.9.14 → 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 (50) 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/{index.css → enigmatic.css} +97 -165
  46. package/{index.js → enigmatic.js} +4 -6
  47. package/package.json +3 -3
  48. package/readme.md +99 -0
  49. package/test.html +176 -0
  50. package/sw-nouse.js +0 -22
package/readme.md CHANGED
@@ -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 ADDED
@@ -0,0 +1,176 @@
1
+ <script src='index.js'></script>
2
+ <script type='module' src='elements/index.mjs'></script>
3
+ <link rel='stylesheet' href='index.css'>
4
+
5
+ <body style='display: grid; place-items: center;'>
6
+ <test-runner></test-runner>
7
+ </body>
8
+
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
173
+ }
174
+ })
175
+ }
176
+ </script>
package/sw-nouse.js DELETED
@@ -1,22 +0,0 @@
1
- self.addEventListener('install', event => {
2
- console.log('V1 installing…');
3
-
4
- // cache a cat SVG
5
- event.waitUntil(
6
- caches.open('static-v1').then(cache => cache.add('/index.js'))
7
- );
8
- });
9
-
10
- self.addEventListener('activate', event => {
11
- console.log('V1 now ready to handle fetches!');
12
- });
13
-
14
- self.addEventListener('fetch', event => {
15
- const url = new URL(event.request.url);
16
-
17
- // serve the cat SVG from the cache if the request is
18
- // same-origin and the path is '/dog.svg'
19
- if (url.origin == location.origin && url.pathname == '/index.js') {
20
- event.respondWith(caches.match('/index.js'));
21
- }
22
- });