jails-js 6.0.1-beta.5 → 6.0.1-beta.7
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 +30 -19
- 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 +18 -17
- package/src/element.ts +7 -1
- package/src/template-system.ts +7 -4
- package/src/utils/index.ts +7 -0
package/src/component.ts
CHANGED
@@ -14,6 +14,7 @@ export const Component = ({ name, module, dependencies, node, templates, signal
|
|
14
14
|
const state = Object.assign({}, scope, model, initialState)
|
15
15
|
const view = module.view? module.view : (data) => data
|
16
16
|
let preserve = []
|
17
|
+
let tick
|
17
18
|
|
18
19
|
const base = {
|
19
20
|
name,
|
@@ -61,7 +62,6 @@ export const Component = ({ name, module, dependencies, node, templates, signal
|
|
61
62
|
}
|
62
63
|
|
63
64
|
const newstate = Object.assign({}, state, scope)
|
64
|
-
|
65
65
|
render(newstate)
|
66
66
|
|
67
67
|
return Promise.resolve(newstate)
|
@@ -101,6 +101,7 @@ export const Component = ({ name, module, dependencies, node, templates, signal
|
|
101
101
|
}
|
102
102
|
node.addEventListener(ev, selectorOrCallback.handler, { signal })
|
103
103
|
}
|
104
|
+
|
104
105
|
},
|
105
106
|
|
106
107
|
off( ev, callback ) {
|
@@ -130,32 +131,32 @@ export const Component = ({ name, module, dependencies, node, templates, signal
|
|
130
131
|
},
|
131
132
|
|
132
133
|
innerHTML ( target, html_ ) {
|
133
|
-
const element = html_? target :
|
134
|
+
const element = html_? target : node
|
134
135
|
const clone = element.cloneNode()
|
135
136
|
const html = html_? html_ : target
|
136
137
|
clone.innerHTML = html
|
137
|
-
|
138
|
-
rAF( _ => Idiomorph.morph(element, clone, IdiomorphOptions) )
|
138
|
+
Promise.resolve(() => Idiomorph.morph(element, clone, IdiomorphOptions))
|
139
139
|
}
|
140
140
|
}
|
141
141
|
|
142
142
|
const render = ( data ) => {
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
143
|
+
clearTimeout( tick )
|
144
|
+
tick = setTimeout(() => {
|
145
|
+
const html = tpl.render.call( view(data), node, safe, g )
|
146
|
+
Idiomorph.morph( node, html, IdiomorphOptions(node) )
|
147
|
+
Promise.resolve().then(() => {
|
148
|
+
node.querySelectorAll('[tplid]')
|
149
|
+
.forEach((element) => {
|
150
|
+
if(!element.base) return
|
151
|
+
element.base.state.protected().forEach( key => delete data[key] )
|
152
|
+
element.base.state.set(data)
|
153
|
+
})
|
154
|
+
Promise.resolve().then(() => g.scope = {})
|
155
|
+
})
|
155
156
|
})
|
156
|
-
|
157
157
|
}
|
158
158
|
|
159
|
+
render( state )
|
159
160
|
node.base = base
|
160
161
|
return module.default( base )
|
161
162
|
}
|
package/src/element.ts
CHANGED
@@ -5,6 +5,8 @@ export const Element = ({ component, templates, start }) => {
|
|
5
5
|
const { name, module, dependencies } = component
|
6
6
|
const abortController = new AbortController()
|
7
7
|
|
8
|
+
let ismounted = false
|
9
|
+
|
8
10
|
return class extends HTMLElement {
|
9
11
|
|
10
12
|
constructor() {
|
@@ -17,6 +19,10 @@ export const Element = ({ component, templates, start }) => {
|
|
17
19
|
start( this.parentNode )
|
18
20
|
}
|
19
21
|
|
22
|
+
if( ismounted ) {
|
23
|
+
return
|
24
|
+
}
|
25
|
+
|
20
26
|
const rtrn = Component({
|
21
27
|
node:this,
|
22
28
|
name,
|
@@ -32,7 +38,7 @@ export const Element = ({ component, templates, start }) => {
|
|
32
38
|
this.dispatchEvent( new CustomEvent(':mount') )
|
33
39
|
}
|
34
40
|
|
35
|
-
|
41
|
+
ismounted = true
|
36
42
|
}
|
37
43
|
|
38
44
|
disconnectedCallback() {
|
package/src/template-system.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { uuid } from './utils'
|
1
|
+
import { uuid, decodeHTML } from './utils'
|
2
2
|
|
3
3
|
const templates = {}
|
4
4
|
|
@@ -31,10 +31,10 @@ export const compile = ( html ) => {
|
|
31
31
|
with( $data ){
|
32
32
|
var output=${parsedHtml
|
33
33
|
.replace(/%%_=(.+?)_%%/g, function(_, variable){
|
34
|
-
return '"+safe(function(){return '+ variable +';})+"'
|
34
|
+
return '"+safe(function(){return '+ decodeHTML(variable) +';})+"'
|
35
35
|
})
|
36
36
|
.replace(/%%_(.+?)_%%/g, function(_, variable){
|
37
|
-
return '";' + variable +'\noutput+="'
|
37
|
+
return '";' + decodeHTML(variable) +'\noutput+="'
|
38
38
|
})};return output;
|
39
39
|
}
|
40
40
|
`)
|
@@ -101,8 +101,11 @@ const transformTemplate = ( clone ) => {
|
|
101
101
|
|
102
102
|
if (htmlIf) {
|
103
103
|
element.removeAttribute('html-if')
|
104
|
+
if( !element.getAttribute('id') ) {
|
105
|
+
element.setAttribute('id', uuid())
|
106
|
+
}
|
104
107
|
const open = document.createTextNode(`%%_ if ( safe(function(){ return ${htmlIf} }) ){ _%%`)
|
105
|
-
const close = document.createTextNode(`%%_ }
|
108
|
+
const close = document.createTextNode(`%%_ } _%%`)
|
106
109
|
wrap(open, element, close)
|
107
110
|
}
|
108
111
|
|
package/src/utils/index.ts
CHANGED
@@ -1,8 +1,15 @@
|
|
1
1
|
|
2
|
+
const textarea = document.createElement('textarea')
|
3
|
+
|
2
4
|
export const g = {
|
3
5
|
scope: {}
|
4
6
|
}
|
5
7
|
|
8
|
+
export const decodeHTML = (text) => {
|
9
|
+
textarea.innerHTML = text
|
10
|
+
return textarea.value
|
11
|
+
}
|
12
|
+
|
6
13
|
export const rAF = (fn) => {
|
7
14
|
if (requestAnimationFrame)
|
8
15
|
return requestAnimationFrame(fn)
|