jails-js 6.0.1-beta.4 → 6.0.1-beta.6

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.
@@ -1,4 +1,4 @@
1
- import { uuid } from './utils'
1
+ import { uuid, decodeHTML } 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 = ( outerHTML ) => {
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',`
@@ -32,10 +31,10 @@ export const compile = ( outerHTML ) => {
32
31
  with( $data ){
33
32
  var output=${parsedHtml
34
33
  .replace(/%%_=(.+?)_%%/g, function(_, variable){
35
- return '"+safe(function(){return '+ variable +';})+"'
34
+ return '"+safe(function(){return '+ decodeHTML(variable) +';})+"'
36
35
  })
37
36
  .replace(/%%_(.+?)_%%/g, function(_, variable){
38
- return '";' + variable +'\noutput+="'
37
+ return '";' + decodeHTML(variable) +'\noutput+="'
39
38
  })};return output;
40
39
  }
41
40
  `)
@@ -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 === 'scope-id' ) {
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 = htmlFor.match(/(.*)\sin\s(.*)/) || ''
94
- const varname = split[1]
95
- const object = split[2]
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] = { ${varname} :${varname}, ${object}: ${object}, $index: $index, $key: $key }; _%%`)
97
- const close = document.createTextNode(`%%_ $index++; } })() _%%`)
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-scope-id', 'jails___scope-id')
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,
@@ -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)