wallace 0.13.0 → 0.14.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.
- package/lib/detacher.js +8 -9
- package/lib/index.js +1 -0
- package/lib/offsetter.js +2 -2
- package/lib/repeaters/keyed.js +36 -24
- package/lib/repeaters/sequential.js +25 -17
- package/lib/toDateString.js +1 -0
- package/lib/types.d.ts +25 -27
- package/lib/watch.js +8 -4
- package/package.json +3 -3
package/lib/detacher.js
CHANGED
|
@@ -9,18 +9,17 @@ export function Detacher(i, e, s) {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
Detacher.prototype.apply = function (element, shouldBeVisible, elements, stash) {
|
|
12
|
-
let adjustedIndex;
|
|
13
12
|
const index = this.i,
|
|
14
13
|
parent = elements[this.e],
|
|
15
|
-
|
|
16
|
-
let
|
|
17
|
-
if (shouldBeVisible &&
|
|
18
|
-
adjustedIndex = countOffset(
|
|
14
|
+
offsetTracker = stash[this.s];
|
|
15
|
+
let ownOffset = offsetTracker.get(index) || 0;
|
|
16
|
+
if (shouldBeVisible && ownOffset === -1) {
|
|
17
|
+
const adjustedIndex = countOffset(offsetTracker, index);
|
|
19
18
|
parent.insertBefore(element, parent.childNodes[adjustedIndex]);
|
|
20
|
-
|
|
21
|
-
} else if (!shouldBeVisible &&
|
|
19
|
+
ownOffset = 0;
|
|
20
|
+
} else if (!shouldBeVisible && ownOffset === 0) {
|
|
22
21
|
parent.removeChild(element);
|
|
23
|
-
|
|
22
|
+
ownOffset = -1;
|
|
24
23
|
}
|
|
25
|
-
|
|
24
|
+
offsetTracker.set(index, ownOffset);
|
|
26
25
|
};
|
package/lib/index.js
CHANGED
|
@@ -10,5 +10,6 @@ export { KeyedRepeater } from "./repeaters/keyed";
|
|
|
10
10
|
export { SequentialRepeater } from "./repeaters/sequential";
|
|
11
11
|
export { Router, route } from "./router";
|
|
12
12
|
export { getStub } from "./stubs";
|
|
13
|
+
export { toDateString } from "./toDateString";
|
|
13
14
|
export { findElement, onEvent } from "./utils";
|
|
14
15
|
export { watch, protect } from "./watch";
|
package/lib/offsetter.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export function countOffset(
|
|
1
|
+
export function countOffset(offsetTracker, index) {
|
|
2
2
|
let offset = 0;
|
|
3
|
-
for (let [key, value] of
|
|
3
|
+
for (let [key, value] of offsetTracker.entries()) {
|
|
4
4
|
if (key >= index) break;
|
|
5
5
|
offset += value;
|
|
6
6
|
}
|
package/lib/repeaters/keyed.js
CHANGED
|
@@ -6,18 +6,24 @@ import { countOffset } from "../offsetter";
|
|
|
6
6
|
* COMPILER_MODS:
|
|
7
7
|
* if allowRepeaterSiblings is false the last two parameters are removed.
|
|
8
8
|
*/
|
|
9
|
-
export function KeyedRepeater(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
this.
|
|
9
|
+
export function KeyedRepeater(
|
|
10
|
+
componentDefinition,
|
|
11
|
+
pool,
|
|
12
|
+
key,
|
|
13
|
+
adjustmentTracker,
|
|
14
|
+
initialIndex
|
|
15
|
+
) {
|
|
16
|
+
this.d = componentDefinition;
|
|
17
|
+
this.k = []; // array of keys as last set.
|
|
18
|
+
this.p = pool; // pool of component instances. Must be a Map.
|
|
17
19
|
if (typeof key === "function") {
|
|
18
|
-
this.
|
|
20
|
+
this.f = key;
|
|
19
21
|
} else {
|
|
20
|
-
this.
|
|
22
|
+
this.n = key;
|
|
23
|
+
}
|
|
24
|
+
if (wallaceConfig.flags.allowRepeaterSiblings) {
|
|
25
|
+
this.a = adjustmentTracker;
|
|
26
|
+
this.i = initialIndex;
|
|
21
27
|
}
|
|
22
28
|
}
|
|
23
29
|
|
|
@@ -30,24 +36,25 @@ export function KeyedRepeater(componentDefinition, key, adjustmentTracker, initi
|
|
|
30
36
|
* @param {any} ctrl - The parent item's controller.
|
|
31
37
|
*/
|
|
32
38
|
KeyedRepeater.prototype.patch = function (e, items, ctrl) {
|
|
33
|
-
const pool = this.
|
|
34
|
-
componentDefinition = this.
|
|
35
|
-
keyName = this.
|
|
36
|
-
keyFn = this.
|
|
39
|
+
const pool = this.p,
|
|
40
|
+
componentDefinition = this.d,
|
|
41
|
+
keyName = this.n,
|
|
42
|
+
keyFn = this.f,
|
|
43
|
+
useKeyName = keyName !== undefined,
|
|
37
44
|
childNodes = e.childNodes,
|
|
38
45
|
itemsLength = items.length,
|
|
39
|
-
previousKeys = this.
|
|
46
|
+
previousKeys = this.k,
|
|
40
47
|
previousKeysLength = previousKeys.length,
|
|
41
48
|
newKeys = [],
|
|
42
49
|
previousKeysSet = new Set(previousKeys),
|
|
43
|
-
adjustmentTracker = this.at,
|
|
44
|
-
initialIndex = this.ii,
|
|
45
50
|
frag = document.createDocumentFragment();
|
|
46
51
|
|
|
47
52
|
let item,
|
|
48
53
|
el,
|
|
49
54
|
itemKey,
|
|
50
55
|
component,
|
|
56
|
+
initialIndex,
|
|
57
|
+
offsetTracker,
|
|
51
58
|
endAnchor = null,
|
|
52
59
|
adjustment = 0,
|
|
53
60
|
anchor = null,
|
|
@@ -58,8 +65,10 @@ KeyedRepeater.prototype.patch = function (e, items, ctrl) {
|
|
|
58
65
|
i = itemsLength - 1;
|
|
59
66
|
|
|
60
67
|
if (wallaceConfig.flags.allowRepeaterSiblings) {
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
offsetTracker = this.a;
|
|
69
|
+
initialIndex = this.i;
|
|
70
|
+
if (offsetTracker) {
|
|
71
|
+
adjustment = countOffset(offsetTracker, initialIndex);
|
|
63
72
|
endAnchor = childNodes[previousKeysLength + adjustment] || null;
|
|
64
73
|
anchor = endAnchor;
|
|
65
74
|
untouched = false;
|
|
@@ -69,8 +78,11 @@ KeyedRepeater.prototype.patch = function (e, items, ctrl) {
|
|
|
69
78
|
// Working backwards saves us having to track moves.
|
|
70
79
|
while (i >= 0) {
|
|
71
80
|
item = items[i];
|
|
72
|
-
itemKey =
|
|
73
|
-
component = pool
|
|
81
|
+
itemKey = useKeyName ? item[keyName] : keyFn(item);
|
|
82
|
+
if (!(component = pool.get(itemKey))) {
|
|
83
|
+
component = new componentDefinition();
|
|
84
|
+
pool.set(itemKey, component);
|
|
85
|
+
}
|
|
74
86
|
component.render(item, ctrl);
|
|
75
87
|
el = component.el;
|
|
76
88
|
if (untouched && !previousKeysSet.has(itemKey)) {
|
|
@@ -100,11 +112,11 @@ KeyedRepeater.prototype.patch = function (e, items, ctrl) {
|
|
|
100
112
|
toStrip--;
|
|
101
113
|
}
|
|
102
114
|
|
|
103
|
-
this.
|
|
115
|
+
this.k = newKeys.reverse();
|
|
104
116
|
|
|
105
117
|
if (wallaceConfig.flags.allowRepeaterSiblings) {
|
|
106
|
-
if (
|
|
107
|
-
|
|
118
|
+
if (offsetTracker) {
|
|
119
|
+
offsetTracker.set(initialIndex, itemsLength - 1);
|
|
108
120
|
}
|
|
109
121
|
}
|
|
110
122
|
};
|
|
@@ -6,14 +6,19 @@ import { countOffset } from "../offsetter";
|
|
|
6
6
|
* COMPILER_MODS:
|
|
7
7
|
* if allowRepeaterSiblings is false the last two parameters are removed.
|
|
8
8
|
*/
|
|
9
|
-
export function SequentialRepeater(
|
|
10
|
-
|
|
9
|
+
export function SequentialRepeater(
|
|
10
|
+
componentDefinition,
|
|
11
|
+
pool,
|
|
12
|
+
adjustmentTracker,
|
|
13
|
+
initialIndex
|
|
14
|
+
) {
|
|
15
|
+
this.d = componentDefinition;
|
|
16
|
+
this.p = pool; // pool of component instances. Must be an Array.
|
|
17
|
+
this.c = 0; // Child count
|
|
11
18
|
if (wallaceConfig.flags.allowRepeaterSiblings) {
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
19
|
+
this.a = adjustmentTracker;
|
|
20
|
+
this.i = initialIndex;
|
|
14
21
|
}
|
|
15
|
-
this.pool = []; // pool of component instances
|
|
16
|
-
this.cc = 0; // Child count
|
|
17
22
|
}
|
|
18
23
|
|
|
19
24
|
/**
|
|
@@ -25,24 +30,27 @@ export function SequentialRepeater(componentDefinition, adjustmentTracker, initi
|
|
|
25
30
|
* @param {any} ctrl - The parent item's controller.
|
|
26
31
|
*/
|
|
27
32
|
SequentialRepeater.prototype.patch = function (parent, items, ctrl) {
|
|
28
|
-
const pool = this.
|
|
29
|
-
componentDefinition = this.
|
|
30
|
-
|
|
33
|
+
const pool = this.p,
|
|
34
|
+
componentDefinition = this.d,
|
|
35
|
+
previousChildCount = this.c,
|
|
31
36
|
itemsLength = items.length,
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
adjustmentTracker = this.at;
|
|
37
|
+
childNodes = parent.childNodes;
|
|
38
|
+
|
|
35
39
|
let i = 0,
|
|
36
40
|
offset = 0,
|
|
37
41
|
component,
|
|
38
42
|
nextElement,
|
|
43
|
+
initialIndex,
|
|
44
|
+
offsetTracker,
|
|
39
45
|
endOfRange = previousChildCount,
|
|
40
46
|
poolCount = pool.length;
|
|
41
47
|
|
|
42
48
|
if (wallaceConfig.flags.allowRepeaterSiblings) {
|
|
43
|
-
|
|
49
|
+
initialIndex = this.i;
|
|
50
|
+
offsetTracker = this.a;
|
|
51
|
+
if (offsetTracker) {
|
|
44
52
|
// The repeat element has siblings
|
|
45
|
-
offset = countOffset(
|
|
53
|
+
offset = countOffset(offsetTracker, initialIndex);
|
|
46
54
|
endOfRange += offset;
|
|
47
55
|
nextElement = childNodes[endOfRange] || null;
|
|
48
56
|
}
|
|
@@ -61,7 +69,7 @@ SequentialRepeater.prototype.patch = function (parent, items, ctrl) {
|
|
|
61
69
|
}
|
|
62
70
|
i++;
|
|
63
71
|
}
|
|
64
|
-
this.
|
|
72
|
+
this.c = itemsLength;
|
|
65
73
|
|
|
66
74
|
let removeAtIndex = offset + previousChildCount - 1;
|
|
67
75
|
const stopatIndex = offset + itemsLength - 1;
|
|
@@ -69,8 +77,8 @@ SequentialRepeater.prototype.patch = function (parent, items, ctrl) {
|
|
|
69
77
|
parent.removeChild(childNodes[i]);
|
|
70
78
|
}
|
|
71
79
|
if (wallaceConfig.flags.allowRepeaterSiblings) {
|
|
72
|
-
if (
|
|
73
|
-
|
|
80
|
+
if (offsetTracker) {
|
|
81
|
+
offsetTracker.set(initialIndex, itemsLength - 1);
|
|
74
82
|
}
|
|
75
83
|
}
|
|
76
84
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const toDateString = date => date.toISOString().slice(0, 10);
|
package/lib/types.d.ts
CHANGED
|
@@ -529,7 +529,8 @@ performance and bundle size:
|
|
|
529
529
|
2. allowCtrl - enables use of `ctrl` in components.
|
|
530
530
|
3. allowMethods - adds the `methods` helper to components.
|
|
531
531
|
4. allowParts - enables use of parts.
|
|
532
|
-
5.
|
|
532
|
+
5. allowRepeaterSiblings - allows repeaters to have siblings.
|
|
533
|
+
6. allowStubs - enables the use of stubs.
|
|
533
534
|
|
|
534
535
|
These flags default to true, unless you specify `flags` in the plugin config, in which
|
|
535
536
|
case they default to false and you need to explicitly enable those you want:
|
|
@@ -840,46 +841,29 @@ interface DirectiveAttributes extends AllDomEvents {
|
|
|
840
841
|
/**
|
|
841
842
|
* ## Wallace directive: bind
|
|
842
843
|
*
|
|
843
|
-
* Sets up two
|
|
844
|
-
*
|
|
845
|
-
* 1. It uses the expression as the element's value.
|
|
846
|
-
* 2. It assigns the value back to the expression when the element's `change` event
|
|
847
|
-
* fires.
|
|
848
|
-
*
|
|
849
|
-
* So this:
|
|
844
|
+
* Sets up two way binding between an input and data:
|
|
850
845
|
*
|
|
851
846
|
* ```
|
|
852
|
-
*
|
|
853
|
-
* <input type="text" bind={name}/>
|
|
854
|
-
* );
|
|
847
|
+
* <input type="text" bind={name} />
|
|
855
848
|
* ```
|
|
856
849
|
*
|
|
857
850
|
* Is the equivalent of this:
|
|
858
851
|
*
|
|
859
|
-
*```
|
|
860
|
-
* const MyComponent = ({name}, {event}) => (
|
|
861
|
-
* <input type="text" onChange={name = event.target.value} value={name}/>
|
|
862
|
-
* );
|
|
863
852
|
* ```
|
|
864
|
-
*
|
|
865
|
-
*
|
|
853
|
+
* <input type="text" value={name} onChange={name = event.target.value} />
|
|
854
|
+
* ```
|
|
855
|
+
* By default it watches the `change` event, but you can specify a different one using
|
|
856
|
+
* the `event` directive:
|
|
866
857
|
*
|
|
867
858
|
* ```
|
|
868
|
-
*
|
|
869
|
-
* <input type="checkbox" onChange={done = event.target.checked} checked={done}/>
|
|
870
|
-
* );
|
|
859
|
+
* <input type="text" bind={name} event:keyup />
|
|
871
860
|
* ```
|
|
872
861
|
*
|
|
873
|
-
* By
|
|
862
|
+
* By default it binds to `value` but you can set a different property:
|
|
874
863
|
*
|
|
875
864
|
*```
|
|
876
|
-
*
|
|
877
|
-
* <input type="text" bind:KeyUp={name} />
|
|
878
|
-
* );
|
|
865
|
+
* <input type="number" bind:valueAsNumber={name} />
|
|
879
866
|
* ```
|
|
880
|
-
*
|
|
881
|
-
* Note that destructured props are converted to member expressions, so these examples
|
|
882
|
-
* work even though it looks like you're setting a local variable.
|
|
883
867
|
*/
|
|
884
868
|
bind?: MustBeExpression;
|
|
885
869
|
|
|
@@ -922,6 +906,19 @@ interface DirectiveAttributes extends AllDomEvents {
|
|
|
922
906
|
*/
|
|
923
907
|
ctrl?: any;
|
|
924
908
|
|
|
909
|
+
/**
|
|
910
|
+
* ## Wallace directive: event
|
|
911
|
+
*
|
|
912
|
+
*
|
|
913
|
+
* Must be used with the `bind` directive, and causes it do watch a different event
|
|
914
|
+
* (the default is `change`)
|
|
915
|
+
*
|
|
916
|
+
* ```
|
|
917
|
+
* <input type="text" bind={name} event:keyup />
|
|
918
|
+
* ```
|
|
919
|
+
*/
|
|
920
|
+
event?: string;
|
|
921
|
+
|
|
925
922
|
/**
|
|
926
923
|
* ## Wallace directive: fixed
|
|
927
924
|
*
|
|
@@ -1085,6 +1082,7 @@ declare namespace JSX {
|
|
|
1085
1082
|
* - `class:xyz` defines a set of classes to be toggled.
|
|
1086
1083
|
* - `css` shorthand for `fixed:class`.
|
|
1087
1084
|
* - `ctrl` specifies ctrl for nested/repeated components.
|
|
1085
|
+
* - `event` changes the event which `bind` reacts to.
|
|
1088
1086
|
* - `fixed:xyz` sets a attribute from an expression at definition.
|
|
1089
1087
|
* - `hide` sets an element or component's hidden property.
|
|
1090
1088
|
* - `html` Set the element's `innnerHTML` property.
|
package/lib/watch.js
CHANGED
|
@@ -9,12 +9,13 @@ export function watch(target, callback) {
|
|
|
9
9
|
const handler = {
|
|
10
10
|
get(target, key) {
|
|
11
11
|
if (key == "isProxy") return true;
|
|
12
|
-
const prop = target[key]
|
|
13
|
-
|
|
14
|
-
if (
|
|
12
|
+
const prop = target[key],
|
|
13
|
+
propType = typeof prop;
|
|
14
|
+
if (propType == "undefined") return;
|
|
15
|
+
if (propType === "object") return new Proxy(prop, handler);
|
|
15
16
|
if (
|
|
16
|
-
Array.isArray(target) &&
|
|
17
17
|
typeof target[key] === "function" &&
|
|
18
|
+
Array.isArray(target) &&
|
|
18
19
|
MUTATING_METHODS.includes(key)
|
|
19
20
|
) {
|
|
20
21
|
return (...args) => {
|
|
@@ -23,6 +24,9 @@ export function watch(target, callback) {
|
|
|
23
24
|
return result;
|
|
24
25
|
};
|
|
25
26
|
}
|
|
27
|
+
if (target instanceof Date && propType === "function") {
|
|
28
|
+
return prop.bind(target);
|
|
29
|
+
}
|
|
26
30
|
return prop;
|
|
27
31
|
},
|
|
28
32
|
set(target, key, value) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wallace",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
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.
|
|
18
|
+
"babel-plugin-wallace": "^0.14.0",
|
|
19
19
|
"browserify": "^17.0.1"
|
|
20
20
|
},
|
|
21
|
-
"gitHead": "
|
|
21
|
+
"gitHead": "94e0750d51118bf80ff69065fdb39a0f0f52dfc7"
|
|
22
22
|
}
|