aberdeen 1.0.7 → 1.0.10
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/README.md +1 -1
- package/dist/aberdeen.d.ts +2 -2
- package/dist/aberdeen.js +35 -12
- package/dist/aberdeen.js.map +4 -4
- package/dist/helpers/reverseSortedSet.d.ts +8 -3
- package/dist-min/aberdeen.js +5 -5
- package/dist-min/aberdeen.js.map +4 -4
- package/html-to-aberdeen +354 -0
- package/package.json +1 -1
- package/src/aberdeen.ts +63 -19
- package/src/helpers/reverseSortedSet.ts +34 -31
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Aberdeen's approach is refreshingly simple:
|
|
|
12
12
|
- ⏩ **Fast:** No virtual DOM. Aberdeen intelligently updates only the minimal, necessary parts of your UI when proxied data changes.
|
|
13
13
|
- 👥 **Awesome lists**: It's very easy and performant to reactively display data sorted by whatever you like.
|
|
14
14
|
- 🔬 **Tiny:** Around 5KB (minimized and gzipped) and with zero runtime dependencies.
|
|
15
|
-
- 🔋 **Batteries included**: Comes with client-side routing, revertible patches for optimistic user-interface updates, component-local CSS, helper functions for transforming reactive data (mapping, partitioning, filtering, etc) and hide/unhide transition effects. No bikeshedding required!
|
|
15
|
+
- 🔋 **Batteries included**: Comes with client-side routing, revertible patches for optimistic user-interface updates, component-local CSS, SVG support, helper functions for transforming reactive data (mapping, partitioning, filtering, etc) and hide/unhide transition effects. No bikeshedding required!
|
|
16
16
|
|
|
17
17
|
## Why *not* use Aberdeen?
|
|
18
18
|
|
package/dist/aberdeen.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ export type SortKeyType = number | string | Array<number | string> | undefined;
|
|
|
66
66
|
* @see {@link onEach} for usage with sorting.
|
|
67
67
|
*/
|
|
68
68
|
export declare function invertString(input: string): string;
|
|
69
|
-
export declare function onEach<T>(target:
|
|
69
|
+
export declare function onEach<T>(target: ReadonlyArray<undefined | T>, render: (value: T, index: number) => void, makeKey?: (value: T, key: any) => SortKeyType): void;
|
|
70
70
|
export declare function onEach<K extends string | number | symbol, T>(target: Record<K, undefined | T>, render: (value: T, index: K) => void, makeKey?: (value: T, key: K) => SortKeyType): void;
|
|
71
71
|
/**
|
|
72
72
|
* Reactively checks if an observable array or object is empty.
|
|
@@ -306,7 +306,7 @@ export declare function ref<T extends TargetType, K extends keyof T>(target: T,
|
|
|
306
306
|
* This is often used together with {@link ref}, in order to use properties other than `.value`.
|
|
307
307
|
* - `{text: string|number}`: Add the value as a `TextNode` to the *current* element.
|
|
308
308
|
* - `{html: string}`: Add the value as HTML to the *current* element. This should only be used in exceptional situations. And of course, beware of XSS.
|
|
309
|
-
|
|
309
|
+
- `Node`: If a DOM Node (Element or TextNode) is passed in, it is added as a child to the *current* element. If the Node is an Element, it becomes the new *current* element for the rest of this `$` function execution.
|
|
310
310
|
*
|
|
311
311
|
* @returns The most inner DOM element that was created (not counting text nodes nor elements created by content functions),
|
|
312
312
|
* or undefined if no elements were created.
|
package/dist/aberdeen.js
CHANGED
|
@@ -44,8 +44,8 @@ class ReverseSortedSet {
|
|
|
44
44
|
}
|
|
45
45
|
get(indexValue) {
|
|
46
46
|
const keyProp = this.keyProp;
|
|
47
|
-
let current = this.tail;
|
|
48
47
|
let prev;
|
|
48
|
+
let current = this.tail;
|
|
49
49
|
for (let l = this.symbols.length - 1;l >= 0; l--) {
|
|
50
50
|
const symbol = this.symbols[l];
|
|
51
51
|
while ((prev = current[symbol]) && prev[keyProp] > indexValue)
|
|
@@ -138,7 +138,7 @@ function partToStr(part) {
|
|
|
138
138
|
let num = Math.abs(Math.round(part));
|
|
139
139
|
const negative = part < 0;
|
|
140
140
|
while (num > 0) {
|
|
141
|
-
result
|
|
141
|
+
result = String.fromCharCode(negative ? 65534 - num % 65533 : 2 + num % 65533) + result;
|
|
142
142
|
num = Math.floor(num / 65533);
|
|
143
143
|
}
|
|
144
144
|
return String.fromCharCode(128 + (negative ? -result.length : result.length)) + result;
|
|
@@ -164,6 +164,7 @@ class Scope {
|
|
|
164
164
|
|
|
165
165
|
class ContentScope extends Scope {
|
|
166
166
|
cleaners;
|
|
167
|
+
inSvgNamespace = false;
|
|
167
168
|
constructor(cleaners = []) {
|
|
168
169
|
super();
|
|
169
170
|
this.cleaners = cleaners;
|
|
@@ -207,6 +208,7 @@ class ChainedScope extends ContentScope {
|
|
|
207
208
|
constructor(parentElement, useParentCleaners = false) {
|
|
208
209
|
super(useParentCleaners ? currentScope.cleaners : []);
|
|
209
210
|
this.parentElement = parentElement;
|
|
211
|
+
this.inSvgNamespace = currentScope.inSvgNamespace;
|
|
210
212
|
if (parentElement === currentScope.parentElement) {
|
|
211
213
|
this.prevSibling = currentScope.getChildPrevSibling();
|
|
212
214
|
currentScope.lastChild = this;
|
|
@@ -255,6 +257,7 @@ class MountScope extends ContentScope {
|
|
|
255
257
|
super();
|
|
256
258
|
this.parentElement = parentElement;
|
|
257
259
|
this.renderer = renderer;
|
|
260
|
+
this.inSvgNamespace = currentScope.inSvgNamespace;
|
|
258
261
|
this.redraw();
|
|
259
262
|
currentScope.cleaners.push(this);
|
|
260
263
|
}
|
|
@@ -444,6 +447,7 @@ class OnEachItemScope extends ContentScope {
|
|
|
444
447
|
this.parent = parent;
|
|
445
448
|
this.itemIndex = itemIndex;
|
|
446
449
|
this.parentElement = parent.parentElement;
|
|
450
|
+
this.inSvgNamespace = currentScope.inSvgNamespace;
|
|
447
451
|
this.parent.byIndex.set(this.itemIndex, this);
|
|
448
452
|
this.lastChild = this;
|
|
449
453
|
if (topRedraw)
|
|
@@ -906,9 +910,9 @@ var SPECIAL_PROPS = {
|
|
|
906
910
|
addNode(document.createTextNode(value));
|
|
907
911
|
},
|
|
908
912
|
element: (value) => {
|
|
909
|
-
|
|
910
|
-
throw new Error(`Unexpected element-argument: ${JSON.parse(value)}`);
|
|
913
|
+
console.log("Aberdeen: $({element: myElement}) is deprecated, use $(myElement) instead");
|
|
911
914
|
addNode(value);
|
|
915
|
+
SPECIAL_PROPS.element = addNode;
|
|
912
916
|
}
|
|
913
917
|
};
|
|
914
918
|
function $(...args) {
|
|
@@ -945,7 +949,12 @@ function $(...args) {
|
|
|
945
949
|
err = `Tag '${arg}' cannot contain space`;
|
|
946
950
|
break;
|
|
947
951
|
} else {
|
|
948
|
-
|
|
952
|
+
const useNamespace = currentScope.inSvgNamespace || arg === "svg";
|
|
953
|
+
if (useNamespace) {
|
|
954
|
+
result = document.createElementNS("http://www.w3.org/2000/svg", arg);
|
|
955
|
+
} else {
|
|
956
|
+
result = document.createElement(arg);
|
|
957
|
+
}
|
|
949
958
|
if (classes)
|
|
950
959
|
result.className = classes.replaceAll(".", " ");
|
|
951
960
|
if (text)
|
|
@@ -955,6 +964,9 @@ function $(...args) {
|
|
|
955
964
|
savedCurrentScope = currentScope;
|
|
956
965
|
}
|
|
957
966
|
const newScope = new ChainedScope(result, true);
|
|
967
|
+
if (arg === "svg") {
|
|
968
|
+
newScope.inSvgNamespace = true;
|
|
969
|
+
}
|
|
958
970
|
newScope.lastChild = result.lastChild || undefined;
|
|
959
971
|
if (topRedrawScope === currentScope)
|
|
960
972
|
topRedrawScope = newScope;
|
|
@@ -962,12 +974,23 @@ function $(...args) {
|
|
|
962
974
|
}
|
|
963
975
|
} else if (typeof arg === "object") {
|
|
964
976
|
if (arg.constructor !== Object) {
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
977
|
+
if (arg instanceof Node) {
|
|
978
|
+
addNode(arg);
|
|
979
|
+
if (arg instanceof Element) {
|
|
980
|
+
if (!savedCurrentScope)
|
|
981
|
+
savedCurrentScope = currentScope;
|
|
982
|
+
currentScope = new ChainedScope(arg, true);
|
|
983
|
+
currentScope.lastChild = arg.lastChild || undefined;
|
|
984
|
+
}
|
|
985
|
+
} else {
|
|
986
|
+
err = `Unexpected argument: ${arg}`;
|
|
987
|
+
break;
|
|
988
|
+
}
|
|
989
|
+
} else {
|
|
990
|
+
for (const key in arg) {
|
|
991
|
+
const val = arg[key];
|
|
992
|
+
applyArg(key, val);
|
|
993
|
+
}
|
|
971
994
|
}
|
|
972
995
|
} else if (typeof arg === "function") {
|
|
973
996
|
new RegularScope(currentScope.parentElement, arg);
|
|
@@ -1205,5 +1228,5 @@ export {
|
|
|
1205
1228
|
$
|
|
1206
1229
|
};
|
|
1207
1230
|
|
|
1208
|
-
//# debugId=
|
|
1231
|
+
//# debugId=4D9B4C45440E57B664756E2164756E21
|
|
1209
1232
|
//# sourceMappingURL=aberdeen.js.map
|