jails-js 6.0.1-beta.3 → 6.0.1-beta.5
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/dist/index.js +50 -63
- package/dist/index.js.map +1 -1
- package/dist/jails.js +1 -1
- package/dist/jails.js.map +1 -1
- package/package.json +1 -1
- package/src/component.ts +32 -37
- package/src/index.ts +1 -1
- package/src/template-system.ts +12 -24
- package/src/utils/index.ts +0 -27
package/src/template-system.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { uuid
|
1
|
+
import { uuid } from './utils'
|
2
2
|
|
3
3
|
const templates = {}
|
4
4
|
|
@@ -22,9 +22,8 @@ export const template = ( target, { components }) => {
|
|
22
22
|
return templates
|
23
23
|
}
|
24
24
|
|
25
|
-
export const compile = (
|
25
|
+
export const compile = ( html ) => {
|
26
26
|
|
27
|
-
const html = transformAttributes( outerHTML )
|
28
27
|
const parsedHtml = JSON.stringify( html )
|
29
28
|
|
30
29
|
return new Function('$element', 'safe', '$g',`
|
@@ -64,7 +63,7 @@ const transformAttributes = ( html ) => {
|
|
64
63
|
.replace(/html-(allowfullscreen|async|autofocus|autoplay|checked|controls|default|defer|disabled|formnovalidate|inert|ismap|itemscope|loop|multiple|muted|nomodule|novalidate|open|playsinline|readonly|required|reversed|selected)=\"(.*?)\"/g, `%%_if(safe(function(){ return $2 })){_%%$1%%_}_%%`)
|
65
64
|
// The rest
|
66
65
|
.replace(/html-(.*?)=\"(.*?)\"/g, (all, key, value) => {
|
67
|
-
if (key === 'key' || key === 'model' || key === '
|
66
|
+
if (key === 'key' || key === 'model' || key === 'scopeid' ) {
|
68
67
|
return all
|
69
68
|
}
|
70
69
|
if (value) {
|
@@ -90,11 +89,12 @@ const transformTemplate = ( clone ) => {
|
|
90
89
|
|
91
90
|
element.removeAttribute('html-for')
|
92
91
|
|
93
|
-
const split
|
94
|
-
const varname
|
95
|
-
const object
|
96
|
-
const
|
97
|
-
const
|
92
|
+
const split = htmlFor.match(/(.*)\sin\s(.*)/) || ''
|
93
|
+
const varname = split[1]
|
94
|
+
const object = split[2]
|
95
|
+
const objectname = object.split(/\./).shift()
|
96
|
+
const open = document.createTextNode(`%%_ ;(function(){ var $index = 0; for(var $key in safe(function(){ return ${object} }) ){ var $scopeid = Math.random().toString(36).substring(2, 9); var ${varname} = ${object}[$key]; $g.scope[$scopeid] = Object.assign({}, { ${objectname}: ${objectname} }, { ${varname} :${varname}, $index: $index, $key: $key }); _%%`)
|
97
|
+
const close = document.createTextNode(`%%_ $index++; } })() _%%`)
|
98
98
|
|
99
99
|
wrap(open, element, close)
|
100
100
|
}
|
@@ -130,27 +130,15 @@ const setTemplates = ( clone, components ) => {
|
|
130
130
|
|
131
131
|
const tplid = node.getAttribute('tplid')
|
132
132
|
const name = node.localName
|
133
|
-
node.setAttribute('html-
|
133
|
+
node.setAttribute('html-scopeid', 'jails___scope-id')
|
134
134
|
|
135
135
|
if( name in components && components[name].module.template ) {
|
136
136
|
const children = node.innerHTML
|
137
137
|
const html = components[name].module.template({ elm:node, children })
|
138
|
-
|
139
|
-
if( html.constructor === Promise ) {
|
140
|
-
html.then( htmlstring => {
|
141
|
-
node.innerHTML = htmlstring
|
142
|
-
const html = node.outerHTML
|
143
|
-
templates[tplid] = {
|
144
|
-
template: html,
|
145
|
-
render: compile(html)
|
146
|
-
}
|
147
|
-
})
|
148
|
-
} else {
|
149
|
-
node.innerHTML = html
|
150
|
-
}
|
138
|
+
node.innerHTML = html
|
151
139
|
}
|
152
140
|
|
153
|
-
const html = node.outerHTML
|
141
|
+
const html = transformAttributes(node.outerHTML)
|
154
142
|
|
155
143
|
templates[ tplid ] = {
|
156
144
|
template: html,
|
package/src/utils/index.ts
CHANGED
@@ -1,15 +1,8 @@
|
|
1
1
|
|
2
|
-
const textarea = document.createElement('textarea')
|
3
|
-
|
4
2
|
export const g = {
|
5
3
|
scope: {}
|
6
4
|
}
|
7
5
|
|
8
|
-
export const decodeHTML = (text) => {
|
9
|
-
textarea.innerHTML = text
|
10
|
-
return textarea.value
|
11
|
-
}
|
12
|
-
|
13
6
|
export const rAF = (fn) => {
|
14
7
|
if (requestAnimationFrame)
|
15
8
|
return requestAnimationFrame(fn)
|
@@ -25,26 +18,6 @@ export const dup = (o) => {
|
|
25
18
|
return JSON.parse(JSON.stringify(o))
|
26
19
|
}
|
27
20
|
|
28
|
-
// http://crockford.com/javascript/memory/leak.html
|
29
|
-
export const purge = (d) => {
|
30
|
-
var a = d.attributes, i, l, n
|
31
|
-
if (a) {
|
32
|
-
for (i = a.length - 1; i >= 0; i -= 1) {
|
33
|
-
n = a[i].name
|
34
|
-
if (typeof d[n] === 'function') {
|
35
|
-
d[n] = null
|
36
|
-
}
|
37
|
-
}
|
38
|
-
}
|
39
|
-
a = d.childNodes
|
40
|
-
if (a) {
|
41
|
-
l = a.length
|
42
|
-
for (i = 0; i < l; i += 1) {
|
43
|
-
purge(d.childNodes[i])
|
44
|
-
}
|
45
|
-
}
|
46
|
-
}
|
47
|
-
|
48
21
|
export const safe = (execute, val) => {
|
49
22
|
try{
|
50
23
|
return execute()
|