wallace 0.0.2 → 0.0.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/LICENSE.md +1 -1
- package/lib/component.js +77 -0
- package/lib/index.js +33 -0
- package/lib/initCalls.js +110 -0
- package/lib/lookup.js +61 -0
- package/lib/pool.js +155 -0
- package/lib/types.d.ts +48 -0
- package/lib/utils.js +49 -0
- package/package.json +12 -28
- package/README.md +0 -3
- package/dist/wallace.js +0 -836
- package/src/component.js +0 -372
- package/src/helpers.js +0 -16
- package/src/index.js +0 -18
- package/src/lookup.js +0 -38
- package/src/mountie.js +0 -23
- package/src/pool.js +0 -173
- package/src/utils.js +0 -64
- package/src/wrapper.js +0 -149
package/src/wrapper.js
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import {doc} from './helpers'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* A wrapper around a DOM element.
|
|
6
|
-
* All transformative methods return this (except transitions as they return promises)
|
|
7
|
-
* This means those methods can be chained.
|
|
8
|
-
*/
|
|
9
|
-
export function Wrapper(element) {
|
|
10
|
-
this.e = element
|
|
11
|
-
this._pool = undefined
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
Wrapper.prototype = {
|
|
15
|
-
/**
|
|
16
|
-
* Get element as 'e' from item, else return text node.
|
|
17
|
-
*/
|
|
18
|
-
__ge: function(item) {
|
|
19
|
-
return item.e || doc.createTextNode(item)
|
|
20
|
-
},
|
|
21
|
-
/**
|
|
22
|
-
* Gets an attribute from the element. Cannot be chained.
|
|
23
|
-
*/
|
|
24
|
-
getAtt: function(name) {
|
|
25
|
-
return this.e[name]
|
|
26
|
-
},
|
|
27
|
-
/**
|
|
28
|
-
* Gets the element's value. Cannot be chained.
|
|
29
|
-
*/
|
|
30
|
-
getValue: function() {
|
|
31
|
-
return this.e.value
|
|
32
|
-
},
|
|
33
|
-
isChecked: function() {
|
|
34
|
-
return this.e.checked
|
|
35
|
-
},
|
|
36
|
-
/* Every method below must return 'this' so it can be chained */
|
|
37
|
-
append: function(item) {
|
|
38
|
-
this.e.appendChild(this.__ge(item))
|
|
39
|
-
return this
|
|
40
|
-
},
|
|
41
|
-
att: function(name, value) {
|
|
42
|
-
this.e[name] = value
|
|
43
|
-
return this
|
|
44
|
-
},
|
|
45
|
-
pool: function(pool) {
|
|
46
|
-
this._pool = pool
|
|
47
|
-
return this
|
|
48
|
-
},
|
|
49
|
-
clear: function() {
|
|
50
|
-
this.e.innerHTML = ''
|
|
51
|
-
this.e.textContent = ''
|
|
52
|
-
this.e.value = ''
|
|
53
|
-
return this
|
|
54
|
-
},
|
|
55
|
-
checked: function(value) {
|
|
56
|
-
this.e.checked = !!value
|
|
57
|
-
return this
|
|
58
|
-
},
|
|
59
|
-
child: function(wrapper) {
|
|
60
|
-
this.e.innerHTML = ''
|
|
61
|
-
this.e.appendChild(wrapper.e)
|
|
62
|
-
return this
|
|
63
|
-
},
|
|
64
|
-
css: function(style) {
|
|
65
|
-
this.e.className = style
|
|
66
|
-
return this
|
|
67
|
-
},
|
|
68
|
-
cssAdd: function(style) {
|
|
69
|
-
this.e.classList.add(style)
|
|
70
|
-
return this
|
|
71
|
-
},
|
|
72
|
-
cssRemove: function(style) {
|
|
73
|
-
this.e.classList.remove(style)
|
|
74
|
-
return this
|
|
75
|
-
},
|
|
76
|
-
cssToggle: function(style) {
|
|
77
|
-
this.e.classList.toggle(style)
|
|
78
|
-
return this
|
|
79
|
-
},
|
|
80
|
-
disabled: function(disabled) {
|
|
81
|
-
this.e.disabled = disabled
|
|
82
|
-
return this
|
|
83
|
-
},
|
|
84
|
-
href: function(value) {
|
|
85
|
-
return this.att('href', value)
|
|
86
|
-
},
|
|
87
|
-
html: function(html) {
|
|
88
|
-
this.e.innerHTML = html
|
|
89
|
-
return this
|
|
90
|
-
},
|
|
91
|
-
id: function(value) {
|
|
92
|
-
return this.att('id', value)
|
|
93
|
-
},
|
|
94
|
-
/*
|
|
95
|
-
* Set inner as individual item or array. Not optimised.
|
|
96
|
-
*/
|
|
97
|
-
inner: function(items) {
|
|
98
|
-
if (!Array.isArray(items)) {
|
|
99
|
-
items = [items]
|
|
100
|
-
}
|
|
101
|
-
const e = this.e
|
|
102
|
-
e.innerHTML = ''
|
|
103
|
-
for (var i=0, il=items.length; i<il; i++) {
|
|
104
|
-
e.appendChild(this.__ge(items[i]))
|
|
105
|
-
}
|
|
106
|
-
return this
|
|
107
|
-
},
|
|
108
|
-
/*
|
|
109
|
-
* Set items from pool.
|
|
110
|
-
*/
|
|
111
|
-
items: function(items, parent) {
|
|
112
|
-
this._pool.patch(this.e, items, parent)
|
|
113
|
-
return this
|
|
114
|
-
},
|
|
115
|
-
on: function(event, callback) {
|
|
116
|
-
this.e.addEventListener(event, e => callback(this, e))
|
|
117
|
-
return this
|
|
118
|
-
},
|
|
119
|
-
replace: function(el) {
|
|
120
|
-
this.e.parentNode.replaceChild(el, this.e)
|
|
121
|
-
return this
|
|
122
|
-
},
|
|
123
|
-
src: function(value) {
|
|
124
|
-
return this.att('src', value)
|
|
125
|
-
},
|
|
126
|
-
style: function(value, name) {
|
|
127
|
-
this.e.style[name] = value
|
|
128
|
-
return this
|
|
129
|
-
},
|
|
130
|
-
swap: function(key, parent) {
|
|
131
|
-
this.child(this._pool.getOne(key, parent))
|
|
132
|
-
return this
|
|
133
|
-
},
|
|
134
|
-
text: function(value) {
|
|
135
|
-
this.e.textContent = value
|
|
136
|
-
return this
|
|
137
|
-
},
|
|
138
|
-
hidden: function(value) {
|
|
139
|
-
// TODO: fix this - it works in browser, is it just tests?
|
|
140
|
-
this.e.classList.toggle('hidden', value)
|
|
141
|
-
// console.log('hidden', value)
|
|
142
|
-
// this.e.hidden = !value
|
|
143
|
-
return this
|
|
144
|
-
},
|
|
145
|
-
value: function(value) {
|
|
146
|
-
this.e.value = value
|
|
147
|
-
return this
|
|
148
|
-
}
|
|
149
|
-
}
|