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.
- package/.vscode/launch.json +15 -0
- package/elements/alert-box/alert-box.js +19 -0
- package/elements/alert-box/index.html +6 -0
- package/elements/block-maker/block-maker.js +15 -0
- package/elements/block-maker/index.html +7 -0
- package/elements/chart-progress-bar/chart-progress-bar.js +9 -0
- package/elements/chart-progress-bar/index.html +5 -0
- package/elements/chart-radial-progress/chart-radial-progress.css +39 -0
- package/elements/chart-radial-progress/chart-radial-progress.js +13 -0
- package/elements/chart-radial-progress/index.html +13 -0
- package/elements/chart-statistic/chart-statistic.js +34 -0
- package/elements/chart-statistic/index.html +13 -0
- package/elements/data-grid/data-grid.js +39 -0
- package/elements/data-grid/index.html +13 -0
- package/elements/data-source/data-source.js +36 -0
- package/elements/data-source/index.html +10 -0
- package/elements/data-stream/data-stream.js +28 -0
- package/elements/data-stream/index.html +7 -0
- package/elements/font-awesome/font-awesome.js +11 -0
- package/elements/font-awesome/index.html +7 -0
- package/elements/for-list/for-list.js +25 -0
- package/elements/for-list/index.html +11 -0
- package/elements/hello-world/hello-world.js +16 -0
- package/elements/hello-world/index.html +3 -0
- package/elements/index.mjs +20 -0
- package/elements/map-embed/index.html +4 -0
- package/elements/map-embed/map-embed.js +9 -0
- package/elements/monaco-editor/index.html +11 -0
- package/elements/monaco-editor/monaco-editor.mjs +33 -0
- package/elements/online-indicator/index.html +15 -0
- package/elements/online-indicator/online-indicator.js +20 -0
- package/elements/side-menu/index.html +10 -0
- package/elements/side-menu/side-menu.js +16 -0
- package/elements/tailwind-css/index.html +11 -0
- package/elements/tailwind-css/tailwind-css.js +11 -0
- package/elements/test-runner/test-runner.js +59 -0
- package/elements/time-ago/index.html +11 -0
- package/elements/time-ago/time-ago.js +22 -0
- package/elements/toggle-switch/index.html +8 -0
- package/elements/toggle-switch/toggle-switch.js +86 -0
- package/elements/view-panel/index.html +18 -0
- package/elements/view-panel/view-panel.js +22 -0
- package/elements/you-tube/index.html +7 -0
- package/elements/you-tube/you-tube.js +9 -0
- package/enigmatic.css +315 -0
- package/enigmatic.js +132 -0
- package/package.json +3 -3
- package/readme.md +99 -0
- package/test.html +173 -37
- package/elements/hello-world.mjs +0 -6
- package/elements/monaco-editor.mjs +0 -32
- package/main.css +0 -372
- package/main.js +0 -78
- package/maker.html +0 -16
package/readme.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<<<<<<< HEAD
|
|
2
|
+
# enigmatic
|
|
3
|
+

|
|
4
|
+

|
|
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
|
+
[](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='
|
|
2
|
-
<
|
|
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
|
-
|
|
6
|
-
|
|
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
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
<my-subclass class='bg-yellow'><my-subclass class='bg-yellow'></my-subclass>
|
|
38
|
-
|
|
39
|
-
<button onclick='b.hide()'>Hide</button>
|
|
40
|
-
</body>
|
|
174
|
+
})
|
|
175
|
+
}
|
|
176
|
+
</script>
|
package/elements/hello-world.mjs
DELETED
|
@@ -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
|
-
*/
|