aberdeen 1.0.0 → 1.0.4
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 +139 -141
- package/dist/aberdeen.d.ts +15 -5
- package/dist/aberdeen.js +9 -7
- package/dist/aberdeen.js.map +3 -3
- package/dist-min/aberdeen.js +3 -3
- package/dist-min/aberdeen.js.map +3 -3
- package/package.json +9 -6
- package/src/aberdeen.ts +23 -11
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aberdeen",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"author": "Frank van Viegen",
|
|
5
5
|
"main": "dist-min/aberdeen.js",
|
|
6
6
|
"devDependencies": {
|
|
@@ -12,31 +12,34 @@
|
|
|
12
12
|
".": {
|
|
13
13
|
"default": "./dist-min/aberdeen.js",
|
|
14
14
|
"development": "./dist/aberdeen.js",
|
|
15
|
-
"types
|
|
15
|
+
"types": "./dist/aberdeen.d.ts"
|
|
16
16
|
},
|
|
17
17
|
"./route": {
|
|
18
18
|
"default": "./dist-min/route.js",
|
|
19
19
|
"development": "./dist/route.js",
|
|
20
|
-
"types
|
|
20
|
+
"types": "./dist/route.d.ts"
|
|
21
21
|
},
|
|
22
22
|
"./transition": {
|
|
23
23
|
"default": "./dist-min/transition.js",
|
|
24
24
|
"development": "./dist/transition.js",
|
|
25
|
-
"types
|
|
25
|
+
"types": "./dist/transition.d.ts"
|
|
26
26
|
},
|
|
27
27
|
"./prediction": {
|
|
28
28
|
"default": "./dist-min/prediction.js",
|
|
29
29
|
"development": "./dist/prediction.js",
|
|
30
|
-
"types
|
|
30
|
+
"types": "./dist/prediction.d.ts"
|
|
31
31
|
},
|
|
32
32
|
"./package.json": "./package.json"
|
|
33
33
|
},
|
|
34
|
-
"description": "A TypeScript/JavaScript library for quickly building performant
|
|
34
|
+
"description": "A TypeScript/JavaScript library for quickly building performant reactive user interfaces without the use of a virtual DOM nor any transpilation.",
|
|
35
35
|
"files": [
|
|
36
36
|
"dist",
|
|
37
37
|
"dist-min",
|
|
38
38
|
"src"
|
|
39
39
|
],
|
|
40
|
+
"bin": {
|
|
41
|
+
"html-to-aberdeen": "./html-to-aberdeen"
|
|
42
|
+
},
|
|
40
43
|
"license": "MIT",
|
|
41
44
|
"scripts": {
|
|
42
45
|
"build": "bun run build:dist && typedoc && rm -rf dist-docs/assets/aberdeen ; cp -r dist dist-docs/assets/aberdeen",
|
package/src/aberdeen.ts
CHANGED
|
@@ -1472,22 +1472,32 @@ const SPECIAL_PROPS: {[key: string]: (value: any) => void} = {
|
|
|
1472
1472
|
* - `{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.
|
|
1473
1473
|
* - `{element: Node}`: Add a pre-existing HTML `Node` to the *current* element.
|
|
1474
1474
|
*
|
|
1475
|
+
* @returns The most inner DOM element that was created (not counting text nodes nor elements created by content functions),
|
|
1476
|
+
* or undefined if no elements were created.
|
|
1475
1477
|
*
|
|
1476
1478
|
* @example Create Element
|
|
1477
1479
|
* ```typescript
|
|
1478
1480
|
* $('button.secondary.outline:Submit', {
|
|
1479
|
-
* disabled:
|
|
1481
|
+
* disabled: false,
|
|
1480
1482
|
* click: () => console.log('Clicked!'),
|
|
1481
1483
|
* $color: 'red'
|
|
1482
1484
|
* });
|
|
1483
1485
|
* ```
|
|
1486
|
+
*
|
|
1487
|
+
* @example Create Nested Elements
|
|
1488
|
+
* ```typescript
|
|
1489
|
+
* let inputElement: Element = $('label:Click me', 'input', {type: 'checkbox'});
|
|
1490
|
+
* // You should usually not touch raw DOM elements, unless when integrating
|
|
1491
|
+
* // with non-Aberdeen code.
|
|
1492
|
+
* console.log('DOM element:', inputElement);
|
|
1493
|
+
* ```
|
|
1484
1494
|
*
|
|
1485
|
-
* @example
|
|
1495
|
+
* @example Content Functions & Reactive Scope
|
|
1486
1496
|
* ```typescript
|
|
1487
1497
|
* const state = proxy({ count: 0 });
|
|
1488
1498
|
* $('div', () => { // Outer element
|
|
1489
1499
|
* // This scope re-renders when state.count changes
|
|
1490
|
-
* $(
|
|
1500
|
+
* $(`p:Count is ${state.count}`);
|
|
1491
1501
|
* $('button:Increment', { click: () => state.count++ });
|
|
1492
1502
|
* });
|
|
1493
1503
|
* ```
|
|
@@ -1514,9 +1524,10 @@ const SPECIAL_PROPS: {[key: string]: (value: any) => void} = {
|
|
|
1514
1524
|
*/
|
|
1515
1525
|
|
|
1516
1526
|
|
|
1517
|
-
export function $(...args: (string | null | undefined | false | (() => void) | Record<string,any>)[]): void {
|
|
1527
|
+
export function $(...args: (string | null | undefined | false | (() => void) | Record<string,any>)[]): void | Element {
|
|
1518
1528
|
let savedCurrentScope;
|
|
1519
1529
|
let err;
|
|
1530
|
+
let result;
|
|
1520
1531
|
|
|
1521
1532
|
for(let arg of args) {
|
|
1522
1533
|
if (arg == null || arg === false) continue;
|
|
@@ -1545,15 +1556,15 @@ export function $(...args: (string | null | undefined | false | (() => void) | R
|
|
|
1545
1556
|
err = `Tag '${arg}' cannot contain space`;
|
|
1546
1557
|
break;
|
|
1547
1558
|
} else {
|
|
1548
|
-
|
|
1549
|
-
if (classes)
|
|
1550
|
-
if (text)
|
|
1551
|
-
addNode(
|
|
1559
|
+
result = document.createElement(arg);
|
|
1560
|
+
if (classes) result.className = classes.replaceAll('.', ' ');
|
|
1561
|
+
if (text) result.textContent = text;
|
|
1562
|
+
addNode(result);
|
|
1552
1563
|
if (!savedCurrentScope) {
|
|
1553
1564
|
savedCurrentScope = currentScope;
|
|
1554
1565
|
}
|
|
1555
|
-
let newScope = new ChainedScope(
|
|
1556
|
-
newScope.lastChild =
|
|
1566
|
+
let newScope = new ChainedScope(result, true);
|
|
1567
|
+
newScope.lastChild = result.lastChild || undefined;
|
|
1557
1568
|
if (topRedrawScope === currentScope) topRedrawScope = newScope;
|
|
1558
1569
|
currentScope = newScope;
|
|
1559
1570
|
}
|
|
@@ -1578,6 +1589,7 @@ export function $(...args: (string | null | undefined | false | (() => void) | R
|
|
|
1578
1589
|
currentScope = savedCurrentScope;
|
|
1579
1590
|
}
|
|
1580
1591
|
if (err) throw new Error(err);
|
|
1592
|
+
return result;
|
|
1581
1593
|
}
|
|
1582
1594
|
|
|
1583
1595
|
let cssCount = 0;
|
|
@@ -1766,7 +1778,7 @@ export function setErrorHandler(handler?: (error: Error) => boolean | undefined)
|
|
|
1766
1778
|
* call or a {@link $} element's render function).
|
|
1767
1779
|
*
|
|
1768
1780
|
* **Note:** While this provides access to the DOM element, directly manipulating it outside
|
|
1769
|
-
* of Aberdeen's control is generally discouraged. Prefer
|
|
1781
|
+
* of Aberdeen's control is generally discouraged. Prefer reactive updates using {@link $}.
|
|
1770
1782
|
*
|
|
1771
1783
|
* @returns The current parent `Element` for DOM insertion.
|
|
1772
1784
|
*
|