jails-js 5.0.0-beta.7 → 5.0.0

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,87 +0,0 @@
1
- import sodajs from 'sodajs'
2
-
3
- export const setSodaConfig = () => {
4
-
5
- sodajs.prefix('v-')
6
-
7
- sodajs.directive('repeat', {
8
-
9
- priority: 10,
10
-
11
- link({ scope, el, expression, getValue, compileNode }) {
12
-
13
- let itemName
14
- let valueName
15
- let trackName
16
-
17
- const trackReg = /\s+by\s+([^\s]+)$/
18
- const inReg = /([^\s]+)\s+in\s+([^\s]+)|\(([^,]+)\s*,\s*([^)]+)\)\s+in\s+([^\s]+)/
19
-
20
- const opt = expression.replace(trackReg, (item, $1) => {
21
- if ($1)
22
- trackName = ($1 || '').trim()
23
- return ''
24
- })
25
-
26
- const r = inReg.exec(opt)
27
-
28
- if (r) {
29
- if (r[1] && r[2]) {
30
- itemName = (r[1] || '').trim()
31
- valueName = (r[2] || '').trim()
32
-
33
- if (!(itemName && valueName)) {
34
- return
35
- }
36
- } else if (r[3] && r[4] && r[5]) {
37
- trackName = (r[3] || '').trim()
38
- itemName = (r[4] || '').trim()
39
- valueName = (r[5] || '').trim()
40
- }
41
- } else {
42
- return
43
- }
44
-
45
- trackName = trackName || '$index'
46
-
47
- const repeatObj = getValue(scope, valueName) || []
48
-
49
- const repeatFunc = (i) => {
50
-
51
- const itemNode = el.cloneNode(true)
52
- const itemScope = Object.create(scope)
53
-
54
- itemScope[trackName] = i
55
- itemScope[itemName] = repeatObj[i]
56
-
57
- itemNode.removeAttribute(`${this._prefix}repeat`)
58
-
59
- el.parentNode.insertBefore(itemNode, el)
60
-
61
- Array.from(itemNode.querySelectorAll('[data-component]'))
62
- .forEach( node => node.setAttribute('data-initial-state', JSON.stringify(itemScope)) )
63
-
64
- compileNode(itemNode, itemScope)
65
- }
66
-
67
- if ('length' in repeatObj) {
68
- for (var i = 0; i < repeatObj.length; i++) {
69
- repeatFunc(i)
70
- }
71
- } else {
72
- for (var i in repeatObj) {
73
- if (repeatObj.hasOwnProperty(i)) {
74
- repeatFunc(i)
75
- }
76
- }
77
- }
78
-
79
- el.parentNode.removeChild(el)
80
-
81
- if (el.childNodes && el.childNodes.length)
82
- el.innerHTML = ''
83
- }
84
- })
85
-
86
- return sodajs
87
- }
@@ -1,41 +0,0 @@
1
-
2
- export const rAF = (fn) => {
3
- (requestAnimationFrame || setTimeout)(fn, 1000 / 60)
4
- }
5
-
6
- export const uuid = () => {
7
- return 'xxxxxxxx'.replace(/[xy]/g, (c) => {
8
- const r = Math.random() * 8 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8)
9
- return v.toString(8)
10
- })
11
- }
12
-
13
- export const stripTemplateTag = ( element ) => {
14
- const templates = Array.from(element.querySelectorAll('template'))
15
- // https://gist.github.com/harmenjanssen/07e425248779c65bc5d11b02fb913274
16
- templates.forEach( template => {
17
- template.parentNode.replaceChild(template.content, template )
18
- })
19
- }
20
-
21
- export const dup = (o) => {
22
- return JSON.parse( JSON.stringify(o) )
23
- }
24
-
25
- export const createTemplate = ( html, templates ) => {
26
-
27
- const vroot = document.createElement('div')
28
- vroot.innerHTML = html
29
- stripTemplateTag( vroot )
30
-
31
- Array
32
- .from(vroot.querySelectorAll('[data-component]'))
33
- .forEach( c => {
34
- const tplid = c.getAttribute('tplid')
35
- const cache = templates[tplid]
36
- if( cache )
37
- c.outerHTML = cache
38
- })
39
-
40
- return vroot.innerHTML
41
- }
@@ -1,25 +0,0 @@
1
- const topics = {}
2
- const _async = {}
3
-
4
- export const publish = (name, params) => {
5
- _async[name] = Object.assign({}, _async[name], params)
6
- if( topics[name] )
7
- topics[name].forEach(topic => topic(params))
8
- }
9
-
10
- export const subscribe = (name, method) => {
11
- topics[name] = topics[name] || []
12
- topics[name].push(method)
13
- if ( name in _async ) {
14
- method(_async[name])
15
- }
16
- }
17
-
18
- export const unsubscribe = (topic) => {
19
- topics[topic.name] = (topics[topic.name] || [])
20
- .filter(t => t != topic.method)
21
- if (!topics[topic.name].length) {
22
- delete topics[topic.name]
23
- delete _async[topic.name]
24
- }
25
- }