@oscarpalmer/abydon 0.17.0 → 0.20.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/dist/abydon.full.mjs +304 -90
- package/dist/constants.d.mts +20 -1
- package/dist/constants.mjs +24 -5
- package/dist/fragments.mjs +4 -4
- package/dist/helpers/dom.d.mts +2 -1
- package/dist/helpers/dom.mjs +4 -1
- package/dist/helpers/index.d.mts +2 -1
- package/dist/helpers/index.mjs +3 -6
- package/dist/node/attribute/index.mjs +12 -2
- package/dist/node/attribute/value.mjs +3 -3
- package/dist/node/event.mjs +3 -3
- package/dist/node/index.mjs +24 -2
- package/dist/node/value.mjs +2 -1
- package/package.json +3 -4
- package/src/constants.ts +42 -4
- package/src/fragment.ts +2 -2
- package/src/fragments.ts +10 -4
- package/src/helpers/dom.ts +4 -0
- package/src/helpers/index.ts +13 -10
- package/src/node/attribute/index.ts +27 -1
- package/src/node/attribute/value.ts +11 -6
- package/src/node/event.ts +9 -4
- package/src/node/index.ts +54 -2
- package/src/node/value.ts +3 -2
package/src/node/index.ts
CHANGED
|
@@ -1,13 +1,21 @@
|
|
|
1
1
|
import type {GenericCallback} from '@oscarpalmer/atoms/models';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
computed,
|
|
4
|
+
isComputed,
|
|
5
|
+
isReactive,
|
|
6
|
+
isSignal,
|
|
7
|
+
type Computed,
|
|
8
|
+
type Reactive,
|
|
9
|
+
} from '@oscarpalmer/mora';
|
|
3
10
|
import {isHTMLOrSVGElement} from '@oscarpalmer/toretto/is';
|
|
4
|
-
import {EXPRESSION_ABYDON_CONTENT} from '../constants';
|
|
11
|
+
import {EXPRESSION_ABYDON_CONTENT, EXPRESSION_TEXTAREA_VALUE} from '../constants';
|
|
5
12
|
import {handleFragments} from '../fragments';
|
|
6
13
|
import {isFragment, isFragments} from '../helpers';
|
|
7
14
|
import {createNodes} from '../helpers/dom';
|
|
8
15
|
import type {FragmentData} from '../models';
|
|
9
16
|
import {mapAttributes} from './attribute';
|
|
10
17
|
import {setReactiveValue} from './value';
|
|
18
|
+
import {mapEvent} from './event';
|
|
11
19
|
|
|
12
20
|
function mapNode(data: FragmentData, comment: Comment): void {
|
|
13
21
|
const matches = EXPRESSION_ABYDON_CONTENT.exec(comment.textContent ?? '');
|
|
@@ -30,6 +38,10 @@ export function mapNodes(data: FragmentData, nodes: ChildNode[]): void {
|
|
|
30
38
|
continue;
|
|
31
39
|
}
|
|
32
40
|
|
|
41
|
+
if (node instanceof HTMLTextAreaElement) {
|
|
42
|
+
mapTextarea(data, node);
|
|
43
|
+
}
|
|
44
|
+
|
|
33
45
|
if (isHTMLOrSVGElement(node)) {
|
|
34
46
|
mapAttributes(data, node);
|
|
35
47
|
}
|
|
@@ -40,6 +52,46 @@ export function mapNodes(data: FragmentData, nodes: ChildNode[]): void {
|
|
|
40
52
|
}
|
|
41
53
|
}
|
|
42
54
|
|
|
55
|
+
function mapTextarea(data: FragmentData, element: HTMLTextAreaElement): void {
|
|
56
|
+
const [, index] = EXPRESSION_TEXTAREA_VALUE.exec(element.value) ?? [];
|
|
57
|
+
|
|
58
|
+
if (index == null) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
element.value = '';
|
|
63
|
+
|
|
64
|
+
const value = data.values[Number.parseInt(index, 10)];
|
|
65
|
+
|
|
66
|
+
if (isSignal(value)) {
|
|
67
|
+
element.value = String(value.peek());
|
|
68
|
+
|
|
69
|
+
mapEvent(element, '@on', () => {
|
|
70
|
+
value.set(element.value);
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
let reactive: Computed<unknown> | undefined;
|
|
77
|
+
|
|
78
|
+
if (typeof value === 'function') {
|
|
79
|
+
reactive = computed(value as GenericCallback);
|
|
80
|
+
} else if (isComputed(value)) {
|
|
81
|
+
reactive = value;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (reactive == null) {
|
|
85
|
+
element.value = String(value);
|
|
86
|
+
} else {
|
|
87
|
+
data.mora.subscribers.add(
|
|
88
|
+
reactive.subscribe(value => {
|
|
89
|
+
element.value = String(value);
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
43
95
|
function mapValue(data: FragmentData, comment: Comment, value: unknown): void {
|
|
44
96
|
switch (true) {
|
|
45
97
|
case typeof value === 'function':
|
package/src/node/value.ts
CHANGED
|
@@ -2,6 +2,7 @@ import {isNullableOrWhitespace} from '@oscarpalmer/atoms/is';
|
|
|
2
2
|
import {getString} from '@oscarpalmer/atoms/string';
|
|
3
3
|
import type {Reactive} from '@oscarpalmer/mora';
|
|
4
4
|
import {isChildNode} from '@oscarpalmer/toretto/is';
|
|
5
|
+
import {ARRAY_COMPARISON_ADDED, ARRAY_COMPARISON_REMOVED} from '../constants';
|
|
5
6
|
import type {Fragment} from '../fragment';
|
|
6
7
|
import {compareArrays, isFragment} from '../helpers';
|
|
7
8
|
import {createNodes, replaceNodes} from '../helpers/dom';
|
|
@@ -71,8 +72,8 @@ function handleArray(
|
|
|
71
72
|
|
|
72
73
|
const comparison = compareArrays(items.fragments ?? [], items.templates);
|
|
73
74
|
|
|
74
|
-
if (comparison !==
|
|
75
|
-
addToArray(identifiers, {...items, next}, nodes, comparison ===
|
|
75
|
+
if (comparison !== ARRAY_COMPARISON_REMOVED) {
|
|
76
|
+
addToArray(identifiers, {...items, next}, nodes, comparison === ARRAY_COMPARISON_ADDED);
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
const toRemove =
|