wallace 0.12.0 → 0.12.2
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/lib/component.js +5 -34
- package/lib/detacher.js +28 -0
- package/lib/index.js +2 -1
- package/lib/repeaters/keyed.js +2 -2
- package/lib/repeaters/keyedFn.js +2 -2
- package/lib/types.d.ts +3 -3
- package/lib/utils.js +5 -10
- package/package.json +3 -3
package/lib/component.js
CHANGED
|
@@ -30,21 +30,12 @@ const ComponentPrototype = {
|
|
|
30
30
|
- add `i = 0, il = this._l` to variable declarator.
|
|
31
31
|
*/
|
|
32
32
|
_u: function (i, il) {
|
|
33
|
-
let watch,
|
|
34
|
-
element,
|
|
35
|
-
parent,
|
|
36
|
-
displayToggle,
|
|
37
|
-
detacher,
|
|
38
|
-
lookupTrue,
|
|
39
|
-
shouldBeVisible,
|
|
40
|
-
detachedElements,
|
|
41
|
-
detachedElement,
|
|
42
|
-
index,
|
|
43
|
-
adjustedIndex;
|
|
33
|
+
let watch, element, displayToggle, detacher, lookupTrue, shouldBeVisible;
|
|
44
34
|
|
|
45
35
|
const watches = this._w,
|
|
46
36
|
props = this.props,
|
|
47
|
-
previous = this._p
|
|
37
|
+
previous = this._p,
|
|
38
|
+
elements = this._e;
|
|
48
39
|
/*
|
|
49
40
|
Watches is an array of objects with keys:
|
|
50
41
|
e: the element index (number)
|
|
@@ -59,15 +50,10 @@ const ComponentPrototype = {
|
|
|
59
50
|
s: the number of watches to skip as their node is underneath
|
|
60
51
|
r: reversed
|
|
61
52
|
?d: detacher
|
|
62
|
-
|
|
63
|
-
The detacher has keys:
|
|
64
|
-
i: the initial element index
|
|
65
|
-
s: the stash key of the detacher (plain object)
|
|
66
|
-
e: the parent element key
|
|
67
53
|
*/
|
|
68
54
|
while (i < il) {
|
|
69
55
|
watch = watches[i];
|
|
70
|
-
element =
|
|
56
|
+
element = elements[watch.e];
|
|
71
57
|
displayToggle = watch.v;
|
|
72
58
|
shouldBeVisible = true;
|
|
73
59
|
if (displayToggle) {
|
|
@@ -75,22 +61,7 @@ const ComponentPrototype = {
|
|
|
75
61
|
shouldBeVisible = displayToggle.r ? lookupTrue : !lookupTrue;
|
|
76
62
|
detacher = displayToggle.d;
|
|
77
63
|
if (detacher) {
|
|
78
|
-
|
|
79
|
-
parent = this._e[detacher.e];
|
|
80
|
-
detachedElements = this._s[detacher.s];
|
|
81
|
-
detachedElement = detachedElements[index];
|
|
82
|
-
if (shouldBeVisible && detachedElement) {
|
|
83
|
-
adjustedIndex =
|
|
84
|
-
index -
|
|
85
|
-
Object.keys(detachedElements).filter(function (k) {
|
|
86
|
-
return k < index && detachedElements[k];
|
|
87
|
-
}).length;
|
|
88
|
-
parent.insertBefore(detachedElement, parent.childNodes[adjustedIndex]);
|
|
89
|
-
detachedElements[index] = null;
|
|
90
|
-
} else if (!shouldBeVisible && !detachedElement) {
|
|
91
|
-
parent.removeChild(element);
|
|
92
|
-
detachedElements[index] = element;
|
|
93
|
-
}
|
|
64
|
+
detacher.apply(element, shouldBeVisible, elements, this._s);
|
|
94
65
|
} else {
|
|
95
66
|
element.hidden = !shouldBeVisible;
|
|
96
67
|
}
|
package/lib/detacher.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deals with conditionally detaching elements with the if directive.
|
|
3
|
+
*/
|
|
4
|
+
export function Detacher(i, e, s) {
|
|
5
|
+
this.i = i; // the initial element index.
|
|
6
|
+
this.e = e; // the stash key of the map of detached nodes.
|
|
7
|
+
this.s = s; // the parent element key.
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
Detacher.prototype.apply = function (element, shouldBeVisible, elements, stash) {
|
|
11
|
+
let adjustedIndex;
|
|
12
|
+
const index = this.i,
|
|
13
|
+
parent = elements[this.e],
|
|
14
|
+
detachedElements = stash[this.s],
|
|
15
|
+
detachedElement = detachedElements[index];
|
|
16
|
+
if (shouldBeVisible && detachedElement) {
|
|
17
|
+
adjustedIndex =
|
|
18
|
+
index -
|
|
19
|
+
Object.keys(detachedElements).filter(function (k) {
|
|
20
|
+
return k < index && detachedElements[k];
|
|
21
|
+
}).length;
|
|
22
|
+
parent.insertBefore(detachedElement, parent.childNodes[adjustedIndex]);
|
|
23
|
+
detachedElements[index] = null;
|
|
24
|
+
} else if (!shouldBeVisible && !detachedElement) {
|
|
25
|
+
parent.removeChild(element);
|
|
26
|
+
detachedElements[index] = element;
|
|
27
|
+
}
|
|
28
|
+
};
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { defineComponent } from "./component";
|
|
2
|
+
export { Detacher } from "./detacher";
|
|
2
3
|
export { extendComponent } from "./extend";
|
|
3
4
|
export { mount } from "./mount";
|
|
4
5
|
export { createComponent } from "./createComponent";
|
|
@@ -10,5 +11,5 @@ export { KeyedFnRepeater } from "./repeaters/keyedFn";
|
|
|
10
11
|
export { SequentialRepeater } from "./repeaters/sequential";
|
|
11
12
|
export { Router, route } from "./router";
|
|
12
13
|
export { getStub } from "./stubs";
|
|
13
|
-
export { findElement, onEvent
|
|
14
|
+
export { findElement, onEvent } from "./utils";
|
|
14
15
|
export { watch, protect } from "./watch";
|
package/lib/repeaters/keyed.js
CHANGED
|
@@ -30,7 +30,8 @@ KeyedRepeater.prototype.patch = function (e, items, ctrl) {
|
|
|
30
30
|
previousKeys = this.keys,
|
|
31
31
|
previousKeysLength = previousKeys.length,
|
|
32
32
|
newKeys = [],
|
|
33
|
-
previousKeysSet = new Set(previousKeys)
|
|
33
|
+
previousKeysSet = new Set(previousKeys),
|
|
34
|
+
frag = document.createDocumentFragment();
|
|
34
35
|
let item,
|
|
35
36
|
el,
|
|
36
37
|
key,
|
|
@@ -43,7 +44,6 @@ KeyedRepeater.prototype.patch = function (e, items, ctrl) {
|
|
|
43
44
|
i = itemsLength - 1;
|
|
44
45
|
|
|
45
46
|
// Working backwards saves us having to track moves.
|
|
46
|
-
const frag = document.createDocumentFragment();
|
|
47
47
|
while (i >= 0) {
|
|
48
48
|
item = items[i];
|
|
49
49
|
key = item[keyName];
|
package/lib/repeaters/keyedFn.js
CHANGED
|
@@ -30,7 +30,8 @@ KeyedFnRepeater.prototype.patch = function (e, items, ctrl) {
|
|
|
30
30
|
previousKeys = this.keys,
|
|
31
31
|
previousKeysLength = previousKeys.length,
|
|
32
32
|
newKeys = [],
|
|
33
|
-
previousKeysSet = new Set(previousKeys)
|
|
33
|
+
previousKeysSet = new Set(previousKeys),
|
|
34
|
+
frag = document.createDocumentFragment();
|
|
34
35
|
let item,
|
|
35
36
|
el,
|
|
36
37
|
key,
|
|
@@ -43,7 +44,6 @@ KeyedFnRepeater.prototype.patch = function (e, items, ctrl) {
|
|
|
43
44
|
i = itemsLength - 1;
|
|
44
45
|
|
|
45
46
|
// Working backwards saves us having to track moves.
|
|
46
|
-
const frag = document.createDocumentFragment();
|
|
47
47
|
while (i >= 0) {
|
|
48
48
|
item = items[i];
|
|
49
49
|
key = keyFn(item);
|
package/lib/types.d.ts
CHANGED
|
@@ -887,7 +887,7 @@ interface DirectiveAttributes extends AllDomEvents {
|
|
|
887
887
|
/**
|
|
888
888
|
* ## Wallace directive: class
|
|
889
889
|
*
|
|
890
|
-
* Without a
|
|
890
|
+
* Without a qualifier this acts as a normal attribute:
|
|
891
891
|
*
|
|
892
892
|
* ```
|
|
893
893
|
* <div class={foo} ></div>
|
|
@@ -915,10 +915,10 @@ interface DirectiveAttributes extends AllDomEvents {
|
|
|
915
915
|
/**
|
|
916
916
|
* ## Wallace directive: ctrl
|
|
917
917
|
*
|
|
918
|
-
* Specifies ctrl for nested
|
|
918
|
+
* Specifies alternative `ctrl` for nested or repeated components.
|
|
919
919
|
*
|
|
920
920
|
* ```
|
|
921
|
-
* <MyComponent.nest ctrl={
|
|
921
|
+
* <MyComponent.nest ctrl={altController} />
|
|
922
922
|
* ```
|
|
923
923
|
*/
|
|
924
924
|
ctrl?: any;
|
package/lib/utils.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
export function findElement(rootElement, path) {
|
|
2
|
-
|
|
2
|
+
let node = rootElement;
|
|
3
|
+
for (let i = 0; i < path.length; i++) {
|
|
4
|
+
node = node.childNodes[path[i]];
|
|
5
|
+
}
|
|
6
|
+
return node;
|
|
3
7
|
}
|
|
4
8
|
|
|
5
9
|
export function replaceNode(nodeToReplace, newNode) {
|
|
6
10
|
nodeToReplace.parentNode.replaceChild(newNode, nodeToReplace);
|
|
7
11
|
}
|
|
8
12
|
|
|
9
|
-
/**
|
|
10
|
-
* Stash something on the component. Returns the element.
|
|
11
|
-
* The generated code is expected to keep track of the position.
|
|
12
|
-
*/
|
|
13
|
-
export function stashMisc(element, stash, object) {
|
|
14
|
-
stash.push(object);
|
|
15
|
-
return element;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
13
|
export function onEvent(element, eventName, callback) {
|
|
19
14
|
element.addEventListener(eventName, callback);
|
|
20
15
|
return element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wallace",
|
|
3
|
-
"version": "0.12.
|
|
3
|
+
"version": "0.12.2",
|
|
4
4
|
"author": "Andrew Buchan",
|
|
5
5
|
"description": "An insanely small, fast, intuitive and extendable front-end framework",
|
|
6
6
|
"homepage": "https://wallace.js.org",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"test": "jest --clearCache && jest"
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"babel-plugin-wallace": "^0.12.
|
|
18
|
+
"babel-plugin-wallace": "^0.12.2",
|
|
19
19
|
"browserify": "^17.0.1"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "7625a9b2fb654b6007a7ae97388a8c98995a49fe"
|
|
22
22
|
}
|